SlideShare ist ein Scribd-Unternehmen logo
1 von 8
Downloaden Sie, um offline zu lesen
//    -------------------------------------------------------------------------------------------------
//    MDP-Plus v. 2.1.2
//
//    Based on MillionDollarPips - (ANY PAIR + NO DLL) - ver 1.1.0
//
//    Someone at a russian forum fixed a Stack Overflow problem, added NDD-mode (ECN-mode)
//    and moved the DLL-functions in the mql4-code.
//
//    Sept-2011 by Capella by at http://www.worldwide-invest.org
//    - Cleaned code from unused code, proper variable names and sub-names.
//
//    Ver. 1.0 - 2011-09-24 by Capella at http://www.worldwide-invest.org
//    - Added Print lines for STOPLEVEL when errors (for debugging purposes)
//    - Removed unused externals and variables
//    - Moved dynamic TP/SL and trading signals constants to externals,
//      as VolatilityLimit and Scalpfactor.
//    - Forced TrailingStop
//
//    Ver. 2.0 - 2011-10-19 by Capella at http://www.worldwide-invest.org
//    - Fixing bugs, and removed unused code.
//    - Forced Trailing, as no-trailing cannot generate profit
//    - Forced HighSpeed, as false mode cannot give good result
//    - Added additional settings for scalping - UseMovingAverage,
//      UseBollingerBands, and OrderExpireSeconds
//    - Automatic adjusted to broker STOPLEVEL, to avoid OrderSend error 130
//    Ver 2.1 - 2011-11-91 by Capella at http://www.worldwide-invest.org
//    - Added Indicatorperiod as external
//    - Modified calculation of variable that triggers trade (local_pricedirection)
//    - Removed Distance as an external, and automatically adjust Distance to be the same as stoplevel
//    - Removed call for sub_moveandfillarrays as it doesn't make any difference
//    Ver 2.1.1 - 2011-11-05 by Capella at http://www.worldwide-invest.org
//    - Fixed a bug in the calculation of local_highest and local_lowest that caused wrong call for
//      OrderModify.
//    - Changed the calculation of STOPLEVEL to also consider FREEZELEVEL
//    Ver 2.1.2 - 2011-11-06 by Capella
//    - Changed default settings according to optimized backtests
//    - Added external parameter Deviation for iBands, default 0
//    -------------------------------------------------------------------------------------------------

#property show_inputs

#include <stdlib.mqh>

//----------------------- Externals ----------------------------------------------------------------
// All externals here have their name starting with a CAPITAL character

extern    string Configuration = "==== Configuration ====";
extern    int Magic = 0;
extern    string OrderCmt = "";
extern    bool NDDmode = FALSE;
extern    bool Show_Debug = FALSE;
extern    bool Verbose = FALSE;
extern    string ScalpingSettings = "==== Scalping settings ====";
extern    double TakeProfit = 10.0;          // TakeProfit from as many points. Default 10 (= 1 pip)
extern    double StopLoss = 60.0;            // StopLoss from as many points. Default 60 (= 6 pips)
extern    double Trailing_Start = 0;         // Start trailing profit from as so many pips. Default 0
extern    double VolatilityLimit = 180;      // Default 180. Can normally be between 100 and 300
extern    double Scalpfactor = 66;           // 60 to 77 - only used if larger than broker StopLevel
extern    bool UseMovingAverage = TRUE;      // User two iMA as channell
extern    bool UseBollingerBands = TRUE;     // Use iBands as channel
extern    int IndicatorPeriod = 30;          // Period for iMA and iBands
extern    double Deviation = 2.00;           // Deviation for iBands
extern    int OrderExpireSeconds = 3600;     // Orders are deted after so many seconds
extern    string Money_Management = "==== Money Management ====";
extern    double Min_Lots = 0.01;
extern    double Max_Lots = 100.0;
extern    double Risk = 100.0;

//--------------------------- Globals --------------------------------------------------------------
// All globals have their name written in lower case characters
//

bool condition1;
bool condition2 = FALSE;
bool trailingstop = TRUE;

int    distance = 0;
int    brokerdigits = 0;
int    slippage = 3;
int    array_tickcounts[30];
int    globalerror = 0;
int    lasttime = 0;
int    tickcounter = 0;
int    upto30counter = 0;
int    AccNum;

double    zero = 0.0;
double    zeropointfour = 0.4;
double    one = 1.0;
double    five = 5.0;
double    ten = 10.0;
double    twenty = 20.0;

                                                       Page 1/8
double     forty = 40.0;
double     multiplier;
double     commission = 0.0;
double     minmaxlot = 0.1;
double     maxamount = 0.0;
double     pipette = 0.0;
double     upper;
double     lower;
double     array_bid[30];
double     array_ask[30];
double     array_spread[30];

//======================= Program initialization ===========================================================

int init()
{
   int stoplevel;

    ArrayInitialize(array_spread, 0);
    VolatilityLimit = VolatilityLimit * Point;
    Scalpfactor = Scalpfactor * 10 * Point / 3;
    brokerdigits = Digits;
    pipette = Point;

    stoplevel = MathMax(MarketInfo(Symbol(), MODE_FREEZELEVEL), MarketInfo(Symbol(), MODE_STOPLEVEL));
    if (TakeProfit < stoplevel)
       TakeProfit = stoplevel;
    if (StopLoss < stoplevel)
       StopLoss = stoplevel;
    if (distance < stoplevel)
       distance = stoplevel;

    if (MathMod(Digits, 2) == 0)
       slippage = 0;
    else
       globalerror = -1;

    start();
    return (0);
}

//====================== Program start ===================================

int start()
{
   if (brokerdigits == 0)
   {
      init();
      return;
   }

    sub_trade();
    return (0);
}

//===================== Subroutines starts here =========================================
// All subs have their names starting with sub_
// Exception are the standard routines init() and start()
//
// Notation:
// All parameters in subs have their names starting with par_
// All local variables in subs have thewir names starting with local_
//

void sub_trade()
{
   string local_textstring;

    bool    local_wasordermodified;
    bool    local_highspeed;
    bool    local_ordersenderror;
    bool    local_isbidgreaterthanima;
    bool    local_isbidgreaterthanibands;
    bool    local_isbidgreaterthanindy;

    int    local_orderticket;
    int    local_lotstep;
    int    local_orderexpiretime;
    int    local_bidpart;
    int    local_askpart;
    int    local_loopcount2;
    int    local_loopcount1;
    int    local_pricedirection;
    int    local_counter1;
    int    local_counter2;

    double    local_askplusdistance;
    double    local_bidminusdistance;
    double    local_a;
    double    local_b;
    double    local_c;
    double    local_scalpsize;

                                                     Page 2/8
double   local_d;
  double   local_orderstoploss;
  double   local_ordertakeprofit;
  double   local_tpadjust;
  double   local_ihigh;
  double   local_ilow;
  double   local_imalow;
  double   local_imahigh;
  double   local_imadiff;
  double   local_ibandsupper;
  double   local_ibandslower;
  double   local_ibandsdiff;
  double   local_highest;
  double   local_lowest;
  double   local_stoplevel;
  double   local_spread;
  double   local_adjuststoplevel;
  double   local_e;
  double   local_avgspread;
  double   local_f;
  double   local_g;
  double   local_h;
  double   local_ihighilowdiff;
  double   local_i;

  if (lasttime < Time[0])
  {
     lasttime = Time[0];
     tickcounter = 0;
  }
  else
     tickcounter++;

  // Calculate a channel based on some indicators
  local_ihigh = iHigh(Symbol(), PERIOD_M1, 0);
  local_ilow = iLow(Symbol(), PERIOD_M1, 0);
  local_ihighilowdiff = local_ihigh - local_ilow;

  local_imalow = iMA(NULL, PERIOD_M1, IndicatorPeriod, 0, MODE_LWMA, PRICE_LOW, 0);
  local_imahigh = iMA(NULL, PERIOD_M1, IndicatorPeriod, 0, MODE_LWMA, PRICE_HIGH, 0);
  local_imadiff = local_imahigh - local_imalow;
  local_isbidgreaterthanima = Bid >= local_imalow + local_imadiff / 2;

  local_ibandsupper = iCustom(NULL, PERIOD_M1, "Bands", IndicatorPeriod, 0, Deviation, MODE_UPPER, 0);
  local_ibandslower = iCustom(NULL, PERIOD_M1, "Bands", IndicatorPeriod, 0, Deviation, MODE_LOWER, 0);
  local_ibandsdiff = local_ibandsupper - local_ibandslower;
  local_isbidgreaterthanibands = Bid >= local_ibandslower + local_ibandsdiff / 2;

  // local_isbidgreaterthanindy is only used for OrderModify on previous BUY_STOP and SELL_STOP
  local_isbidgreaterthanindy = FALSE;
  if (UseMovingAverage == FALSE && UseBollingerBands == TRUE)
  {
     local_isbidgreaterthanindy = TRUE;
     local_highest = local_ibandsupper;
     local_lowest = local_ibandslower;
  }
  else if (UseMovingAverage == TRUE && UseBollingerBands == FALSE)
  {
     local_isbidgreaterthanindy = TRUE;
     local_highest = local_imahigh;
     local_lowest = local_imalow;
  }
  else if (UseMovingAverage == TRUE && UseBollingerBands == TRUE)
     if (local_isbidgreaterthanima == TRUE && local_isbidgreaterthanibands == TRUE)
     {
        local_isbidgreaterthanindy = TRUE;
        local_highest = MathMax(local_ibandsupper, local_imahigh);
        local_lowest = MathMin(local_ibandslower, local_imalow);
     }

   if (!condition2)
   {
      for (local_loopcount2 = OrdersTotal() - 1; local_loopcount2 >= 0; local_loopcount2--)
      {
         OrderSelect(local_loopcount2, SELECT_BY_POS, MODE_TRADES);
         if (OrderSymbol() == Symbol() && OrderCloseTime() != 0 && OrderClosePrice() != OrderOpenPrice() &&
OrderProfit() != 0.0 && OrderComment() != "partial close" && StringFind(OrderComment(), "[sl]from #") == -1 &&
            StringFind(OrderComment(), "[tp]from #") == -1)
         {
            condition2 = TRUE;
            local_a = MathAbs(OrderProfit() / (OrderClosePrice() - OrderOpenPrice()));
            commission = (-OrderCommission()) / local_a;
            Print("Commission_Rate : " + sub_dbl2strbrokerdigits(commission));
            break;
         }
      }
   }

  if (!condition2)
  {
     for (local_loopcount2 = OrdersHistoryTotal() - 1; local_loopcount2 >= 0; local_loopcount2--)
     {

                                                    Page 3/8
OrderSelect(local_loopcount2, SELECT_BY_POS, MODE_HISTORY);
         if (OrderSymbol() == Symbol() && OrderCloseTime() != 0 && OrderClosePrice() != OrderOpenPrice() &&
OrderProfit() != 0.0 && OrderComment() != "partial close" && StringFind(OrderComment(), "[sl]from #") == -1
         && StringFind(OrderComment(), "[tp]from #") == -1)
         {
            condition2 = TRUE;
            local_a = MathAbs(OrderProfit() / (OrderClosePrice() - OrderOpenPrice()));
            commission = (-OrderCommission()) / local_a;
            Print("Commission_Rate : " + sub_dbl2strbrokerdigits(commission));
            break;
         }
      }
   }

  local_stoplevel = MarketInfo(Symbol(), MODE_STOPLEVEL) * Point;
  local_spread = Ask - Bid;
  local_adjuststoplevel = 0.5;
  if (local_adjuststoplevel < local_stoplevel - 5.0 * pipette)
  {
     local_highspeed = FALSE;
     local_b = forty * pipette;
     local_adjuststoplevel = ten * pipette;
     local_c = five * pipette;
  }
  else
  {
     local_highspeed = TRUE;
     local_b = twenty * pipette;
     local_adjuststoplevel = zero * pipette;
     local_c = Trailing_Start * pipette;
  }

  local_b = MathMax(local_b, local_stoplevel);
  if (local_highspeed)
     local_adjuststoplevel = MathMax(local_adjuststoplevel, local_stoplevel);
  ArrayCopy(array_spread, array_spread, 0, 1, 29);
  array_spread[29] = local_spread;
  if (upto30counter < 30)
     upto30counter++;
  local_e = 0;
  local_loopcount2 = 29;
  for (local_loopcount1 = 0; local_loopcount1 < upto30counter; local_loopcount1++)
  {
     local_e += array_spread[local_loopcount2];
     local_loopcount2--;
  }

  local_avgspread = local_e / upto30counter;
  if (!condition2 && local_avgspread < 15.0 * pipette)
     commission = 15.0 * pipette - local_avgspread;

  local_f = sub_normalizebrokerdigits(Ask + commission);
  local_g = sub_normalizebrokerdigits(Bid - commission);
  local_h = local_avgspread + commission;

  if(local_ihighilowdiff > VolatilityLimit)
  {
     if (Bid < local_lowest)
        local_pricedirection = -1;
     else if (Bid > local_highest)
        local_pricedirection = 1;
  }

  local_scalpsize = MathMax(local_stoplevel, Scalpfactor);

  if (Bid == 0.0 || MarketInfo(Symbol(), MODE_LOTSIZE) == 0.0)
     local_scalpsize = 0;

  local_i = local_scalpsize + local_avgspread + commission;
  local_orderexpiretime = TimeCurrent() + OrderExpireSeconds;

  if (MarketInfo(Symbol(), MODE_LOTSTEP) == 0.0)
     local_lotstep = 5;
  else
     local_lotstep = sub_logarithm(0.1, MarketInfo(Symbol(), MODE_LOTSTEP));

  if (Risk < 0.001 || Risk > 1000.0)
  {
     Comment("ERROR -- Invalid Risk Value.");
     return;
  }

  if (AccountBalance() <= 0.0)
  {
     Comment("ERROR -- Account Balance is " + DoubleToStr(MathRound(AccountBalance()), 0));
     return;
  }

  if (local_scalpsize != 0.0)
  {
     maxamount = MathMax(AccountBalance(), maxamount);


                                                    Page 4/8
local_d =   MathMin(AccountFreeMargin() * AccountLeverage() / 2.0, maxamount * Risk / 100.0 * Bid /
local_i);
      minmaxlot   =   local_d / MarketInfo(Symbol(), MODE_LOTSIZE);
      minmaxlot   =   NormalizeDouble(minmaxlot, local_lotstep);
      minmaxlot   =   MathMax(Min_Lots, minmaxlot);
      minmaxlot   =   MathMax(MarketInfo(Symbol(), MODE_MINLOT), minmaxlot);
      minmaxlot   =   MathMin(Max_Lots, minmaxlot);
      minmaxlot   =   MathMin(MarketInfo(Symbol(), MODE_MAXLOT), minmaxlot);
   }

   // Run through already open orders and modify if necessary
   local_counter1 = 0;
   local_counter2 = 0;
   for (local_loopcount2 = 0; local_loopcount2 < OrdersTotal(); local_loopcount2++)
   {
      OrderSelect(local_loopcount2, SELECT_BY_POS, MODE_TRADES);
      if (OrderMagicNumber() == Magic && OrderCloseTime() == 0)
      {
         if (OrderSymbol() != Symbol())
         {
            local_counter2++;
            continue;
         }
         switch (OrderType())
         {
         case OP_BUY:
            while (trailingstop)
            {
               local_orderstoploss = OrderStopLoss();
               local_ordertakeprofit = OrderTakeProfit();
               if (!(local_ordertakeprofit < sub_normalizebrokerdigits(local_f + local_b) && local_f + local_b -
local_ordertakeprofit > local_c))
                   break;
               local_orderstoploss = sub_normalizebrokerdigits(Bid - local_b);
               local_ordertakeprofit = sub_normalizebrokerdigits(local_f + local_b);
               local_wasordermodified = OrderModify(OrderTicket(), 0, local_orderstoploss,
local_ordertakeprofit, local_orderexpiretime, Lime);
               break;
            }
            local_counter1++;
            break;
         case OP_SELL:
            while (trailingstop)
            {
               local_orderstoploss = OrderStopLoss();
               local_ordertakeprofit = OrderTakeProfit();
               if (!(local_ordertakeprofit > sub_normalizebrokerdigits(local_g - local_b) &&
local_ordertakeprofit - local_g + local_b > local_c))
                   break;
               local_orderstoploss = sub_normalizebrokerdigits(Ask + local_b);
               local_ordertakeprofit = sub_normalizebrokerdigits(local_g - local_b);
               local_wasordermodified = OrderModify(OrderTicket(), 0, local_orderstoploss,
local_ordertakeprofit, local_orderexpiretime, Orange);
               break;
            }
            local_counter1++;
            break;
         case OP_BUYSTOP:
            if (!local_isbidgreaterthanindy)
            {
               local_tpadjust = OrderTakeProfit() - OrderOpenPrice() - commission;
               while (true)
               {
                   if (!(sub_normalizebrokerdigits(Ask + local_adjuststoplevel) < OrderOpenPrice() &&
OrderOpenPrice() - Ask - local_adjuststoplevel > local_c))
                      break;
                   local_wasordermodified = OrderModify(OrderTicket(), sub_normalizebrokerdigits(Ask +
local_adjuststoplevel), sub_normalizebrokerdigits(Bid + local_adjuststoplevel - local_tpadjust),
sub_normalizebrokerdigits(local_f + local_adjuststoplevel + local_tpadjust), 0, Lime);
                   break;
               }
               local_counter1++;
            }
            else
               OrderDelete(OrderTicket());
            break;
         case OP_SELLSTOP:
            if (local_isbidgreaterthanindy)
            {
               local_tpadjust = OrderOpenPrice() - OrderTakeProfit() - commission;
               while (true)
               {
                   if (!(sub_normalizebrokerdigits(Bid - local_adjuststoplevel) > OrderOpenPrice() && Bid -
local_adjuststoplevel - OrderOpenPrice() > local_c))
                      break;
                   local_wasordermodified = OrderModify(OrderTicket(), sub_normalizebrokerdigits(Bid -
local_adjuststoplevel), sub_normalizebrokerdigits(Ask - local_adjuststoplevel + local_tpadjust),
sub_normalizebrokerdigits(local_g - local_adjuststoplevel - local_tpadjust), 0, Orange);
                   break;
               }
               local_counter1++;
            }

                                                        Page 5/8
else
                 OrderDelete(OrderTicket());
          }
      }
  }

  local_ordersenderror = FALSE;
  if (globalerror >= 0 || globalerror == -2)
  {
     local_bidpart = NormalizeDouble(Bid / pipette, 0);
     local_askpart = NormalizeDouble(Ask / pipette, 0);
     if (local_bidpart % 10 != 0 || local_askpart % 10 != 0)
        globalerror = -1;
     else
     {
        if (globalerror >= 0 && globalerror < 10)
           globalerror++;
        else
           globalerror = -2;
     }
  }

   // Open new BUY- or SELL-orders, or BUYSTOP or SELLSTOP orders
   if (local_scalpsize != 0.0 && local_counter1 == 0 && local_pricedirection != 0 &&
sub_normalizebrokerdigits(local_h) <= sub_normalizebrokerdigits(forty * pipette) && globalerror == -1)
   {
      if (local_pricedirection < 0)
      {
         if (local_highspeed)
         {
            local_askplusdistance = Ask + distance * Point;
            if (NDDmode)
            {
               local_orderticket = OrderSend(Symbol(), OP_BUYSTOP, minmaxlot, local_askplusdistance, slippage,
0, 0, OrderCmt, Magic, 0, Lime);
               if (OrderSelect(local_orderticket, SELECT_BY_TICKET))
                  OrderModify(OrderTicket(), OrderOpenPrice(), local_askplusdistance - StopLoss * Point,
local_askplusdistance + TakeProfit * Point, local_orderexpiretime, Lime);
            }
            else
               local_orderticket = OrderSend(Symbol(), OP_BUYSTOP, minmaxlot, local_askplusdistance, slippage,
local_askplusdistance - StopLoss * Point, local_askplusdistance + TakeProfit * Point, OrderCmt, Magic,
local_orderexpiretime, Lime);

            if (local_orderticket < 0)
            {
               local_ordersenderror = TRUE;
               Print("ERROR BUYSTOP : " + sub_dbl2strbrokerdigits(Ask + local_adjuststoplevel) + " SL:" +
sub_dbl2strbrokerdigits(Bid + local_adjuststoplevel - local_scalpsize) + " TP:" +
sub_dbl2strbrokerdigits(local_f + local_adjuststoplevel + local_scalpsize));
            }
            else
            {
               PlaySound("news.wav");
               Print("BUYSTOP : " + sub_dbl2strbrokerdigits(Ask + local_adjuststoplevel) + " SL:" +
sub_dbl2strbrokerdigits(Bid + local_adjuststoplevel - local_scalpsize) + " TP:" +
sub_dbl2strbrokerdigits(local_f + local_adjuststoplevel + local_scalpsize));
            }
         }
         else // local_highspeed == FALSE
         {
            if (Bid - local_ilow > 0.0)
            {
               local_orderticket = OrderSend(Symbol(), OP_BUY, minmaxlot, Ask, slippage, 0, 0, OrderCmt, Magic,
local_orderexpiretime, Lime);
               if (local_orderticket < 0)
               {
                  local_ordersenderror = TRUE;
                  Print("ERROR BUY Ask:" + sub_dbl2strbrokerdigits(Ask) + " SL:" + sub_dbl2strbrokerdigits(Bid -
local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_f + local_scalpsize));
               }
               else
               {
                  while (true)
                  {
                     local_wasordermodified = OrderModify(local_orderticket, 0, sub_normalizebrokerdigits(Bid -
local_scalpsize), sub_normalizebrokerdigits(local_f + local_scalpsize), local_orderexpiretime, Lime);
                     break;
                  }
                  PlaySound("news.wav");
                  Print("BUY Ask:" + sub_dbl2strbrokerdigits(Ask) + " SL:" + sub_dbl2strbrokerdigits(Bid -
local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_f + local_scalpsize));
               }
            }
         }
      }
      else
      {
         if (local_pricedirection > 0)
         {
            if (local_highspeed)
            {

                                                    Page 6/8
local_bidminusdistance = Bid - distance * Point;
               if (NDDmode)
               {
                  local_orderticket = OrderSend(Symbol(), OP_SELLSTOP, minmaxlot, local_bidminusdistance,
slippage, 0, 0, OrderCmt, Magic, 0, Orange);
                  if (OrderSelect(local_orderticket, SELECT_BY_TICKET))
                     OrderModify(OrderTicket(), OrderOpenPrice(), local_bidminusdistance + StopLoss * Point,
local_bidminusdistance - TakeProfit * Point, local_orderexpiretime, Orange);
               }
               else
                  local_orderticket = OrderSend(Symbol(), OP_SELLSTOP, minmaxlot, local_bidminusdistance,
slippage, local_bidminusdistance + StopLoss * Point, local_bidminusdistance - TakeProfit * Point, OrderCmt,
Magic, local_orderexpiretime, Orange);
               if (local_orderticket < 0)
               {
                  local_ordersenderror = TRUE;
                  Print("ERROR SELLSTOP : " + sub_dbl2strbrokerdigits(Bid - local_adjuststoplevel) + " SL:" +
sub_dbl2strbrokerdigits(Ask - local_adjuststoplevel + local_scalpsize) + " TP:" +
sub_dbl2strbrokerdigits(local_g - local_adjuststoplevel - local_scalpsize));
               }
               else
               {
                  PlaySound("news.wav");
                  Print("SELLSTOP : " + sub_dbl2strbrokerdigits(Bid - local_adjuststoplevel) + " SL:" +
sub_dbl2strbrokerdigits(Ask - local_adjuststoplevel + local_scalpsize) + " TP:" +
sub_dbl2strbrokerdigits(local_g - local_adjuststoplevel - local_scalpsize));
               }
            }
            else // local_highspeed == FALSE
            {
               if (local_ihigh - Bid < 0.0)
               {
                  local_orderticket = OrderSend(Symbol(), OP_SELL, minmaxlot, Bid, slippage, 0, 0, OrderCmt,
Magic, local_orderexpiretime, Orange);
                  if (local_orderticket < 0)
                  {
                     local_ordersenderror = TRUE;
                     Print("ERROR SELL Bid:" + sub_dbl2strbrokerdigits(Bid) + " SL:" +
sub_dbl2strbrokerdigits(Ask + local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_g - local_scalpsize));
                  }
                  else
                  {
                     while (true)
                     {
                        local_wasordermodified = OrderModify(local_orderticket, 0, sub_normalizebrokerdigits(Ask
+ local_scalpsize), sub_normalizebrokerdigits(local_g - local_scalpsize), local_orderexpiretime, Orange);
                        break;
                     }
                     PlaySound("news.wav");
                     Print("SELL Bid:" + sub_dbl2strbrokerdigits(Bid) + " SL:" + sub_dbl2strbrokerdigits(Ask +
local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_g - local_scalpsize));
                  }
               }
            }
         }
      }
   }

    if (globalerror >= 0)
       Comment("Robot is initializing...");
    else
    {
       if (globalerror == -2)
          Comment("ERROR -- Instrument " + Symbol() + " prices should have " + brokerdigits + " fraction digits
on broker account");
       else
       {
          local_textstring = TimeToStr(TimeCurrent()) + " tick:" + sub_adjust00instring(tickcounter);
          if (Show_Debug || Verbose)
          {
             local_textstring = local_textstring + "n" + sub_dbl2strbrokerdigits(Scalpfactor) + " " +
sub_dbl2strbrokerdigits(local_scalpsize) + " digits:" + brokerdigits + " " + globalerror + " stopLevel:" +
sub_dbl2strbrokerdigits(local_stoplevel);
             local_textstring = local_textstring + "n" + local_pricedirection + " " +
sub_dbl2strbrokerdigits(local_imahigh) + " " + sub_dbl2strbrokerdigits(local_imalow) + " " +
sub_dbl2strbrokerdigits(zeropointfour) + " exp:" + TimeToStr(local_orderexpiretime, TIME_MINUTES) + "
numOrders:" + local_counter1 + " shouldRepeat:" + local_ordersenderror;
             local_textstring = local_textstring + "ntrailingLimit:" +
sub_dbl2strbrokerdigits(local_adjuststoplevel) + " trailingDist:" + sub_dbl2strbrokerdigits(local_b) + "
trailingResolution:" + sub_dbl2strbrokerdigits(local_c) + " useStopOrders:" + local_highspeed;
          }
          local_textstring = local_textstring + "nBid:" + sub_dbl2strbrokerdigits(Bid) + " Ask:" +
sub_dbl2strbrokerdigits(Ask) + " avgSpread:" + sub_dbl2strbrokerdigits(local_avgspread) + " Commission rate:" +
sub_dbl2strbrokerdigits(commission) + " Real avg. spread:" + sub_dbl2strbrokerdigits(local_h) + " Lots:" +
sub_dbl2strparb(minmaxlot, local_lotstep);
          if (sub_normalizebrokerdigits(local_h) > sub_normalizebrokerdigits(forty * pipette))
          {
             local_textstring = local_textstring + "n" + "Robot is OFF :: Real avg. spread is too high for this
scalping strategy ( " + sub_dbl2strbrokerdigits(local_h) + " > " + sub_dbl2strbrokerdigits(forty * pipette) + "
)";
          }
          Comment(local_textstring);

                                                    Page 7/8
if (local_counter1 != 0 || local_pricedirection != 0 || Verbose)
               sub_printformattedstring(local_textstring);
        }
    }
}

string sub_dbl2strbrokerdigits(double par_a)
{
   return (DoubleToStr(par_a, brokerdigits));
}

string sub_dbl2strparb(double par_a, int par_b)
{
   return (DoubleToStr(par_a, par_b));
}

double sub_normalizebrokerdigits(double par_a)
{
   return (NormalizeDouble(par_a, brokerdigits));
}

string sub_adjust00instring(int par_a)
{
   if (par_a < 10)
      return ("00" + par_a);
   if (par_a < 100)
      return ("0" + par_a);
   return ("" + par_a);
}

double sub_logarithm(double par_a, double par_b)
{
   return (MathLog(par_b) / MathLog(par_a));
}

void sub_printformattedstring(string par_a)
{
   int local_difference;
   int local_a = -1;

    while (local_a < StringLen(par_a))
    {
       local_difference = local_a + 1;
       local_a = StringFind(par_a, "n", local_difference);
       if (local_a == -1)
       {
          Print(StringSubstr(par_a, local_difference));
          return;
       }
       Print(StringSubstr(par_a, local_difference, local_a - local_difference));
    }
}




                                                       Page 8/8

Weitere ähnliche Inhalte

Was ist angesagt?

How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...doughellmann
 
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...doughellmann
 
3 mathematical challenge_code
3 mathematical challenge_code3 mathematical challenge_code
3 mathematical challenge_codeRussell Childs
 
C++ L02-Conversion+enum+Operators
C++ L02-Conversion+enum+OperatorsC++ L02-Conversion+enum+Operators
C++ L02-Conversion+enum+OperatorsMohammad Shaker
 
Embedded systemsproject_2020
Embedded systemsproject_2020Embedded systemsproject_2020
Embedded systemsproject_2020Nikos Mouzakitis
 
Realisation de controlleur VGA(VHDL)
Realisation de controlleur VGA(VHDL)Realisation de controlleur VGA(VHDL)
Realisation de controlleur VGA(VHDL)yahya ayari
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...ssuserd6b1fd
 
A proposal of the OpenFlow controller development support tool
A proposal of the OpenFlow controller development support tool A proposal of the OpenFlow controller development support tool
A proposal of the OpenFlow controller development support tool Yutaka Yasuda
 
Python 炒股指南
Python 炒股指南 Python 炒股指南
Python 炒股指南 Leo Zhou
 
Create xo game in android studio
Create xo game in android studioCreate xo game in android studio
Create xo game in android studioMahmoodGhaemMaghami
 
Scottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RADScottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RADlostcaggy
 
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...ssuserd6b1fd
 

Was ist angesagt? (20)

How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
 
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
 
OpenBot-Code
OpenBot-CodeOpenBot-Code
OpenBot-Code
 
C++ L07-Struct
C++ L07-StructC++ L07-Struct
C++ L07-Struct
 
67WS Seminar Event
67WS Seminar Event67WS Seminar Event
67WS Seminar Event
 
3 mathematical challenge_code
3 mathematical challenge_code3 mathematical challenge_code
3 mathematical challenge_code
 
Open bot
Open bot Open bot
Open bot
 
C++ L02-Conversion+enum+Operators
C++ L02-Conversion+enum+OperatorsC++ L02-Conversion+enum+Operators
C++ L02-Conversion+enum+Operators
 
Embedded systemsproject_2020
Embedded systemsproject_2020Embedded systemsproject_2020
Embedded systemsproject_2020
 
C++ L06-Pointers
C++ L06-PointersC++ L06-Pointers
C++ L06-Pointers
 
Realisation de controlleur VGA(VHDL)
Realisation de controlleur VGA(VHDL)Realisation de controlleur VGA(VHDL)
Realisation de controlleur VGA(VHDL)
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
 
Kts c6-vhdl
Kts c6-vhdlKts c6-vhdl
Kts c6-vhdl
 
A proposal of the OpenFlow controller development support tool
A proposal of the OpenFlow controller development support tool A proposal of the OpenFlow controller development support tool
A proposal of the OpenFlow controller development support tool
 
Python 炒股指南
Python 炒股指南 Python 炒股指南
Python 炒股指南
 
C++ L04-Array+String
C++ L04-Array+StringC++ L04-Array+String
C++ L04-Array+String
 
Create xo game in android studio
Create xo game in android studioCreate xo game in android studio
Create xo game in android studio
 
Scottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RADScottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RAD
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
 

Andere mochten auch

CTI Report_Pulse of Live Streaming in China
CTI Report_Pulse of Live Streaming in ChinaCTI Report_Pulse of Live Streaming in China
CTI Report_Pulse of Live Streaming in ChinaRhea Yushan Liu
 
Did You Know - March 2016
Did You Know - March 2016Did You Know - March 2016
Did You Know - March 2016Europa UOMO
 
Jung e a mediunidade (djalma moita argollo)
Jung e a mediunidade (djalma moita argollo)Jung e a mediunidade (djalma moita argollo)
Jung e a mediunidade (djalma moita argollo)Mario Lima
 
Goal Recognition in Soccer Match
Goal Recognition in Soccer MatchGoal Recognition in Soccer Match
Goal Recognition in Soccer MatchDharmesh Tank
 
The results of applying the principles of corporate governance in corporation...
The results of applying the principles of corporate governance in corporation...The results of applying the principles of corporate governance in corporation...
The results of applying the principles of corporate governance in corporation...Alexander Decker
 
Melvin P. Wissch CV.docx 2015 45
Melvin P. Wissch CV.docx 2015 45Melvin P. Wissch CV.docx 2015 45
Melvin P. Wissch CV.docx 2015 45Melvin Papie Wisseh
 
Mtc tarefa 5 - esquema e resumo - final jvt
Mtc   tarefa 5 - esquema e resumo - final jvtMtc   tarefa 5 - esquema e resumo - final jvt
Mtc tarefa 5 - esquema e resumo - final jvtJovert Freire
 
Did you know - December 2015
Did you know - December 2015Did you know - December 2015
Did you know - December 2015Europa UOMO
 
New Management Model
New Management ModelNew Management Model
New Management ModelRodrigo Silva
 
Did you know Newsletter September 2015
Did you know Newsletter September 2015Did you know Newsletter September 2015
Did you know Newsletter September 2015Europa UOMO
 
Did you know newsletter n2-2015
Did you know newsletter n2-2015Did you know newsletter n2-2015
Did you know newsletter n2-2015Europa UOMO
 
O petróleo é deles, vergonha nacional!
O petróleo é deles, vergonha nacional!O petróleo é deles, vergonha nacional!
O petróleo é deles, vergonha nacional!policialbr
 

Andere mochten auch (20)

CTI Report_Pulse of Live Streaming in China
CTI Report_Pulse of Live Streaming in ChinaCTI Report_Pulse of Live Streaming in China
CTI Report_Pulse of Live Streaming in China
 
Did You Know - March 2016
Did You Know - March 2016Did You Know - March 2016
Did You Know - March 2016
 
San 00001671
San 00001671San 00001671
San 00001671
 
Cv José Martins Ferreira Junior
Cv José Martins Ferreira JuniorCv José Martins Ferreira Junior
Cv José Martins Ferreira Junior
 
1 executivo
1   executivo1   executivo
1 executivo
 
Jung e a mediunidade (djalma moita argollo)
Jung e a mediunidade (djalma moita argollo)Jung e a mediunidade (djalma moita argollo)
Jung e a mediunidade (djalma moita argollo)
 
Goal Recognition in Soccer Match
Goal Recognition in Soccer MatchGoal Recognition in Soccer Match
Goal Recognition in Soccer Match
 
The results of applying the principles of corporate governance in corporation...
The results of applying the principles of corporate governance in corporation...The results of applying the principles of corporate governance in corporation...
The results of applying the principles of corporate governance in corporation...
 
Melvin P. Wissch CV.docx 2015 45
Melvin P. Wissch CV.docx 2015 45Melvin P. Wissch CV.docx 2015 45
Melvin P. Wissch CV.docx 2015 45
 
Mossack 17.1
Mossack 17.1Mossack 17.1
Mossack 17.1
 
Mtc tarefa 5 - esquema e resumo - final jvt
Mtc   tarefa 5 - esquema e resumo - final jvtMtc   tarefa 5 - esquema e resumo - final jvt
Mtc tarefa 5 - esquema e resumo - final jvt
 
Did you know - December 2015
Did you know - December 2015Did you know - December 2015
Did you know - December 2015
 
Bienvenidos
BienvenidosBienvenidos
Bienvenidos
 
Andrey Smetanin CV
Andrey Smetanin CVAndrey Smetanin CV
Andrey Smetanin CV
 
Cibercultura
CiberculturaCibercultura
Cibercultura
 
New Management Model
New Management ModelNew Management Model
New Management Model
 
Did you know Newsletter September 2015
Did you know Newsletter September 2015Did you know Newsletter September 2015
Did you know Newsletter September 2015
 
Did you know newsletter n2-2015
Did you know newsletter n2-2015Did you know newsletter n2-2015
Did you know newsletter n2-2015
 
O petróleo é deles, vergonha nacional!
O petróleo é deles, vergonha nacional!O petróleo é deles, vergonha nacional!
O petróleo é deles, vergonha nacional!
 
Juan castro activiad1_2mapac
Juan castro activiad1_2mapacJuan castro activiad1_2mapac
Juan castro activiad1_2mapac
 

Ähnlich wie Mdp plus 2.1

Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Lin Yo-An
 
Inventory aging report using oracle discoverer desktop
Inventory aging report using oracle discoverer desktopInventory aging report using oracle discoverer desktop
Inventory aging report using oracle discoverer desktopAhmed Elshayeb
 
How to transfer bad PLSQL into good (AAAPEKS23)
How to transfer bad PLSQL into good (AAAPEKS23)How to transfer bad PLSQL into good (AAAPEKS23)
How to transfer bad PLSQL into good (AAAPEKS23)Maik Becker
 
MySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web ApplicationsMySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web ApplicationsOSSCube
 
LLVM Backend の紹介
LLVM Backend の紹介LLVM Backend の紹介
LLVM Backend の紹介Akira Maruoka
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfSIGMATAX1
 
8 bit single cycle processor
8 bit single cycle processor8 bit single cycle processor
8 bit single cycle processorDhaval Kaneria
 
Tool sdl2pml
Tool sdl2pmlTool sdl2pml
Tool sdl2pmlS56WBV
 
Sine Wave Generator with controllable frequency displayed on a seven segment ...
Sine Wave Generator with controllable frequency displayed on a seven segment ...Sine Wave Generator with controllable frequency displayed on a seven segment ...
Sine Wave Generator with controllable frequency displayed on a seven segment ...Karthik Rathinavel
 
Blood pressure set programming
Blood pressure set programmingBlood pressure set programming
Blood pressure set programmingNoorshahida Kassim
 
GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf
 GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf
GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdfalltiusind
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuningAOE
 
2.1 ### uVision Project, (C) Keil Software .docx
2.1   ### uVision Project, (C) Keil Software    .docx2.1   ### uVision Project, (C) Keil Software    .docx
2.1 ### uVision Project, (C) Keil Software .docxtarifarmarie
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Svet Ivantchev
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたAkira Maruoka
 

Ähnlich wie Mdp plus 2.1 (20)

Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
 
Inventory aging report using oracle discoverer desktop
Inventory aging report using oracle discoverer desktopInventory aging report using oracle discoverer desktop
Inventory aging report using oracle discoverer desktop
 
Lampiran 1.programdocx
Lampiran 1.programdocxLampiran 1.programdocx
Lampiran 1.programdocx
 
How to transfer bad PLSQL into good (AAAPEKS23)
How to transfer bad PLSQL into good (AAAPEKS23)How to transfer bad PLSQL into good (AAAPEKS23)
How to transfer bad PLSQL into good (AAAPEKS23)
 
MySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web ApplicationsMySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web Applications
 
PIC and LCD
PIC and LCDPIC and LCD
PIC and LCD
 
LLVM Backend の紹介
LLVM Backend の紹介LLVM Backend の紹介
LLVM Backend の紹介
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
 
8 bit single cycle processor
8 bit single cycle processor8 bit single cycle processor
8 bit single cycle processor
 
Tool sdl2pml
Tool sdl2pmlTool sdl2pml
Tool sdl2pml
 
Sine Wave Generator with controllable frequency displayed on a seven segment ...
Sine Wave Generator with controllable frequency displayed on a seven segment ...Sine Wave Generator with controllable frequency displayed on a seven segment ...
Sine Wave Generator with controllable frequency displayed on a seven segment ...
 
Blood pressure set programming
Blood pressure set programmingBlood pressure set programming
Blood pressure set programming
 
GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf
 GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf
GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
 
2.1 ### uVision Project, (C) Keil Software .docx
2.1   ### uVision Project, (C) Keil Software    .docx2.1   ### uVision Project, (C) Keil Software    .docx
2.1 ### uVision Project, (C) Keil Software .docx
 
Verilog_Examples (1).pdf
Verilog_Examples (1).pdfVerilog_Examples (1).pdf
Verilog_Examples (1).pdf
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
 
Message in a bottle
Message in a bottleMessage in a bottle
Message in a bottle
 

Kürzlich hochgeladen

WheelTug PLC Pitch Deck | Investor Insights | April 2024
WheelTug PLC Pitch Deck | Investor Insights | April 2024WheelTug PLC Pitch Deck | Investor Insights | April 2024
WheelTug PLC Pitch Deck | Investor Insights | April 2024Hector Del Castillo, CPM, CPMM
 
9654467111 Call Girls In Katwaria Sarai Short 1500 Night 6000
9654467111 Call Girls In Katwaria Sarai Short 1500 Night 60009654467111 Call Girls In Katwaria Sarai Short 1500 Night 6000
9654467111 Call Girls In Katwaria Sarai Short 1500 Night 6000Sapana Sha
 
slideshare_2404_presentation materials_en.pdf
slideshare_2404_presentation materials_en.pdfslideshare_2404_presentation materials_en.pdf
slideshare_2404_presentation materials_en.pdfsansanir
 
Corporate Presentation Probe April 2024.pdf
Corporate Presentation Probe April 2024.pdfCorporate Presentation Probe April 2024.pdf
Corporate Presentation Probe April 2024.pdfProbe Gold
 
9654467111 Low Rate Call Girls In Tughlakabad, Delhi NCR
9654467111 Low Rate Call Girls In Tughlakabad, Delhi NCR9654467111 Low Rate Call Girls In Tughlakabad, Delhi NCR
9654467111 Low Rate Call Girls In Tughlakabad, Delhi NCRSapana Sha
 
如何办理密苏里大学堪萨斯分校毕业证(文凭)UMKC学位证书
如何办理密苏里大学堪萨斯分校毕业证(文凭)UMKC学位证书如何办理密苏里大学堪萨斯分校毕业证(文凭)UMKC学位证书
如何办理密苏里大学堪萨斯分校毕业证(文凭)UMKC学位证书Fir La
 
the 25 most beautiful words for a loving and lasting relationship.pdf
the 25 most beautiful words for a loving and lasting relationship.pdfthe 25 most beautiful words for a loving and lasting relationship.pdf
the 25 most beautiful words for a loving and lasting relationship.pdfFrancenel Paul
 
The Concept of Humanity in Islam and its effects at future of humanity
The Concept of Humanity in Islam and its effects at future of humanityThe Concept of Humanity in Islam and its effects at future of humanity
The Concept of Humanity in Islam and its effects at future of humanityJohanAspro
 
如何办理北卡罗来纳大学教堂山分校毕业证(文凭)UNC学位证书
如何办理北卡罗来纳大学教堂山分校毕业证(文凭)UNC学位证书如何办理北卡罗来纳大学教堂山分校毕业证(文凭)UNC学位证书
如何办理北卡罗来纳大学教堂山分校毕业证(文凭)UNC学位证书Fir La
 
Collective Mining | Corporate Presentation - April 2024
Collective Mining | Corporate Presentation - April 2024Collective Mining | Corporate Presentation - April 2024
Collective Mining | Corporate Presentation - April 2024CollectiveMining1
 
Basic Accountants in|TaxlinkConcept.pdf
Basic  Accountants in|TaxlinkConcept.pdfBasic  Accountants in|TaxlinkConcept.pdf
Basic Accountants in|TaxlinkConcept.pdftaxlinkcpa
 
Corporate Presentation Probe April 2024.pdf
Corporate Presentation Probe April 2024.pdfCorporate Presentation Probe April 2024.pdf
Corporate Presentation Probe April 2024.pdfProbe Gold
 
The resilient U.S. late-cycle expansion contributed to a stalling pattern in ...
The resilient U.S. late-cycle expansion contributed to a stalling pattern in ...The resilient U.S. late-cycle expansion contributed to a stalling pattern in ...
The resilient U.S. late-cycle expansion contributed to a stalling pattern in ...Kumaran637735
 
如何办理东俄勒冈大学毕业证(文凭)EOU学位证书
如何办理东俄勒冈大学毕业证(文凭)EOU学位证书如何办理东俄勒冈大学毕业证(文凭)EOU学位证书
如何办理东俄勒冈大学毕业证(文凭)EOU学位证书Fir La
 
Osisko Gold Royalties Ltd - Corporate Presentation, April 23, 2024
Osisko Gold Royalties Ltd - Corporate Presentation, April 23, 2024Osisko Gold Royalties Ltd - Corporate Presentation, April 23, 2024
Osisko Gold Royalties Ltd - Corporate Presentation, April 23, 2024Osisko Gold Royalties Ltd
 
Nicola Mining Inc. Corporate Presentation April 2024
Nicola Mining Inc. Corporate Presentation April 2024Nicola Mining Inc. Corporate Presentation April 2024
Nicola Mining Inc. Corporate Presentation April 2024nicola_mining
 

Kürzlich hochgeladen (20)

young call girls in Hauz Khas,🔝 9953056974 🔝 escort Service
young call girls in Hauz Khas,🔝 9953056974 🔝 escort Serviceyoung call girls in Hauz Khas,🔝 9953056974 🔝 escort Service
young call girls in Hauz Khas,🔝 9953056974 🔝 escort Service
 
WheelTug PLC Pitch Deck | Investor Insights | April 2024
WheelTug PLC Pitch Deck | Investor Insights | April 2024WheelTug PLC Pitch Deck | Investor Insights | April 2024
WheelTug PLC Pitch Deck | Investor Insights | April 2024
 
9654467111 Call Girls In Katwaria Sarai Short 1500 Night 6000
9654467111 Call Girls In Katwaria Sarai Short 1500 Night 60009654467111 Call Girls In Katwaria Sarai Short 1500 Night 6000
9654467111 Call Girls In Katwaria Sarai Short 1500 Night 6000
 
slideshare_2404_presentation materials_en.pdf
slideshare_2404_presentation materials_en.pdfslideshare_2404_presentation materials_en.pdf
slideshare_2404_presentation materials_en.pdf
 
Corporate Presentation Probe April 2024.pdf
Corporate Presentation Probe April 2024.pdfCorporate Presentation Probe April 2024.pdf
Corporate Presentation Probe April 2024.pdf
 
9654467111 Low Rate Call Girls In Tughlakabad, Delhi NCR
9654467111 Low Rate Call Girls In Tughlakabad, Delhi NCR9654467111 Low Rate Call Girls In Tughlakabad, Delhi NCR
9654467111 Low Rate Call Girls In Tughlakabad, Delhi NCR
 
如何办理密苏里大学堪萨斯分校毕业证(文凭)UMKC学位证书
如何办理密苏里大学堪萨斯分校毕业证(文凭)UMKC学位证书如何办理密苏里大学堪萨斯分校毕业证(文凭)UMKC学位证书
如何办理密苏里大学堪萨斯分校毕业证(文凭)UMKC学位证书
 
the 25 most beautiful words for a loving and lasting relationship.pdf
the 25 most beautiful words for a loving and lasting relationship.pdfthe 25 most beautiful words for a loving and lasting relationship.pdf
the 25 most beautiful words for a loving and lasting relationship.pdf
 
The Concept of Humanity in Islam and its effects at future of humanity
The Concept of Humanity in Islam and its effects at future of humanityThe Concept of Humanity in Islam and its effects at future of humanity
The Concept of Humanity in Islam and its effects at future of humanity
 
如何办理北卡罗来纳大学教堂山分校毕业证(文凭)UNC学位证书
如何办理北卡罗来纳大学教堂山分校毕业证(文凭)UNC学位证书如何办理北卡罗来纳大学教堂山分校毕业证(文凭)UNC学位证书
如何办理北卡罗来纳大学教堂山分校毕业证(文凭)UNC学位证书
 
Call Girls in South Ex⎝⎝9953056974⎝⎝ Escort Delhi NCR
Call Girls in South Ex⎝⎝9953056974⎝⎝ Escort Delhi NCRCall Girls in South Ex⎝⎝9953056974⎝⎝ Escort Delhi NCR
Call Girls in South Ex⎝⎝9953056974⎝⎝ Escort Delhi NCR
 
Collective Mining | Corporate Presentation - April 2024
Collective Mining | Corporate Presentation - April 2024Collective Mining | Corporate Presentation - April 2024
Collective Mining | Corporate Presentation - April 2024
 
Basic Accountants in|TaxlinkConcept.pdf
Basic  Accountants in|TaxlinkConcept.pdfBasic  Accountants in|TaxlinkConcept.pdf
Basic Accountants in|TaxlinkConcept.pdf
 
Model Call Girl in Uttam Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Uttam Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Uttam Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Uttam Nagar Delhi reach out to us at 🔝9953056974🔝
 
Corporate Presentation Probe April 2024.pdf
Corporate Presentation Probe April 2024.pdfCorporate Presentation Probe April 2024.pdf
Corporate Presentation Probe April 2024.pdf
 
The resilient U.S. late-cycle expansion contributed to a stalling pattern in ...
The resilient U.S. late-cycle expansion contributed to a stalling pattern in ...The resilient U.S. late-cycle expansion contributed to a stalling pattern in ...
The resilient U.S. late-cycle expansion contributed to a stalling pattern in ...
 
如何办理东俄勒冈大学毕业证(文凭)EOU学位证书
如何办理东俄勒冈大学毕业证(文凭)EOU学位证书如何办理东俄勒冈大学毕业证(文凭)EOU学位证书
如何办理东俄勒冈大学毕业证(文凭)EOU学位证书
 
Osisko Gold Royalties Ltd - Corporate Presentation, April 23, 2024
Osisko Gold Royalties Ltd - Corporate Presentation, April 23, 2024Osisko Gold Royalties Ltd - Corporate Presentation, April 23, 2024
Osisko Gold Royalties Ltd - Corporate Presentation, April 23, 2024
 
Nicola Mining Inc. Corporate Presentation April 2024
Nicola Mining Inc. Corporate Presentation April 2024Nicola Mining Inc. Corporate Presentation April 2024
Nicola Mining Inc. Corporate Presentation April 2024
 
young Call girls in Dwarka sector 1🔝 9953056974 🔝 Delhi escort Service
young Call girls in Dwarka sector 1🔝 9953056974 🔝 Delhi escort Serviceyoung Call girls in Dwarka sector 1🔝 9953056974 🔝 Delhi escort Service
young Call girls in Dwarka sector 1🔝 9953056974 🔝 Delhi escort Service
 

Mdp plus 2.1

  • 1. // ------------------------------------------------------------------------------------------------- // MDP-Plus v. 2.1.2 // // Based on MillionDollarPips - (ANY PAIR + NO DLL) - ver 1.1.0 // // Someone at a russian forum fixed a Stack Overflow problem, added NDD-mode (ECN-mode) // and moved the DLL-functions in the mql4-code. // // Sept-2011 by Capella by at http://www.worldwide-invest.org // - Cleaned code from unused code, proper variable names and sub-names. // // Ver. 1.0 - 2011-09-24 by Capella at http://www.worldwide-invest.org // - Added Print lines for STOPLEVEL when errors (for debugging purposes) // - Removed unused externals and variables // - Moved dynamic TP/SL and trading signals constants to externals, // as VolatilityLimit and Scalpfactor. // - Forced TrailingStop // // Ver. 2.0 - 2011-10-19 by Capella at http://www.worldwide-invest.org // - Fixing bugs, and removed unused code. // - Forced Trailing, as no-trailing cannot generate profit // - Forced HighSpeed, as false mode cannot give good result // - Added additional settings for scalping - UseMovingAverage, // UseBollingerBands, and OrderExpireSeconds // - Automatic adjusted to broker STOPLEVEL, to avoid OrderSend error 130 // Ver 2.1 - 2011-11-91 by Capella at http://www.worldwide-invest.org // - Added Indicatorperiod as external // - Modified calculation of variable that triggers trade (local_pricedirection) // - Removed Distance as an external, and automatically adjust Distance to be the same as stoplevel // - Removed call for sub_moveandfillarrays as it doesn't make any difference // Ver 2.1.1 - 2011-11-05 by Capella at http://www.worldwide-invest.org // - Fixed a bug in the calculation of local_highest and local_lowest that caused wrong call for // OrderModify. // - Changed the calculation of STOPLEVEL to also consider FREEZELEVEL // Ver 2.1.2 - 2011-11-06 by Capella // - Changed default settings according to optimized backtests // - Added external parameter Deviation for iBands, default 0 // ------------------------------------------------------------------------------------------------- #property show_inputs #include <stdlib.mqh> //----------------------- Externals ---------------------------------------------------------------- // All externals here have their name starting with a CAPITAL character extern string Configuration = "==== Configuration ===="; extern int Magic = 0; extern string OrderCmt = ""; extern bool NDDmode = FALSE; extern bool Show_Debug = FALSE; extern bool Verbose = FALSE; extern string ScalpingSettings = "==== Scalping settings ===="; extern double TakeProfit = 10.0; // TakeProfit from as many points. Default 10 (= 1 pip) extern double StopLoss = 60.0; // StopLoss from as many points. Default 60 (= 6 pips) extern double Trailing_Start = 0; // Start trailing profit from as so many pips. Default 0 extern double VolatilityLimit = 180; // Default 180. Can normally be between 100 and 300 extern double Scalpfactor = 66; // 60 to 77 - only used if larger than broker StopLevel extern bool UseMovingAverage = TRUE; // User two iMA as channell extern bool UseBollingerBands = TRUE; // Use iBands as channel extern int IndicatorPeriod = 30; // Period for iMA and iBands extern double Deviation = 2.00; // Deviation for iBands extern int OrderExpireSeconds = 3600; // Orders are deted after so many seconds extern string Money_Management = "==== Money Management ===="; extern double Min_Lots = 0.01; extern double Max_Lots = 100.0; extern double Risk = 100.0; //--------------------------- Globals -------------------------------------------------------------- // All globals have their name written in lower case characters // bool condition1; bool condition2 = FALSE; bool trailingstop = TRUE; int distance = 0; int brokerdigits = 0; int slippage = 3; int array_tickcounts[30]; int globalerror = 0; int lasttime = 0; int tickcounter = 0; int upto30counter = 0; int AccNum; double zero = 0.0; double zeropointfour = 0.4; double one = 1.0; double five = 5.0; double ten = 10.0; double twenty = 20.0; Page 1/8
  • 2. double forty = 40.0; double multiplier; double commission = 0.0; double minmaxlot = 0.1; double maxamount = 0.0; double pipette = 0.0; double upper; double lower; double array_bid[30]; double array_ask[30]; double array_spread[30]; //======================= Program initialization =========================================================== int init() { int stoplevel; ArrayInitialize(array_spread, 0); VolatilityLimit = VolatilityLimit * Point; Scalpfactor = Scalpfactor * 10 * Point / 3; brokerdigits = Digits; pipette = Point; stoplevel = MathMax(MarketInfo(Symbol(), MODE_FREEZELEVEL), MarketInfo(Symbol(), MODE_STOPLEVEL)); if (TakeProfit < stoplevel) TakeProfit = stoplevel; if (StopLoss < stoplevel) StopLoss = stoplevel; if (distance < stoplevel) distance = stoplevel; if (MathMod(Digits, 2) == 0) slippage = 0; else globalerror = -1; start(); return (0); } //====================== Program start =================================== int start() { if (brokerdigits == 0) { init(); return; } sub_trade(); return (0); } //===================== Subroutines starts here ========================================= // All subs have their names starting with sub_ // Exception are the standard routines init() and start() // // Notation: // All parameters in subs have their names starting with par_ // All local variables in subs have thewir names starting with local_ // void sub_trade() { string local_textstring; bool local_wasordermodified; bool local_highspeed; bool local_ordersenderror; bool local_isbidgreaterthanima; bool local_isbidgreaterthanibands; bool local_isbidgreaterthanindy; int local_orderticket; int local_lotstep; int local_orderexpiretime; int local_bidpart; int local_askpart; int local_loopcount2; int local_loopcount1; int local_pricedirection; int local_counter1; int local_counter2; double local_askplusdistance; double local_bidminusdistance; double local_a; double local_b; double local_c; double local_scalpsize; Page 2/8
  • 3. double local_d; double local_orderstoploss; double local_ordertakeprofit; double local_tpadjust; double local_ihigh; double local_ilow; double local_imalow; double local_imahigh; double local_imadiff; double local_ibandsupper; double local_ibandslower; double local_ibandsdiff; double local_highest; double local_lowest; double local_stoplevel; double local_spread; double local_adjuststoplevel; double local_e; double local_avgspread; double local_f; double local_g; double local_h; double local_ihighilowdiff; double local_i; if (lasttime < Time[0]) { lasttime = Time[0]; tickcounter = 0; } else tickcounter++; // Calculate a channel based on some indicators local_ihigh = iHigh(Symbol(), PERIOD_M1, 0); local_ilow = iLow(Symbol(), PERIOD_M1, 0); local_ihighilowdiff = local_ihigh - local_ilow; local_imalow = iMA(NULL, PERIOD_M1, IndicatorPeriod, 0, MODE_LWMA, PRICE_LOW, 0); local_imahigh = iMA(NULL, PERIOD_M1, IndicatorPeriod, 0, MODE_LWMA, PRICE_HIGH, 0); local_imadiff = local_imahigh - local_imalow; local_isbidgreaterthanima = Bid >= local_imalow + local_imadiff / 2; local_ibandsupper = iCustom(NULL, PERIOD_M1, "Bands", IndicatorPeriod, 0, Deviation, MODE_UPPER, 0); local_ibandslower = iCustom(NULL, PERIOD_M1, "Bands", IndicatorPeriod, 0, Deviation, MODE_LOWER, 0); local_ibandsdiff = local_ibandsupper - local_ibandslower; local_isbidgreaterthanibands = Bid >= local_ibandslower + local_ibandsdiff / 2; // local_isbidgreaterthanindy is only used for OrderModify on previous BUY_STOP and SELL_STOP local_isbidgreaterthanindy = FALSE; if (UseMovingAverage == FALSE && UseBollingerBands == TRUE) { local_isbidgreaterthanindy = TRUE; local_highest = local_ibandsupper; local_lowest = local_ibandslower; } else if (UseMovingAverage == TRUE && UseBollingerBands == FALSE) { local_isbidgreaterthanindy = TRUE; local_highest = local_imahigh; local_lowest = local_imalow; } else if (UseMovingAverage == TRUE && UseBollingerBands == TRUE) if (local_isbidgreaterthanima == TRUE && local_isbidgreaterthanibands == TRUE) { local_isbidgreaterthanindy = TRUE; local_highest = MathMax(local_ibandsupper, local_imahigh); local_lowest = MathMin(local_ibandslower, local_imalow); } if (!condition2) { for (local_loopcount2 = OrdersTotal() - 1; local_loopcount2 >= 0; local_loopcount2--) { OrderSelect(local_loopcount2, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderCloseTime() != 0 && OrderClosePrice() != OrderOpenPrice() && OrderProfit() != 0.0 && OrderComment() != "partial close" && StringFind(OrderComment(), "[sl]from #") == -1 && StringFind(OrderComment(), "[tp]from #") == -1) { condition2 = TRUE; local_a = MathAbs(OrderProfit() / (OrderClosePrice() - OrderOpenPrice())); commission = (-OrderCommission()) / local_a; Print("Commission_Rate : " + sub_dbl2strbrokerdigits(commission)); break; } } } if (!condition2) { for (local_loopcount2 = OrdersHistoryTotal() - 1; local_loopcount2 >= 0; local_loopcount2--) { Page 3/8
  • 4. OrderSelect(local_loopcount2, SELECT_BY_POS, MODE_HISTORY); if (OrderSymbol() == Symbol() && OrderCloseTime() != 0 && OrderClosePrice() != OrderOpenPrice() && OrderProfit() != 0.0 && OrderComment() != "partial close" && StringFind(OrderComment(), "[sl]from #") == -1 && StringFind(OrderComment(), "[tp]from #") == -1) { condition2 = TRUE; local_a = MathAbs(OrderProfit() / (OrderClosePrice() - OrderOpenPrice())); commission = (-OrderCommission()) / local_a; Print("Commission_Rate : " + sub_dbl2strbrokerdigits(commission)); break; } } } local_stoplevel = MarketInfo(Symbol(), MODE_STOPLEVEL) * Point; local_spread = Ask - Bid; local_adjuststoplevel = 0.5; if (local_adjuststoplevel < local_stoplevel - 5.0 * pipette) { local_highspeed = FALSE; local_b = forty * pipette; local_adjuststoplevel = ten * pipette; local_c = five * pipette; } else { local_highspeed = TRUE; local_b = twenty * pipette; local_adjuststoplevel = zero * pipette; local_c = Trailing_Start * pipette; } local_b = MathMax(local_b, local_stoplevel); if (local_highspeed) local_adjuststoplevel = MathMax(local_adjuststoplevel, local_stoplevel); ArrayCopy(array_spread, array_spread, 0, 1, 29); array_spread[29] = local_spread; if (upto30counter < 30) upto30counter++; local_e = 0; local_loopcount2 = 29; for (local_loopcount1 = 0; local_loopcount1 < upto30counter; local_loopcount1++) { local_e += array_spread[local_loopcount2]; local_loopcount2--; } local_avgspread = local_e / upto30counter; if (!condition2 && local_avgspread < 15.0 * pipette) commission = 15.0 * pipette - local_avgspread; local_f = sub_normalizebrokerdigits(Ask + commission); local_g = sub_normalizebrokerdigits(Bid - commission); local_h = local_avgspread + commission; if(local_ihighilowdiff > VolatilityLimit) { if (Bid < local_lowest) local_pricedirection = -1; else if (Bid > local_highest) local_pricedirection = 1; } local_scalpsize = MathMax(local_stoplevel, Scalpfactor); if (Bid == 0.0 || MarketInfo(Symbol(), MODE_LOTSIZE) == 0.0) local_scalpsize = 0; local_i = local_scalpsize + local_avgspread + commission; local_orderexpiretime = TimeCurrent() + OrderExpireSeconds; if (MarketInfo(Symbol(), MODE_LOTSTEP) == 0.0) local_lotstep = 5; else local_lotstep = sub_logarithm(0.1, MarketInfo(Symbol(), MODE_LOTSTEP)); if (Risk < 0.001 || Risk > 1000.0) { Comment("ERROR -- Invalid Risk Value."); return; } if (AccountBalance() <= 0.0) { Comment("ERROR -- Account Balance is " + DoubleToStr(MathRound(AccountBalance()), 0)); return; } if (local_scalpsize != 0.0) { maxamount = MathMax(AccountBalance(), maxamount); Page 4/8
  • 5. local_d = MathMin(AccountFreeMargin() * AccountLeverage() / 2.0, maxamount * Risk / 100.0 * Bid / local_i); minmaxlot = local_d / MarketInfo(Symbol(), MODE_LOTSIZE); minmaxlot = NormalizeDouble(minmaxlot, local_lotstep); minmaxlot = MathMax(Min_Lots, minmaxlot); minmaxlot = MathMax(MarketInfo(Symbol(), MODE_MINLOT), minmaxlot); minmaxlot = MathMin(Max_Lots, minmaxlot); minmaxlot = MathMin(MarketInfo(Symbol(), MODE_MAXLOT), minmaxlot); } // Run through already open orders and modify if necessary local_counter1 = 0; local_counter2 = 0; for (local_loopcount2 = 0; local_loopcount2 < OrdersTotal(); local_loopcount2++) { OrderSelect(local_loopcount2, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == Magic && OrderCloseTime() == 0) { if (OrderSymbol() != Symbol()) { local_counter2++; continue; } switch (OrderType()) { case OP_BUY: while (trailingstop) { local_orderstoploss = OrderStopLoss(); local_ordertakeprofit = OrderTakeProfit(); if (!(local_ordertakeprofit < sub_normalizebrokerdigits(local_f + local_b) && local_f + local_b - local_ordertakeprofit > local_c)) break; local_orderstoploss = sub_normalizebrokerdigits(Bid - local_b); local_ordertakeprofit = sub_normalizebrokerdigits(local_f + local_b); local_wasordermodified = OrderModify(OrderTicket(), 0, local_orderstoploss, local_ordertakeprofit, local_orderexpiretime, Lime); break; } local_counter1++; break; case OP_SELL: while (trailingstop) { local_orderstoploss = OrderStopLoss(); local_ordertakeprofit = OrderTakeProfit(); if (!(local_ordertakeprofit > sub_normalizebrokerdigits(local_g - local_b) && local_ordertakeprofit - local_g + local_b > local_c)) break; local_orderstoploss = sub_normalizebrokerdigits(Ask + local_b); local_ordertakeprofit = sub_normalizebrokerdigits(local_g - local_b); local_wasordermodified = OrderModify(OrderTicket(), 0, local_orderstoploss, local_ordertakeprofit, local_orderexpiretime, Orange); break; } local_counter1++; break; case OP_BUYSTOP: if (!local_isbidgreaterthanindy) { local_tpadjust = OrderTakeProfit() - OrderOpenPrice() - commission; while (true) { if (!(sub_normalizebrokerdigits(Ask + local_adjuststoplevel) < OrderOpenPrice() && OrderOpenPrice() - Ask - local_adjuststoplevel > local_c)) break; local_wasordermodified = OrderModify(OrderTicket(), sub_normalizebrokerdigits(Ask + local_adjuststoplevel), sub_normalizebrokerdigits(Bid + local_adjuststoplevel - local_tpadjust), sub_normalizebrokerdigits(local_f + local_adjuststoplevel + local_tpadjust), 0, Lime); break; } local_counter1++; } else OrderDelete(OrderTicket()); break; case OP_SELLSTOP: if (local_isbidgreaterthanindy) { local_tpadjust = OrderOpenPrice() - OrderTakeProfit() - commission; while (true) { if (!(sub_normalizebrokerdigits(Bid - local_adjuststoplevel) > OrderOpenPrice() && Bid - local_adjuststoplevel - OrderOpenPrice() > local_c)) break; local_wasordermodified = OrderModify(OrderTicket(), sub_normalizebrokerdigits(Bid - local_adjuststoplevel), sub_normalizebrokerdigits(Ask - local_adjuststoplevel + local_tpadjust), sub_normalizebrokerdigits(local_g - local_adjuststoplevel - local_tpadjust), 0, Orange); break; } local_counter1++; } Page 5/8
  • 6. else OrderDelete(OrderTicket()); } } } local_ordersenderror = FALSE; if (globalerror >= 0 || globalerror == -2) { local_bidpart = NormalizeDouble(Bid / pipette, 0); local_askpart = NormalizeDouble(Ask / pipette, 0); if (local_bidpart % 10 != 0 || local_askpart % 10 != 0) globalerror = -1; else { if (globalerror >= 0 && globalerror < 10) globalerror++; else globalerror = -2; } } // Open new BUY- or SELL-orders, or BUYSTOP or SELLSTOP orders if (local_scalpsize != 0.0 && local_counter1 == 0 && local_pricedirection != 0 && sub_normalizebrokerdigits(local_h) <= sub_normalizebrokerdigits(forty * pipette) && globalerror == -1) { if (local_pricedirection < 0) { if (local_highspeed) { local_askplusdistance = Ask + distance * Point; if (NDDmode) { local_orderticket = OrderSend(Symbol(), OP_BUYSTOP, minmaxlot, local_askplusdistance, slippage, 0, 0, OrderCmt, Magic, 0, Lime); if (OrderSelect(local_orderticket, SELECT_BY_TICKET)) OrderModify(OrderTicket(), OrderOpenPrice(), local_askplusdistance - StopLoss * Point, local_askplusdistance + TakeProfit * Point, local_orderexpiretime, Lime); } else local_orderticket = OrderSend(Symbol(), OP_BUYSTOP, minmaxlot, local_askplusdistance, slippage, local_askplusdistance - StopLoss * Point, local_askplusdistance + TakeProfit * Point, OrderCmt, Magic, local_orderexpiretime, Lime); if (local_orderticket < 0) { local_ordersenderror = TRUE; Print("ERROR BUYSTOP : " + sub_dbl2strbrokerdigits(Ask + local_adjuststoplevel) + " SL:" + sub_dbl2strbrokerdigits(Bid + local_adjuststoplevel - local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_f + local_adjuststoplevel + local_scalpsize)); } else { PlaySound("news.wav"); Print("BUYSTOP : " + sub_dbl2strbrokerdigits(Ask + local_adjuststoplevel) + " SL:" + sub_dbl2strbrokerdigits(Bid + local_adjuststoplevel - local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_f + local_adjuststoplevel + local_scalpsize)); } } else // local_highspeed == FALSE { if (Bid - local_ilow > 0.0) { local_orderticket = OrderSend(Symbol(), OP_BUY, minmaxlot, Ask, slippage, 0, 0, OrderCmt, Magic, local_orderexpiretime, Lime); if (local_orderticket < 0) { local_ordersenderror = TRUE; Print("ERROR BUY Ask:" + sub_dbl2strbrokerdigits(Ask) + " SL:" + sub_dbl2strbrokerdigits(Bid - local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_f + local_scalpsize)); } else { while (true) { local_wasordermodified = OrderModify(local_orderticket, 0, sub_normalizebrokerdigits(Bid - local_scalpsize), sub_normalizebrokerdigits(local_f + local_scalpsize), local_orderexpiretime, Lime); break; } PlaySound("news.wav"); Print("BUY Ask:" + sub_dbl2strbrokerdigits(Ask) + " SL:" + sub_dbl2strbrokerdigits(Bid - local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_f + local_scalpsize)); } } } } else { if (local_pricedirection > 0) { if (local_highspeed) { Page 6/8
  • 7. local_bidminusdistance = Bid - distance * Point; if (NDDmode) { local_orderticket = OrderSend(Symbol(), OP_SELLSTOP, minmaxlot, local_bidminusdistance, slippage, 0, 0, OrderCmt, Magic, 0, Orange); if (OrderSelect(local_orderticket, SELECT_BY_TICKET)) OrderModify(OrderTicket(), OrderOpenPrice(), local_bidminusdistance + StopLoss * Point, local_bidminusdistance - TakeProfit * Point, local_orderexpiretime, Orange); } else local_orderticket = OrderSend(Symbol(), OP_SELLSTOP, minmaxlot, local_bidminusdistance, slippage, local_bidminusdistance + StopLoss * Point, local_bidminusdistance - TakeProfit * Point, OrderCmt, Magic, local_orderexpiretime, Orange); if (local_orderticket < 0) { local_ordersenderror = TRUE; Print("ERROR SELLSTOP : " + sub_dbl2strbrokerdigits(Bid - local_adjuststoplevel) + " SL:" + sub_dbl2strbrokerdigits(Ask - local_adjuststoplevel + local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_g - local_adjuststoplevel - local_scalpsize)); } else { PlaySound("news.wav"); Print("SELLSTOP : " + sub_dbl2strbrokerdigits(Bid - local_adjuststoplevel) + " SL:" + sub_dbl2strbrokerdigits(Ask - local_adjuststoplevel + local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_g - local_adjuststoplevel - local_scalpsize)); } } else // local_highspeed == FALSE { if (local_ihigh - Bid < 0.0) { local_orderticket = OrderSend(Symbol(), OP_SELL, minmaxlot, Bid, slippage, 0, 0, OrderCmt, Magic, local_orderexpiretime, Orange); if (local_orderticket < 0) { local_ordersenderror = TRUE; Print("ERROR SELL Bid:" + sub_dbl2strbrokerdigits(Bid) + " SL:" + sub_dbl2strbrokerdigits(Ask + local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_g - local_scalpsize)); } else { while (true) { local_wasordermodified = OrderModify(local_orderticket, 0, sub_normalizebrokerdigits(Ask + local_scalpsize), sub_normalizebrokerdigits(local_g - local_scalpsize), local_orderexpiretime, Orange); break; } PlaySound("news.wav"); Print("SELL Bid:" + sub_dbl2strbrokerdigits(Bid) + " SL:" + sub_dbl2strbrokerdigits(Ask + local_scalpsize) + " TP:" + sub_dbl2strbrokerdigits(local_g - local_scalpsize)); } } } } } } if (globalerror >= 0) Comment("Robot is initializing..."); else { if (globalerror == -2) Comment("ERROR -- Instrument " + Symbol() + " prices should have " + brokerdigits + " fraction digits on broker account"); else { local_textstring = TimeToStr(TimeCurrent()) + " tick:" + sub_adjust00instring(tickcounter); if (Show_Debug || Verbose) { local_textstring = local_textstring + "n" + sub_dbl2strbrokerdigits(Scalpfactor) + " " + sub_dbl2strbrokerdigits(local_scalpsize) + " digits:" + brokerdigits + " " + globalerror + " stopLevel:" + sub_dbl2strbrokerdigits(local_stoplevel); local_textstring = local_textstring + "n" + local_pricedirection + " " + sub_dbl2strbrokerdigits(local_imahigh) + " " + sub_dbl2strbrokerdigits(local_imalow) + " " + sub_dbl2strbrokerdigits(zeropointfour) + " exp:" + TimeToStr(local_orderexpiretime, TIME_MINUTES) + " numOrders:" + local_counter1 + " shouldRepeat:" + local_ordersenderror; local_textstring = local_textstring + "ntrailingLimit:" + sub_dbl2strbrokerdigits(local_adjuststoplevel) + " trailingDist:" + sub_dbl2strbrokerdigits(local_b) + " trailingResolution:" + sub_dbl2strbrokerdigits(local_c) + " useStopOrders:" + local_highspeed; } local_textstring = local_textstring + "nBid:" + sub_dbl2strbrokerdigits(Bid) + " Ask:" + sub_dbl2strbrokerdigits(Ask) + " avgSpread:" + sub_dbl2strbrokerdigits(local_avgspread) + " Commission rate:" + sub_dbl2strbrokerdigits(commission) + " Real avg. spread:" + sub_dbl2strbrokerdigits(local_h) + " Lots:" + sub_dbl2strparb(minmaxlot, local_lotstep); if (sub_normalizebrokerdigits(local_h) > sub_normalizebrokerdigits(forty * pipette)) { local_textstring = local_textstring + "n" + "Robot is OFF :: Real avg. spread is too high for this scalping strategy ( " + sub_dbl2strbrokerdigits(local_h) + " > " + sub_dbl2strbrokerdigits(forty * pipette) + " )"; } Comment(local_textstring); Page 7/8
  • 8. if (local_counter1 != 0 || local_pricedirection != 0 || Verbose) sub_printformattedstring(local_textstring); } } } string sub_dbl2strbrokerdigits(double par_a) { return (DoubleToStr(par_a, brokerdigits)); } string sub_dbl2strparb(double par_a, int par_b) { return (DoubleToStr(par_a, par_b)); } double sub_normalizebrokerdigits(double par_a) { return (NormalizeDouble(par_a, brokerdigits)); } string sub_adjust00instring(int par_a) { if (par_a < 10) return ("00" + par_a); if (par_a < 100) return ("0" + par_a); return ("" + par_a); } double sub_logarithm(double par_a, double par_b) { return (MathLog(par_b) / MathLog(par_a)); } void sub_printformattedstring(string par_a) { int local_difference; int local_a = -1; while (local_a < StringLen(par_a)) { local_difference = local_a + 1; local_a = StringFind(par_a, "n", local_difference); if (local_a == -1) { Print(StringSubstr(par_a, local_difference)); return; } Print(StringSubstr(par_a, local_difference, local_a - local_difference)); } } Page 8/8