MT5 EA Template

ssopiak

Trader
Mar 2, 2024
3
0
7
51
Thanks for the template, it's really useful.
I'd like to customise it to add trailing stoploss for example.
What do you think would be the best way to do this?
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,839
1,422
144
Odesa
www.earnforex.com
Thanks for the template, it's really useful.
I'd like to customise it to add trailing stoploss for example.
What do you think would be the best way to do this?
To add a trailing stop? You can look at any trailing stop EA we have and use the code from there. For example, Trailing Stop on Profit.
 

ssopiak

Trader
Mar 2, 2024
3
0
7
51
To add a trailing stop? You can look at any trailing stop EA we have and use the code from there. For example, Trailing Stop on Profit.
OK thanks, but my question isn't how to implement a trailling stop but where to implement it.
My idea is to code several buy/sell signals and several types of stop loss and then test several combinations.
For example, is it relevant to add 2 parameters to the "CheckEntrySignal()" function to add an argument with a type of signal (1=moving average crossing, 2=bollinger band, 3=hammer canddle...etc) and a type of stoploss (1=fixed, 2=based on ATRs, 3=trailing stop, ....) ?
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,839
1,422
144
Odesa
www.earnforex.com
OK thanks, but my question isn't how to implement a trailling stop but where to implement it.
My idea is to code several buy/sell signals and several types of stop loss and then test several combinations.
For example, is it relevant to add 2 parameters to the "CheckEntrySignal()" function to add an argument with a type of signal (1=moving average crossing, 2=bollinger band, 3=hammer canddle...etc) and a type of stoploss (1=fixed, 2=based on ATRs, 3=trailing stop, ....) ?
I wouldn't mix entry signals and trailing stop. Trailing stop is best added as a separate function like this:
MQL5:
if (CountPositions())
    {
        // There is a position open. Manage SL, TP, or close if necessary.
        if (UsePartialClose) PartialCloseAll();
        CheckExitSignal();
        TrailingStop();
    }
Then you implement the actual trailing stop strategy (or strategies) inside the TrailingStop() function.
 
  • 👍
Reactions: ssopiak

ssopiak

Trader
Mar 2, 2024
3
0
7
51
I wouldn't mix entry signals and trailing stop. Trailing stop is best added as a separate function like this:
MQL5:
if (CountPositions())
    {
        // There is a position open. Manage SL, TP, or close if necessary.
        if (UsePartialClose) PartialCloseAll();
        CheckExitSignal();
        TrailingStop();
    }
Then you implement the actual trailing stop strategy (or strategies) inside the TrailingStop() function.
Ok thanks !