0

Below is the method I'm using to place an order after three minutes if it doesn't go through. I've converted the larger part of it from mql4 to mql5. It's just the commented part that I'm not sure how I'll change to mql5 since in mql5 send orders return bool's and not int's. I would be glad if I could get help with fixing this remaining part.


void MakeOrders()
{
   static datetime lastTime = 0;
   datetime currTime = iTime(Symbol(),PERIOD_M3,0);

   if (currTime>lastTime)

   {
      for (int i=ObjectsTotal(0, 0, -1)-1; i>=0; i--)

      {
         string name = ObjectName(0, i, 0, -1);

         if (ObjectGetString(0, name, OBJPROP_NAME, 0)==OBJ_RECTANGLE && ObjectGetString(0,name,OBJPROP_TEXT)=="")
         {
            double entryPrice=ObjectGetDouble(0,name,OBJPROP_PRICE,1)-3*_Point; 
            double stopLoss=ObjectGetDouble(0,name,OBJPROP_PRICE,2); 
            double slDist=fabs(entryPrice-stopLoss); 
            double dTakeProfit=entryPrice-2*slDist;

            MqlTradeRequest request={0};
            MqlTradeResult  result={0};
            //--- parameters of request
            request.action   =TRADE_ACTION_DEAL;                     // type of trade operation
            request.symbol   =Symbol();                              // symbol
            request.volume   =lotSize;                                   // volume of 0.1 lot
            request.type     =ORDER_TYPE_BUY_LIMIT;                        // order type
            request.price    = entryPrice; // price for opening
            //request.deviation=5;                                     // allowed deviation from the price
            request.magic    =magicnumber;                          // MagicNumber of the order
            request.tp       = dTakeProfit;
            request.sl       = stopLoss;
            //--- send the request
            if(!OrderSend(request,result))
             PrintFormat("OrderSend error %d",GetLastError());

            /*
            int ticketSell = OrderSend(Symbol(),OP_SELLLIMIT,lotSize, entryPrice,0,stopLoss,dTakeProfit,"SellOrder",magicnumber,0,Red);           

            if (ticketSell>0)

            {

               ObjectSetText(name,string(ticketSell));

               i = ObjectsTotal()-1; // rather than continuing the 'for' loop, we must restart because arrows (ie new objects) were created.

            }
               */
         }
      }

      lastTime = currTime;

   }
}

Carnality
  • 1
  • 1
  • send `OrderSend()` that takes request and result, and check the result. – Daniel Kniaz Sep 06 '19 at 11:36
  • @DanielKniaz I added `OrderSend(request,result);` and nothing happened. So I added a print statement to `if (ObjectGetString(0, name, OBJPROP_NAME, 0)==OBJ_RECTANGLE && ObjectGetString(0,name,OBJPROP_TEXT)==""){}` which didn't print. The original mql4 code for this condition was `if (ObjectType(name)==OBJ_RECTANGLE && ObjectDescription(name)=="") {}`. Maybe I didn't convert that bit well. Not sure. – Carnality Sep 06 '19 at 17:42
  • @DanielKniaz I haven't been able to fix this issue – Carnality Sep 09 '19 at 08:01

1 Answers1

0
if(result.retcode==10009 || result.order>0)
     ObjectSetText(name,string(result.order));