//+------------------------------------------------------------------+
//| MTF_ADX.mq4 |
//| Copyright 2025, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_level1 14
#property indicator_buffers 3
#property indicator_color1 LightSeaGreen
#property indicator_color2 YellowGreen
#property indicator_color3 Wheat
//--- indicator parameters
input ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // 時間足
input int InPeriod=20; // Adx Period
//--- buffers
double ExtMainBuffer[];
double ExtPlusBuffer[];
double ExtMinusBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- middle line
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(0,ExtMainBuffer);
ArraySetAsSeries(ExtMainBuffer, true);
//--- upper band
SetIndexStyle(1,DRAW_LINE,STYLE_DOT,1);
SetIndexBuffer(1,ExtPlusBuffer);
ArraySetAsSeries(ExtPlusBuffer, true);
//--- lower band
SetIndexStyle(2,DRAW_LINE,STYLE_DOT,1);
SetIndexBuffer(2,ExtMinusBuffer);
ArraySetAsSeries(ExtMinusBuffer, true);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
if (_Period > TimeFrame && TimeFrame != PERIOD_CURRENT) return -1;
int limit = rates_total-prev_calculated-1;
for (int i=limit; i>=0; i--)
{
int bar = iBarShift(NULL, TimeFrame, Time[i]);
if (bar == -1) continue;
ExtMainBuffer[i] = iADX(NULL,TimeFrame,InPeriod,PRICE_HIGH,MODE_MAIN,bar) ;
ExtPlusBuffer[i] = iADX(NULL,TimeFrame,InPeriod,PRICE_HIGH,MODE_PLUSDI,bar) ;
ExtMinusBuffer[i] = iADX(NULL,TimeFrame,InPeriod,PRICE_HIGH,MODE_MINUSDI,bar) ;
}
return(rates_total);
}
【MQL】MTF_ADX(マルチタイムフレームADX)
当ページのリンクには広告が含まれています。