![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Dear coders,
I'm trying to improve my Martingale EA, by adding a new SL method. Namely the x candle low for long trades, and for short trades the x candle high.
If the previous trade was a winner, the EA will calculate the lotsize with this formula:
lotsize = ((Risk_per_Trade/100.0) * money ) / (LongSL*pips);
If the previous trade was a loser:
When I backtest the EA I get error 4051 , invalid lots amount for OrderSend function.
I've already tried many things, but I couldn't find the solution.
This is the whole function for the lotsize calculation and the order placement.
I really hope that someone could explain why my code isn't working.
Thanks in advance,
Thierry