
パラメータの時間足に設定した時間足の移動平均線を下位の時間軸にマルチタイムフレームで展開するインジケーターです。
パラメータの時間足と同じ時間足で表示させた場合、普通の移動平均線で表示されます。
//+------------------------------------------------------------------+
//| MultiTimeFrameMA.mq4 |
//| Copyright 2025, Greeds Ltd. |
//| https://fxtrading.greeds.co.jp/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Greeds Ltd."
#property link "https://fxtrading.greeds.co.jp/"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
input ENUM_TIMEFRAMES inTimeFrame = PERIOD_H1; // 時間足
input int inPeriod = 14; // 期間
input int inShift = 0; // シフト
input ENUM_MA_METHOD inMethod = MODE_SMA; // MA種別
input ENUM_APPLIED_PRICE inPrice = PRICE_CLOSE; // 適用価格
input color inClr = clrRed; // 色
input ENUM_LINE_STYLE inStyle = STYLE_SOLID; // 線種
input int inWidth = 1; // 太さ
double MABuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0, MABuffer);
SetIndexStyle (0, DRAW_LINE, inStyle, inWidth, inClr);
SetIndexLabel(0, "MA");
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 <= inTimeFrame | inTimeFrame == PERIOD_CURRENT)
{
int limit = Bars - IndicatorCounted() - 1;
int min = PeriodSeconds(inTimeFrame) / PeriodSeconds();
if (limit < min) limit = min;
for (int i = limit; i >= 0; i--) {
int index = iBarShift(NULL, inTimeFrame, Time[i]);
MABuffer[i] = iMA(NULL, inTimeFrame, inPeriod, inShift, inMethod, inPrice, index );
}
}
return(rates_total);
}