Mastering TP SL Trailing: Your Guide to Expert Trading on MetaTrader 5

Mike 2018.10.26 00:49 19 0 0
Attachments

The idea behind this strategy - Sergey Efimenko

Code author - barabashkakvn

When trading, setting up your stop loss (SL) and take profit (TP) is crucial. This EA (Expert Advisor) is designed to adjust these settings for you automatically, but it only kicks in for profitable trades.

If the Only zero values option is set to 'true', the EA will look for positions where either the stop loss or take profit is set to zero. When it finds one, here’s what happens:

  • If it’s a BUY position:
    • The stop loss is set to the current price (Bid) minus the stop loss amount.
    • The take profit is set to the current price (Bid) plus the take profit amount.
  • If it’s a SELL position:
    • The stop loss is set to the current price (Ask) plus the stop loss amount.
    • The take profit is set to the current price (Ask) minus the take profit amount.

On the flip side, if the Only zero values option is 'false', the EA will not adjust any stop loss or take profit parameters.

This EA is designed to work with all positions for the current symbol, so it doesn’t matter if you’re using unique magic numbers.

Want to see how it all comes together? You can uncomment the following lines in your code:

   ExtStopLoss    = InpStopLoss     * m_adjusted_point;
   ExtTakeProfit  = InpTakeProfit   * m_adjusted_point;
   ExtTrailingStop= InpTrailingStop * m_adjusted_point;
   ExtTrailingStep= InpTrailingStep * m_adjusted_point;

//m_trade.Buy(2.0);
//m_trade.Sell(1.0);
//---
   return(INIT_SUCCEEDED);
  }

Then, run the EA in the strategy tester to see it in action!

List
Comments 0