Join our fan page
- Views:
- 8107
- Rating:
- Published:
- 2012.10.10 13:00
- Updated:
- 2016.11.22 07:32
-
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance
The Expert Advisor moves Stop Loss of the open position along the border of the channel built using ATR_Trailing. Stop Loss is modified only when the bar is changed based on the newly closed bar's data in case Stop Loss will be eventually pinned to the current price.
The Expert Advisor provides a possibility to display the indicator used in it on the current chart directly from the Expert Advisor. There is no need to install the indicator on the chart manually. This is quite convenient, as the indicator is displayed on the chart automatically after the Expert Advisor is installed on the chart. This indicator always has input parameters identical to the Expert Advisor's ones.
Below is the code allowing users to implement such a feature:
//+------------------------------------------------------------------+ //| Inclusion of CChart class in expert | //+------------------------------------------------------------------+ #include <Charts\Chart.mqh> //---- declaration of a global variable as CChart type CChart cchart; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //---- getting handle of the ATR_Trailing indicator InpInd_Handle=iCustom(Symbol(),PERIOD_CURRENT,"ATR_Trailing",Period_ATR,Sell_Factor,Buy_Factor); if(InpInd_Handle==INVALID_HANDLE) Print(" Failed to get handle of ATR_Trailing indicator"); //--- resetting error code to zero ResetLastError(); //--- cchart object works with the current chart (ID=0) , the expert is attached to cchart.Attach(0); //---- adding of ATR_Trailing indicator on the chart if(!cchart.IndicatorAdd(0,InpInd_Handle)) Print(" Failed to add ATR_Trailing indicator on the chart");
Expert Advisor input parameters:
//+----------------------------------------------+ //| Expert Advisor input parameters | //+----------------------------------------------+ input int Period_ATR=14; //АТR period input double Sell_Factor=2.0; input double Buy_Factor=2.0; input uint Deviation=10; //slippage
Image:
Exp_ATR_Trailing working chart
Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/1016

The indicator of two unspecified time intervals.

Function Library for Working with Time Series: iTime, iOpen, iHigh, iLow, iClose, iHighest, iLowest, iBarshift. Short invocation version is available for all functions (with the current chart's symbol and period).

The simple indicator for displaying some relevant information about a position right in the chart window.

Standard Stochastic oscillator displayed as a cloud that can be located by setting the indicator timeframe value different from the chart one.