Download MetaTrader 5

Stoploss & TakeProfit not working

To add comments, please log in or register
Quentin Dutot
482
Quentin Dutot  

Hello, I developed an EA for the DAX (ger30), it works perfectly in tests I have no error.

But when I go into real OrderSend and OrderModifiy returns the error "invalid tp or sl", while I never had this error in test. So I just ask for your help after spending the long hours digging into my code and doing some research on it .. Do you have any ideas ?

Thank you in advance for your help.

PS: the automatic trading is already authorized on the EA side and on the MT4 side.

whroeder1
16572
whroeder1  
We're not a mind readers.
  1. Show your code
  2. Print out your variables used in the OrderSend, including Ask/Bid and find out why.
  3. You can't move stops closer to the market than the minimum (MODE_STOPLEVEL * _Point.)

Quentin Dutot
482
Quentin Dutot  

In the codes below StopLoss, TakeProfit, Slippage and TrailingStop are constant.

OrderSend :

if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

OrderSend(Symbol(), OP_BUY, OptimizedLots(), Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);


OrderModify :

OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);


When there is no SL and no TP (so 0 and 0 values) the EA can open positions without problems in test and real, so SL/TP are the problem here.

Fernando Carreiro
3598
Fernando Carreiro  
Quentin Dutot:

In the codes below StopLoss, TakeProfit, Slippage and TrailingStop are constant.

OrderSend :

OrderModify :

When there is no SL and no TP (so 0 and 0 values) the EA can open positions without problems in test and real, so SL/TP are the problem here.

You are ignoring the information and links that @whroeder1 has outlined in his post. Visit every link he has provided and follow-up on what they tell you.

For example, you are not checking for minimum allowable stops size, and you are also ignoring the fact that Buy orders close on the Bid price and not the Ask price. These are just two examples, but all the details are in the links that he provided!

Don't just expect us to give you a clean code solution, as that will not help you in the future. You have to understand the "why" and "how", so follow the links and study the information.

Then post your improved code attempt to verify!

To add comments, please log in or register