How to calculate from ID1

 

Hello,

I'm using an indicator IXO but using it in EA give serious fast problem in BackTest (is very slow).

The indi calculate in Tick and ID0 ...someone can suggest the modification to calculate every candle starting from ID1 (no ID0).

The code is easy, I try but I get error.

Many thanks.

THE CODE: 


//+------------------------------------------------------------------+
//|                                                    IXOAH_mt5.mq5 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   ""
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot Up
#property indicator_label1  "xoUp"
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_color1  clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Dwn
#property indicator_label2  "xoDwn"
#property indicator_type2   DRAW_HISTOGRAM
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- input parameters
input int      BoxSize=15;
//--- indicator buffers
double         UpBuffer[];
double         DwnBuffer[];

int Cur=0;
   int KirUp=0;
   int KirDn=0;
   int kr=0;
   int no=0;
   double valueh=0;
   double valuel=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,UpBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,DwnBuffer,INDICATOR_DATA); 
//---
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
//---
   ArraySetAsSeries(UpBuffer,true);
   ArraySetAsSeries(DwnBuffer,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[])
  {
//---
   int CurrentBar;
   double Hi=0,Lo=0,Curb=0;
   int bars=rates_total-1;//Bars(Symbol(),PERIOD_CURRENT);
//---
   ArraySetAsSeries(close,true);
   //ArraySetAsSeries(high,true);
   //ArraySetAsSeries(low,true);
//---


Comment (close[1]);

   //----Calculation---------------------------
   for(int i=0;i<=bars;i++)
   {
      CurrentBar = bars-i;
      if (Cur<1)
      {
         Hi=close[CurrentBar];
         Lo=close[CurrentBar];
         Cur=1;
      }
      Curb=close[CurrentBar];
      if (Curb>(Hi+BoxSize*_Point))
      {
         Cur+=1;
         Hi=Curb;
         Lo=Curb-BoxSize*_Point;
         KirUp=1;
         KirDn=0;
         kr+=1;
         no=0;   
      }
      if (Curb<(Lo-BoxSize*_Point))
      {
         Cur+=1;
         Lo=Curb;
         Hi=Curb+BoxSize*_Point;
         KirUp=0;
         KirDn=1;
         no+=1;
         kr=0;
      }
      valueh=kr;
      valuel=0-no;
      UpBuffer[CurrentBar]=valueh;
      DwnBuffer[CurrentBar]=valuel;
   }      
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Claudio Buratti:

Hello,

I'm using an indicator IXO but using it in EA give serious fast problem in BackTest (is very slow).

The indi calculate in Tick and ID0 ...someone can suggest the modification to calculate every candle starting from ID1 (no ID0).

The code is easy, I try but I get error.

Many thanks.

THE CODE: 


Use XO that does not calculate all the bars at each tick (there is no reason whatsoever to calculate XO all the bars all the time)
Reason: