Carnality
Carnality

Reputation: 1

How to convert send order from mql4 to mql5

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;

   }
}

Upvotes: 0

Views: 764

Answers (1)

Morimil
Morimil

Reputation: 1

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

Upvotes: 0

Related Questions