MultiTF Pivot!请教大神,这个自定义指标程序有什么问题?初次加载不能正确显示指标线,再次手动加载能够正常显示运行。

 

指标程序源码如下:

#property description "MultiTF Pivots"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers   6
#property indicator_plots     6
#property indicator_type1     DRAW_LINE
#property indicator_style1    STYLE_SOLID
#property indicator_color1    clrYellow
#property indicator_width1    2
#property indicator_label1    "LowTFP"
#property indicator_type2     DRAW_LINE
#property indicator_style2    STYLE_SOLID
#property indicator_color2    clrNONE
#property indicator_label2    "LowTFR1"
#property indicator_type3     DRAW_LINE
#property indicator_style3    STYLE_SOLID
#property indicator_color3    clrNONE
#property indicator_label3    "LowTS1"
#property indicator_type4     DRAW_LINE
#property indicator_style4    STYLE_DOT
#property indicator_color4    clrPink
#property indicator_label4    "HighTFP"
#property indicator_type5     DRAW_LINE
#property indicator_style5    STYLE_DASHDOT
#property indicator_color5    clrPink
#property indicator_label5    "HighTFR1"
#property indicator_type6     DRAW_LINE
#property indicator_style6    STYLE_DASHDOT
#property indicator_color6    clrPink
#property indicator_label6    "HighTFS1"

input ENUM_TIMEFRAMES    LowTF    =PERIOD_H4;
input ENUM_TIMEFRAMES   HighTF    =PERIOD_D1;

double LowTFP[];
double LowTFR1[];
double LowTFS1[];
//double LowTFR2[];
//double LowTFS2[];
double HighTFP[];
double HighTFR1[];
double HighTFS1[];
int    LShift, HShift, MinBars;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
string sn1, sn2, shortname;
//--- check for input value
   if(LowTF<Period() || HighTF<LowTF || Period()>PERIOD_H1)
     {
       Print("Incorrect timeframe input parameter......");
       return(INIT_FAILED);
     }
   LShift=PeriodSeconds(LowTF)/PeriodSeconds(PERIOD_CURRENT);
   HShift=PeriodSeconds(HighTF)/PeriodSeconds(PERIOD_CURRENT);
   SetIndexBuffer(0,LowTFP,INDICATOR_DATA);
   SetIndexBuffer(1,LowTFR1,INDICATOR_DATA);
   SetIndexBuffer(2,LowTFS1,INDICATOR_DATA);
   SetIndexBuffer(3,HighTFP,INDICATOR_DATA);
   SetIndexBuffer(4,HighTFR1,INDICATOR_DATA);
   SetIndexBuffer(5,HighTFS1,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,HShift);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,HShift);
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,HShift);
   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,HShift);
   PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,HShift);
   PlotIndexSetInteger(5,PLOT_DRAW_BEGIN,HShift);
   MinBars=MathMax(LShift,HShift);

   shortname="MultiTF Pivot v11(LTF: "+EnumToString(LowTF)+", HTF: "+EnumToString(HighTF)+")";
   IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//---
   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 i=0, limit=0, shift1=0, shift2=0;
int copied1,copied2;
MqlRates LtfRates[],HtfRates[];

    ArraySetAsSeries(LtfRates,true);
    ArraySetAsSeries(HtfRates,true);
//--- check for bars count
   if(rates_total<MinBars)
   {  Print("Not enough bars for calculation to ",Symbol());  return(0);  }
   if(prev_calculated==0)
     limit=MinBars;
   else
     limit=prev_calculated-1; 
   for(i=limit;i<rates_total && !IsStopped();i++)
   {  copied1=CopyRates(NULL,LowTF,time[i],2,LtfRates);
      copied2=CopyRates(NULL,HighTF,time[i],2,HtfRates);
      if(copied1>0 && copied2>0)
      {
         LowTFP[i]=(LtfRates[1].high+LtfRates[1].low+LtfRates[1].close)/3.0;
         LowTFR1[i]=2*LowTFP[i]-LtfRates[1].low;
         LowTFS1[i]=2*LowTFP[i]-LtfRates[1].high;
         HighTFP[i]=(HtfRates[1].high+HtfRates[1].low+HtfRates[1].close)/3.0;
         HighTFR1[i]=2*HighTFP[i]-HtfRates[1].low;
         HighTFS1[i]=2*HighTFP[i]-HtfRates[1].high;
      }
   }       
   return(rates_total);
}
//+------------------------------------------------------------------+
请高手修正。

 
源代码是MQL5编写
 

论坛


When you post code please use the CODE button (Alt-S)!

Use the CODE button

 
ok!
原因: