//+------------------------------------------------------------------+
//| MTF_MA.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_chart_window
#property indicator_buffers 1
#property indicator_color1 White
//--- indicator parameters
input ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // 時間足
input int InpMAPeriod = 200; // Period
input int InpMAShift = 0; // Shift
input ENUM_MA_METHOD InpMAMethod = MODE_EMA; // Method
//--- buffers
double ExtEMABuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- middle line
SetIndexStyle(0,DRAW_LINE,2,1);
SetIndexBuffer(0,ExtEMABuffer);
SetIndexShift(0,InpMAShift);
ArraySetAsSeries(ExtEMABuffer, 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;
for (int i=0; i<limit; i++)
{
int bar = iBarShift(NULL, TimeFrame, Time[i]);
ExtEMABuffer[i] = iMA(NULL,TimeFrame,InpMAPeriod,InpMAShift,InpMAMethod,PRICE_CLOSE,bar);
}
return(rates_total);
}
【MQL】MTF_MA(マルチタイムフレーム移動平均線)
当ページのリンクには広告が含まれています。

コメント