//+------------------------------------------------------------------+
//| DonchainChannels.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 3
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Green
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
double upper[];
double middle[];
double lower[];
input int tch_peroid = 20;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit() {
IndicatorShortName("DCH(" + IntegerToString(tch_peroid) + ")");
//---
SetIndexBuffer(0, upper);
SetIndexBuffer(1, middle);
SetIndexBuffer(2, lower);
//---
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE);
SetIndexStyle(2, DRAW_LINE);
//---
SetIndexLabel(0, "Upper");
SetIndexLabel(1, "Middle");
SetIndexLabel(2, "Lower");
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 limit;
// 第一次回调计算所有 K 线
if (prev_calculated == 0)
limit = rates_total - 1;
else
limit = rates_total - prev_calculated; // 后续回调,limit = 0 计算最后一根不断更新的 K 线,当新 K 线形成时, limit = 1,需要计算上一根的最终收盘后的价格和最新形成的一根
// 最后最新一根索引是 0,从前往后算
for (int i = limit; i >= 0; i--) {
upper[i] = iHigh(Symbol(), Period(), iHighest(Symbol(), Period(), MODE_HIGH, tch_peroid, i));
lower[i] = iLow(Symbol(), Period(), iLowest(Symbol(), Period(), MODE_LOW, tch_peroid, i));
middle[i] = (upper[i] + lower[i]) / 2;
}
return(rates_total);
}
//+------------------------------------------------------------------+
暂无评论