help with lot multiplier

 

hi,

i nead to impleament a lot multyplier in this grid script i post the code. Can someone help me?

//+------------------------------------------------------------------+
//|                                                   SetGrid Script |
//|                                                      By UziForex |
//|                                                                  |
//+------------------------------------------------------------------+

#property copyright "By UziForex"
#property link      "https://blitzforex.xyz"
#property strict
#property script_show_inputs

input int    nMagic    = 0;      // Magic Number se vuoi distinguere gli ordini
input double lots      = 0.01;   // Il lotto da usare
input bool   sellLimit = false;  // true = griglia SELL LIMIT SOPRA
input bool   buyLimit  = false;  // true = griglia BUY LIMIT SOTTO
input double startPips = 10.0;   // Inizio della griglia IN PIP DAL PREZZO ATTUALE
input double stepPips  = 5.0;    // Passo della griglia = ogni quanti pip va l'ordine successivo
input int    nSteps    = 5;      // Numero di passi = di ordini da piazzare
input double takePip   = 5.0;    // Take comune in pip dopo l'ultimo ordine
input double stopPip   = 0 ;   // Stop comune in pip prima del primo ordine 
extern double lotmultiplier = 2;  // Moltiplatore dei lotti
input color colorBuy  =  clrLime;
input color colorSell =  clrRed;
input color colorNone =  clrYellow;

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+

void OnStart()
{
   //---
   string           www  = "https://blitzforex.xyz";
   if (ObjectFind  (www) < 0)
   {
      ObjectCreate (www, OBJ_LABEL,    0, 0, 0);
      ObjectSet    (www, OBJPROP_BACK,    true);
      ObjectSet    (www, OBJPROP_CORNER,     1);
      ObjectSet    (www, OBJPROP_ANGLE,     90);
      ObjectSet    (www, OBJPROP_XDISTANCE, 25);
      ObjectSet    (www, OBJPROP_YDISTANCE, 75);
      ObjectSetText(www, www, 10, "Tahoma", colorBuy);
   }
   Comment(WindowExpertName() + " Trading System");

   if (!buyLimit && !sellLimit)
   {
      MessageBox("ATTENZIONE!!!\r\n\r\nDevi settare buyLimit, setLiimit ... o entrambi!", "https://blitzforex.xyz", 0x00000010 | 0x00000000);
      return;
   }

   double pip = MarketInfo(Symbol(), MODE_POINT)*MathPow(10, MathMod(MarketInfo(Symbol(), MODE_DIGITS), 2));

   double startSell = NormalizeDouble(Ask + startPips*pip, Digits), lastSell = 0.0;
   double startBuy  = NormalizeDouble(Bid - startPips*pip, Digits), lastBuy  = 0.0;
  
   for (int n = 0; n < nSteps; n++)
   {
      if (sellLimit)
      {
         double openPrice = NormalizeDouble(startSell + n*stepPips*pip, Digits);
         if (OrderSend(Symbol(), OP_SELLLIMIT, lots , openPrice, 0, 0, 0, "GRID SELL", nMagic, 0, colorSell) > 0) Alert(Symbol() + " SELL Order OK!!!!");
         else                                                                                                    Alert(Symbol() + " SELL ERROR " + IntegerToString(GetLastError()));

         lastSell = openPrice;
      }

      if (buyLimit)
      {
         double openPrice = NormalizeDouble(startBuy - n*stepPips*pip, Digits);
         if (OrderSend(Symbol(), OP_BUYLIMIT,lots, openPrice, 0, 0, 0, "GRID BUY", nMagic, 0, colorBuy) > 0) Alert(Symbol() + " BUY Order OK!!!!");
         else                                                                                                 Alert(Symbol() + " BUY ERROR " + IntegerToString(GetLastError()));
         
         lastBuy = openPrice;
      }
   }

   double stopBuy = NormalizeDouble(lastBuy  - stopPip*pip, Digits);
   double takeBuy = NormalizeDouble(startBuy + takePip*pip, Digits);

   double stopSell = NormalizeDouble(lastSell  + stopPip*pip, Digits);
   double takeSell = NormalizeDouble(startSell - takePip*pip, Digits);
      
   for (int i = 0; i < OrdersTotal(); i++)
   {
      if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      { 
         Alert(GetLastError());
      }
      else if (OrderSymbol() != Symbol())
      {
         //
      }   
      else if (nMagic != OrderMagicNumber())
      {
         //
      }   
      else if (OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT)
      {
         if (!OrderModify(OrderTicket(), OrderOpenPrice(), stopBuy, takeBuy, 0)) Alert(GetLastError());
      }
      else if (OrderType() == OP_SELL || OrderType() == OP_SELLLIMIT)
      {
         if (!OrderModify(OrderTicket(), OrderOpenPrice(), stopSell, takeSell, 0)) Alert(GetLastError());
      }   
   }
}

//+------------------------------------------------------------------+
 

Hi,

You could use this formula in OrderSend() function to spend the lot size for each new pending order:

lots*MathPow(lotmultiplier,n)
 
ok thanks really helpfull and if i wanna wait  x time before open every pending ?
 
Thomas Bolognesi:
ok thanks really helpfull and if i wanna wait  x time before open every pending ?

So you could use this below before the "for" loop:

   static datetime lastTime=TimeCurrent();
   if(TimeCurrent()<lastTime+X_Minutes*60)return;//X_Minutes is a global extern variable that can be any integer positive value
   lastTime=TimeCurrent();