//+------------------------------------------------------------------+
//| MTF均线模板.mq4 |
//| Copyright 2023, 100w123 |
//| https://100w123.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, 100w123"
#property link "https://100w123.com"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrAqua
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
double ma[];
input ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT;
input int MaPeriod = 21;
input int MaShift = 0;
input ENUM_MA_METHOD MaMethod = MODE_SMA;
input ENUM_APPLIED_PRICE MaAppliedPrice = PRICE_CLOSE;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit() {
SetIndexBuffer(0, ma);
SetIndexLabel(0, StringFormat("MA(%d) [%s]", MaPeriod, EnumToString(TimeFrame)));
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[]) {
int shift_need_recalculate = iBarShift(NULL, Period(), iTime(NULL, TimeFrame, 0));
if (rates_total <= shift_need_recalculate) {
return 0;
}
int num_uncalculated = rates_total - prev_calculated;
for (int i = MathMax(shift_need_recalculate, num_uncalculated - 1); i >= 0; i--)
{
int shift = iBarShift(NULL, TimeFrame, time[i]);
ma[i] = iMA(NULL, TimeFrame, MaPeriod, MaShift, MaMethod, MaAppliedPrice, shift);
}
return(rates_total);
}
//+------------------------------------------------------------------+
暂无评论
