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.
In the codes below StopLoss, TakeProfit, Slippage and TrailingStop are constant.
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(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.
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!