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

If you change the timeframe or the name of the chart symbol in MetaTrader, all indicators on the chart will be unloaded from the chart and will be loaded onto it again. Unlike MT4, in MT5 the sequence of load/unload is not defined due to its internal architecture.

This feature sometimes causes problems which are not immediately obvious. These problems are related to the fact that OnInit of the new loaded indicator instance can be executed before the OnDeinit of the instance being unloaded.

Situations in which this problem is detected, are most often connected with the desire to transmit (explicitly/implicitly) some information from OnDeinit of the older indicator instance to OnInit of the new one. In other words, the new indicator instance should know about the existence of the old one, and should not load until the old instance is unloaded.

This library allows to apply this synchronization to any indicator.

Here is an example of a simple indicator

#property indicator_chart_window

#property indicator_buffers 1
#property indicator_plots   1
#property indicator_color1  clrRed
#property indicator_type1   DRAW_LINE

input int Input = 0;

double Buffer[];

int OnInit()
{
  SetIndexBuffer(0, Buffer);
  Print("Init");
  return(INIT_SUCCEEDED);
}

void OnDeinit( const int Reason )
{
  Print("DeInit");
}

void OnChartEvent( const int id,
                   const long& lparam,
                   const double& dparam,
                   const string& sparam )
{
}

void OnTimer()
{
}

int OnCalculate( const int rates_total,
                 const int prev_calculated,
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[] )
{
  ArrayCopy(Buffer, open, prev_calculated, prev_calculated);  
  return(rates_total);
}

If you launch this indicator and start switching its chart timeframes or symbol, the alternation of the lines "Init" and "Deinit" will be broken.

If we add the following line at the beginning of indicator code

#include <Init_Sync.mqh> // Synchronizes Init/Deinit of indicators

the proper alternation will be observed.

To apply this property to a desired indicator, add the above structure to its code.

Note

// The library makes indicators' Init/Deinit synchronized.
// The indicator must contain int OnInit(), OnDeinit, OnTimer and OnChartEvent.
// If not used? leave empty.

#include <TypeToBytes.mqh> // https://www.mql5.com/en/code/16280
#include <crc64.mqh>       // https://www.mql5.com/en/blogs/post/683577

Additional mqh-files required for the library operation are available at the specified links.

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

Color_Spread Color_Spread

The indicator shows the current spread using a color line.

Exp_XFatlXSatlCloud Exp_XFatlXSatlCloud

The Exp_XFatlXSatlCloud trading system is based on change of the trend direction displayed by the XFatlXSatlCloud indicator

XMA_BB_Pivot XMA_BB_Pivot

Two colored filled rectangles drawn between the values ​​of two Bollinger channels on one bar.

XMA_Keltner_Pivot XMA_Keltner_Pivot

Two colored filled rectangles drawn between the values ​​of two Keltner channels on one bar.