//+------------------------------------------------------------------+
//| MTF_Bands.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 3
#property indicator_color1 Magenta
#property indicator_color2 Magenta
#property indicator_color3 Magenta
//--- indicator parameters
input ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // 時間足
input int InpBandsPeriod=20; // Bands Period
input int InpBandsShift=0; // Bands Shift
input double InpBandsDeviations=2.0; // Bands Deviations
//--- buffers
double ExtMovingBuffer[];
double ExtUpperBuffer[];
double ExtLowerBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- middle line
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMovingBuffer);
SetIndexShift(0,InpBandsShift);
SetIndexLabel(0,"Bands SMA");
ArraySetAsSeries(ExtMovingBuffer, true);
//--- upper band
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtUpperBuffer);
SetIndexShift(1,InpBandsShift);
SetIndexLabel(1,"Bands Upper");
ArraySetAsSeries(ExtUpperBuffer, true);
//--- lower band
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,ExtLowerBuffer);
SetIndexShift(2,InpBandsShift);
SetIndexLabel(2,"Bands Lower");
ArraySetAsSeries(ExtLowerBuffer, 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;
ExtUpperBuffer[i] = iBands(NULL,TimeFrame,InpBandsPeriod,InpBandsDeviations,InpBandsShift,PRICE_CLOSE,MODE_UPPER,bar);
ExtMovingBuffer[i] = iBands(NULL,TimeFrame,InpBandsPeriod,InpBandsDeviations,InpBandsShift,PRICE_CLOSE,MODE_MAIN,bar);
ExtLowerBuffer[i] = iBands(NULL,TimeFrame,InpBandsPeriod,InpBandsDeviations,InpBandsShift,PRICE_CLOSE,MODE_LOWER,bar);
}
return(rates_total);
}
【MQL】MTF_Bands(マルチタイムフレームボリンジャーバンド)
当ページのリンクには広告が含まれています。