Download MetaTrader 5

ecn stops and 4756 error

To add comments, please log in or register
live55
14
live55 2012.05.09 02:21 
Hi, 

i have problem with sl and tp modify on ecn broker.
In strategy tester places the orders without any problems with sl and tp, 
on demo forward test (alpari) im getting 4756 error no matter how many pips is sl and tp set and the order is set without sl and tp.


Here is the journal and expert tabs and code, any help would be appreciated
  

journal:
journal
experts:
experts
 MqlTradeRequest Request;                             // Will be used for trade requests
   MqlTradeResult Result;                               // Will be used for results of trade requests
   
   ZeroMemory(Request);
   ZeroMemory(Result);
   
   double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);    // Ask price
   double Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);    // Bid price
   double SL=0, TP=0;
   int err=0;

   if(!PositionSelect(_Symbol))
     {
      Request.action = TRADE_ACTION_DEAL;
  Request.magic = magic;
  Request.symbol = _Symbol;
  Request.volume = Lot;
  Request.price = NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_BID), _Digits);
  Request.type = ORDER_TYPE_SELL; 
  Request.sl = 0; // No StopLoss Market Stop
  Request.tp = 0; // No TakeProfit Market Stop
  Request.type_filling = ORDER_FILLING_FOK;
  Request.type_time = ORDER_TIME_GTC;
  Request.deviation = 50;
  Request.comment = "Sell Trade";
      
      
   
  bool result = OrderSend(Request, Result); 
  if (result == false)  { err=GetLastError(); Print("Buy Trade Failed. error ",err); ResetLastError(); return;} // If trade fails, do not proceed to trade Modify.
  else Print("Result Code: ", Result.retcode, ", ", "Deal: ", Result.deal, ", ", "Volume: ", Result.volume, ", ", 
  "Price: ", Result.price, ", ", "Requote Bid: ", Result.bid, ", ", "Requote Ask: ", Result.ask);

        
//----- Modify SL and TP -------------------
   if (TakeProfit > 0) TP = SymbolInfoDouble(Symbol(), SYMBOL_BID) + TakeProfit*Poin ; else TP = 0;
   if (StopLoss > 0) SL = SymbolInfoDouble(Symbol(), SYMBOL_BID) - StopLoss*Poin ; else SL = 0;
                
  Request.action = TRADE_ACTION_SLTP;
  Request.symbol = _Symbol;
  Request.sl = NormalizeDouble(SL, _Digits);
  Request.tp = NormalizeDouble(TP, _Digits);
  Request.deviation= 50;
               
  result = OrderSend(Request, Result); 
  if (result == false)  { err=GetLastError(); Print("Modify Buy Trade Failed, Error ",err); ResetLastError(); }
  else Print("Result Code: ", Result.retcode, ", ", "Deal: ", Result.deal, ", ", "Volume: ", Result.volume, ", ", 
  "Price: ", Result.price, ", ", "Requote Bid: ", Result.bid, ", ", "Requote Ask: ", Result.ask);
      
johhny6
130
johhny6 2012.05.10 07:41  
live55:

You're submitting orders with a SL and TP of 0.0000, because the code logic is incorrect (or for some other reason).


In your case it does not look like a broker issue, or slippage (ala: https://www.mql5.com/en/forum/4480)

EA fails to open trades in Strategy Tester - CTrade::PositionOpen: [invalid fill]
  • www.mql5.com
08 11:04:35 CTrade::PositionOpen: market buy 0.
onewithzachy
2271
onewithzachy 2012.05.10 08:41  

If I were you I'll use CTrade Class to get broker comments. I have example and attachment here however it does not involving order modify :( .

BTW you should execute ...

ClearStructures();   the correct one is : zero memory operation. :)

... before running modify. There's example in Include\Trade\Trade.mqh under ...

 bool CTrade::PositionModify(const string symbol,double sl,double tp)

Have fun.

:) 

live55
14
live55 2012.05.10 12:10  
johhny6: i think this is the way u do it with ecn broker with 0 sl tp and then modify


onewithzachy: i will try to implement this, ty


Just got one tip to put sleep for few seconds before order modify and it works somehow.

However the code need to be reworked, i think this is not way to do it with the time delay altought it is working.


Regards

John


onewithzachy
2271
onewithzachy 2012.05.10 16:40  

live55, you are right !!!. I add 5 milisec sleep and then order modify tp and sl works on both OrderSend and CTrade Class !!!. Who gave you this idea anyway ???.

But this is ridiculous, even MT4 will modify right away without waiting !!!.

See my code here

live55
14
live55 2012.05.11 00:34  

glad it helped you, ive found this issue with delay if i was modifying mt4 ea for ecn, but like you said, mt4 doesnt really need delay between modify..

im just wondering if it is safe enough to go live with this modify lately, just thinking about retry for modify if modify fails - for safe..

i will look on it when i have more time, however im not coder so i will check your codes for inspiration


Regards

John

To add comments, please log in or register