Exp_ATR_Trailing - MetaTrader 5 Expert | Forex Indicator Download - MT4/MT5 Resources

The Expert Advisor moves the stop loss of open positions along the channel borders constructed using ATR_Trailing. The stop loss is modified only when the bar changes based on the data of the newly closed bar, to prevent the loss from ending up fixed at the current price.
The Expert Advisor offers the possibility to display the indicators used in it on the current chart directly from the Expert Advisor. No need to manually install indicators on charts. This is very convenient because after installing the Expert Advisor on the chart, the indicator is automatically displayed on the chart. The input parameters of this indicator are always the same as those of the Expert Advisor.
Here is the code that allows the user to implement such functionality:
//+------------------------------------------------------------------+ //|Include CChart class in Expert | //+------------------------------------------------------------------+ #include <Chart\Chart.mqh> //----Declare global variables as CChart type CChart chart; //+------------------------------------------------------------------+ //|Expert initialization function | //+------------------------------------------------------------------+ Integer initialization () { //---- Get the handle of the ATR_Trailing indicator InpInd_Handle= Customized ( symbol (), PERIOD_CURRENT , "ATR_Trailing" , Period_ATR, Sell_Factor, Buy_Factor); if (InpInd_Handle== INVALID_HANDLE ) print ( "Unable to get handle of ATR_Trailing indicator" ); //--- Reset error code to zero reset last error (); //--- cchart object is used with the current chart (ID=0) and the EA is attached to cchart. append( 0 ); //---- Add ATR_Trailing indicator on the chart if (!cchart.IndicatorAdd( 0 ,InpInd_Handle)) print ( "Failed to add ATR_Trailing indicator on the chart" );
//+------------------------------------------------------------------------+ //| EA transaction input parameters | //+------------------------------------------------------------------------+ Input integer period_ATR= 14 ; //ATR period Enter Double Sales Factor = 2.0 ; Enter Double Buy Factor = 2.0 ; Enter Unit Deviation = 10 ; // Slippage
image:

Exp_ATR_Trailing work chart
Attachment download
📎 atr_trailing.mq5 (6.08 KB)
📎 exp_atr_trailing.mq5 (18.04 KB)
Source: MQL5 #1016
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •