mt5 open close数组起点设置

int OnCalculate(const int rates_total,    // number of bars in history at the current tick
                const int prev_calculated,// amount of history in bars at the previous tick
                const datetime &time[],
                const double &open[],
                const double& high[],     // price array of maximums of price for the calculation of indicator
                const double& low[],      // price array of price lows for the indicator calculation
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   ArraySetAsSeries(open,true);

}

初始是open[0]最左边

ArraySetAsSeries(open,true);后open[0]为最右边

//+------------------------------------------------------------------+ //| WH_DKL_FinalFix.mq5 | //| Copyright 2023, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2023, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 4 #property indicator_plots 1 #property indicator_type1 DRAW_COLOR_LINE #property indicator_color1 clrBlue, clrMagenta // 0=蓝色, 1=洋红色 #property indicator_style1 STYLE_SOLID #property indicator_width1 3 input int SmoothingPeriod = 1; // 平滑周期设置为1 (SMA(L,1,1)就是L本身) double VAR1Buffer[]; // SMA(L,1,1)计算值 (直接等于L) double DKLBuffer[]; // 多空线值 double ColorBuffer[]; // 颜色缓冲区 double LastTurnBuffer[]; // 记录转折点值 //+------------------------------------------------------------------+ //| 自定义指标初始化函数 | //+------------------------------------------------------------------+ int OnInit() { SetIndexBuffer(0, DKLBuffer, INDICATOR_DATA); SetIndexBuffer(1, ColorBuffer, INDICATOR_COLOR_INDEX); SetIndexBuffer(2, VAR1Buffer, INDICATOR_CALCULATIONS); SetIndexBuffer(3, LastTurnBuffer, INDICATOR_CALCULATIONS); IndicatorSetString(INDICATOR_SHORTNAME, "多空线修复版(" + string(SmoothingPeriod) + ")"); PlotIndexSetString(0, PLOT_LABEL, "多空线"); // 修改颜色设置:0=蓝色, 1=洋红色 PlotIndexSetInteger(0, PLOT_LINE_COLOR, 0, clrBlue); PlotIndexSetInteger(0, PLOT_LINE_COLOR, 1, clrMagenta); PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, SmoothingPeriod + 1); // 设置数组为时间序列 ArraySetAsSeries(DKLBuffer, true); ArraySetAsSeries(ColorBuffer, true); ArraySetAsSeries(VAR1Buffer, true); ArraySetAsSeries(LastTurnBuffer, true); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 自定义指标迭代函数 (修复版) | //+------------------------------------------------------------------+ 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[]) { // 设置数组为时间序列 ArraySetAsSeries(low, true); // 改为使用低点序列 if(rates_total < 2) return(0); // 至少需要2根K线 int start; if(prev_calculated == 0) { // 初始化所有缓冲区 for(int i = 0; i < rates_total; i++) { // VAR1直接等于low (SMA(L,1,1)) VAR1Buffer[i] = low[i]; // 从high改为low // 初始化多空线 DKLBuffer[i] = low[i]; // 从high改为low // 初始化转折点值 LastTurnBuffer[i] = low[i]; // 从high改为low // 初始颜色为洋红色 ColorBuffer[i] = 1; } start = 1; // 从第2根K线开始计算 } else { start = prev_calculated - 1; if(start < 1) start = 1; } // 核心逻辑实现 for(int i = start; i < rates_total; i++) { // VAR1直接等于low (SMA(L,1,1)) VAR1Buffer[i] = low[i]; // 从high改为low // 1. 检测下降转折点 (VAR1 < REF(VAR1,1)) if(VAR1Buffer[i] < VAR1Buffer[i-1]) { // 记录转折点值 LastTurnBuffer[i] = VAR1Buffer[i]; } else { // 继承前值转折点 LastTurnBuffer[i] = LastTurnBuffer[i-1]; } // 2. 多空线 = REF(VAR1, BARSLAST(转折点)) DKLBuffer[i] = LastTurnBuffer[i]; // 3. 颜色判断 (多空线 <= REF(多空线,1) ? 蓝色 : 洋红色) if(i > 0) { if(DKLBuffer[i] <= DKLBuffer[i-1]) { ColorBuffer[i] = 0; // 蓝色 } else { ColorBuffer[i] = 1; // 洋红色 } } else { ColorBuffer[i] = 1; // 第一根K线默认洋红色 } // 调试输出(更新为显示低点) PrintFormat("Bar %d: Low=%.5f, VAR1=%.5f, LastTurn=%.5f, DKL=%.5f, Color=%s", i, low[i], VAR1Buffer[i], LastTurnBuffer[i], DKLBuffer[i], (ColorBuffer[i]==0?"Blue":"Magenta")); } return(rates_total); } //+------------------------------------------------------------------+ 以上代码在笔记本MT5软件上显示,但是在台式MT5软件主图上不显示,怎么回事,检查一下代码,使其在台式MT5上也能显示出来
12-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值