Download MetaTrader 5
To add comments, please log in or register
Find out how to add a video in the messages editor
Poctim
8
Poctim 2014.06.14 13:24 

Having some issues with creating an ECN compatible OrderSend

The error is that the "OrderSend" fails giving me a different ticket # than it should even the orders are being opened - the order Modify also never triggers to set the stops

(minStop, StopLoss and TakeProfit arguments are in Pips) 

 Code:

bool CreateOrder( int argOrderType, double lotSize, double argMinStop, string argComment, 

                  double argStopLoss=0, double argTakeProfit=0, int argMagicNumber=0, int argSlip=0) export

  {

   int Ticket;

   double usePrice;

   

   if(argStopLoss < argMinStop && argStopLoss != 0) argStopLoss = argMinStop;

   if(argTakeProfit < argMinStop && argTakeProfit != 0) argTakeProfit = argMinStop;

   

   while(IsTradeContextBusy()) Sleep(10);      

   RefreshRates();

   

   if (argOrderType == OP_BUY)

      usePrice = Ask;

   else

      usePrice = Bid;

   

   if(Ticket != OrderSend(Symbol(), argOrderType, lotSize, usePrice, argSlip, 0, 0, argComment, argMagicNumber))

     {         

      Print("Order Send Failed on Order: " + (string)OrderTicket() + " - " + CheckError(GetLastError()));

      return(false);

     }

   else   

     {

      if(argStopLoss != 0) argStopLoss = SetSL(argOrderType, argStopLoss);

      if(argTakeProfit != 0) argTakeProfit = SetTP(argOrderType, argTakeProfit);


      if(OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) 

         if(!OrderModify(OrderTicket(), OrderOpenPrice(), argStopLoss, argTakeProfit, 0))

            Print("Order Modify Failed on Order: " + (string)OrderTicket() + " - " + CheckError(GetLastError()));

      

      return(true);

     }

   

   Print("Order Create Failed on Order: " + (string)OrderTicket() + " - " + CheckError(GetLastError()));

   return(false);   

  }

 

Logs:

2014.06.14 09:19:41.328 GBPCHF,Daily: 262 tick events (1263 bars, 1523 bar states) processed within 0 ms (total time 0 ms)

2014.06.14 09:19:41.328 2014.05.26 23:59  Tester: order #7 is closed

2014.06.14 09:19:41.328 2014.05.26 23:59  Tester: order #8 is closed

2014.06.14 09:19:41.328 2014.05.12 00:00  Trending EA v2 GBPCHF,Daily: Order Send Failed on Order: 7 - No Error Found - Index:0

2014.06.14 09:19:41.328 2014.05.12 00:00  Trending EA v2 GBPCHF,Daily: open #8 buy 0.01 GBPCHF at 1.49431 ok

2014.06.14 09:19:41.328 2014.04.04 00:00  Trending EA v2 GBPCHF,Daily: Order Send Failed on Order: 5 - No Error Found - Index:0

2014.06.14 09:19:41.328 2014.04.04 00:00  Trending EA v2 GBPCHF,Daily: open #7 buy 0.01 GBPCHF at 1.48004 ok

2014.06.14 09:19:41.328 2014.03.20 00:00  Trending EA v2 GBPCHF,Daily: close #5 buy 0.01 GBPCHF at 1.48034 at price 1.45630

2014.06.14 09:19:41.328 2014.03.20 00:00  Trending EA v2 GBPCHF,Daily: close #6 buy 0.01 GBPCHF at 1.50024 at price 1.45630

2014.06.14 09:19:41.327 2014.01.09 00:00  Trending EA v2 GBPCHF,Daily: Order Send Failed on Order: 5 - No Error Found - Index:0

2014.06.14 09:19:41.327 2014.01.09 00:00  Trending EA v2 GBPCHF,Daily: open #6 buy 0.01 GBPCHF at 1.50024 ok

2014.06.14 09:19:41.327 2014.01.03 00:00  Trending EA v2 GBPCHF,Daily: Order Send Failed on Order: 3 - No Error Found - Index:0

2014.06.14 09:19:41.327 2014.01.03 00:00  Trending EA v2 GBPCHF,Daily: open #5 buy 0.01 GBPCHF at 1.48034 ok

2014.06.14 09:19:41.327 2013.12.19 00:00  Trending EA v2 GBPCHF,Daily: close #3 sell 0.01 GBPCHF at 1.44570 at price 1.46644

2014.06.14 09:19:41.327 2013.12.19 00:00  Trending EA v2 GBPCHF,Daily: close #4 buy 0.01 GBPCHF at 1.47544 at price 1.46490

2014.06.14 09:19:41.327 2013.11.08 00:00  Trending EA v2 GBPCHF,Daily: Order Send Failed on Order: 3 - No Error Found - Index:0

2014.06.14 09:19:41.327 2013.11.08 00:00  Trending EA v2 GBPCHF,Daily: open #4 buy 0.01 GBPCHF at 1.47544 ok

2014.06.14 09:19:41.327 2013.10.29 00:00  Trending EA v2 GBPCHF,Daily: Order Send Failed on Order: 1 - No Error Found - Index:0

2014.06.14 09:19:41.327 2013.10.29 00:00  Trending EA v2 GBPCHF,Daily: open #3 sell 0.01 GBPCHF at 1.44570 ok

2014.06.14 09:19:41.327 2013.09.20 00:00  Trending EA v2 GBPCHF,Daily: close #1 buy 0.01 GBPCHF at 1.47044 at price 1.45940

2014.06.14 09:19:41.327 2013.09.20 00:00  Trending EA v2 GBPCHF,Daily: close #2 sell 0.01 GBPCHF at 1.43760 at price 1.46094

2014.06.14 09:19:41.326 2013.07.12 00:00  Trending EA v2 GBPCHF,Daily: Order Send Failed on Order: 1 - No Error Found - Index:0

2014.06.14 09:19:41.326 2013.07.12 00:00  Trending EA v2 GBPCHF,Daily: open #2 sell 0.01 GBPCHF at 1.43760 ok

2014.06.14 09:19:41.326 2013.05.29 00:00  Trending EA v2 GBPCHF,Daily: Order Send Failed on Order: 7 - No Error Found - Index:0

2014.06.14 09:19:41.326 2013.05.29 00:00  Trending EA v2 GBPCHF,Daily: open #1 buy 0.01 GBPCHF at 1.47044 ok


 

Poctim
8
Poctim 2014.06.14 14:17  

Nevermind - finally figured the thing out :)

 

 

   if(Ticket != OrderSend(Symbol(), argOrderType, lotSize, usePrice, argSlip, 0, 0, argComment, argMagicNumber))

     {   

Should have been:

 

    

   Ticket = OrderSend(Symbol(), argOrderType, lotSize, usePrice, argSlip, 0, 0, argComment, argMagicNumber);

      if(Ticket == -1)

 

duh........ lol 

/
To add comments, please log in or register