error 4756 - page 4

 
RaptorUK:

I think,  I will confirm,  that I have seen the same issue in the Strategy Tester,  not sure how exactly this could happen,  I'll try it again with some more error reporting added to make sure.

 OK,  one mystery solved . . .  I didn't realise the Spread used in the Strategy Tester is taken from the History data,  in particular the M1 data.   The reason I have invalid stops in my Strategy Tester run is because the spread is bigger than my SL.  I'll add a test for this.

 

Konstantin83:
2013.03.10 11:19:18    2012.01.04 15:00:00   failed buy stop 1.00 EURUSD at 1.30505 sl: 1.28375 tp: 1.30375 [Invalid stops]

I dont understand invalid stop. the sl is below the buy  sl: 1.28375 <1.30505 ?

 
Konstantin83:

CopyHigh(_Symbol,_Period,TimeCurrent(),5,hg);

Top = NormalizeDouble(rates[ArrayMaximum(hg,0,WHOLE_ARRAY)].high,_Digits); 

- misunderstood design.
Choose among the values ​​of the maximum double and use that instead of the integer index

thank  Konstantin83:

 but i dont understand what you say.

top is the highest of last 5 candles and top is double  and not integer index

 

top
 

dan5:

 I dont understand invalid stop. the sl is below the buy  sl: 1.28375 <1.30505 ?


Don't take "Invalid stops" too literally.  It isn't just about Stop Loss, it also can be the entry price and/or the TP.  When you get an error print the following information,  it will help you work out what has gone wrong:

 

  1. the trade type, Buy Limit, Buy, Sell, Sell Stop, etc.
  2. the Ask price
  3. the Bid price
  4. the entry price
  5. the SL
  6. the TP
  7. the Freeze Level
  8. the Stops Level
  9. the error number (and error description if you really want) 
You should also read this article,  it was written for mql4 but I'm pretty sure it still applies to mql5:  Requirements and Limitations in Making Trades
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
  • book.mql4.com
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
 

dan5:

 2013.03.10 11:19:18    2012.01.04 15:00:00   failed buy stop 1.00 EURUSD at 1.30505 sl: 1.28375 tp: 1.30375 [Invalid stops]


I dont understand invalid stop. the sl is below the buy  sl: 1.28375 <1.30505 ?


Did you notice that the entry  1.30505  is >  the TP  1.30375  ?
 
RaptorUK:
Did you notice that the entry  1.30505  is >  the TP  1.30375  ?

thank you for your help i modifie my sl and tp  it's ok now

 mrequest.sl = NormalizeDouble( mrequest.price + STP*_Point,_Digits); // Stop Loss
 mrequest.tp = NormalizeDouble( mrequest.price - TKP*_Point,_Digits);// Take Profit

instead of:

mrequest.sl = NormalizeDouble(latest_price.bid + STP*_Point,_Digits); // Stop Loss
mrequest.tp = NormalizeDouble(latest_price.bid - TKP*_Point,_Digits); // Take Profit

 
dan5:

thank you for your help i modifie my sl and tp  it's ok now

 mrequest.sl = NormalizeDouble( mrequest.price + STP*_Point,_Digits); // Stop Loss
 mrequest.tp = NormalizeDouble( mrequest.price - TKP*_Point,_Digits);// Take Profit

instead of:

mrequest.sl = NormalizeDouble(latest_price.bid + STP*_Point,_Digits); // Stop Loss
mrequest.tp = NormalizeDouble(latest_price.bid - TKP*_Point,_Digits); // Take Profit

That's good news,  hope you didn't mind me subverting your thread,  but I think we both got something useful out of it in the end :-)
 
RaptorUK:
That's good news,  hope you didn't mind me subverting your thread,  but I think we both got something useful out of it in the end :-)
Did you find an other solution what I propose with OnTradeTransaction to proceed with sl & tp on a Market Execution (ECN broker) case ?
 
angevoyageur:
Did you find an other solution what I propose with OnTradeTransaction to proceed with sl & tp on a Market Execution (ECN broker) case ?
The code I suggested in this post https://www.mql5.com/en/forum/11051#comment_446272   works OK as far as I can tell,  I assumed it wasn't working in the Strategy Tester due to my assumption about the spread being fixed (as in MT4)  being incorrect.  My code now works in the Strategy Tester and in Demo for symbols with execution type of Instant or Exchange execution, my code determines the type and sends the appropriate request(s).   Ideally I would like my code to automatically handle any execution type.
 
RaptorUK:
The code I suggested in this post https://www.mql5.com/en/forum/11051#comment_446272   works OK as far as I can tell,  I assumed it wasn't working in the Strategy Tester due to my assumption about the spread being fixed (as in MT4)  being incorrect.  My code now works in the Strategy Tester and in Demo for symbols with execution type of Instant or Exchange execution, my code determines the type and sends the appropriate request(s).   Ideally I would like my code to automatically handle any execution type.
Ah ok, I missed it.
Reason: