거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Twitter에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
조회수:
8110
평가:
(20)
게시됨:
2012.10.10 13:00
업데이트됨:
2016.11.22 07:32
\MQL5\Indicators\
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

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

Exp_ATR_Trailing working chart 

MetaQuotes Ltd에서 러시아어로 번역함.
원본 코드: https://www.mql5.com/ru/code/1016

i-AnyRange2 i-AnyRange2

The indicator of two unspecified time intervals.

TimeSeries - Function Library for Working with Time Series TimeSeries - Function Library for Working with Time Series

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).

PositionInfo PositionInfo

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

ColorStochastic_HTF ColorStochastic_HTF

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