Problems found during the back testing and can't find the root cause! - page 5

 
jollydragon:

. I still can't see the disappearing of the peaks. How to "re-initialise" it?

  

You can re-initialise by either changing timeframes

or

open the indicator input window and click OK 

 

GumRai 2015.05.14 21:51 #

You can re-initialise by either changing timeframes

or

open the indicator input window and click OK  


After trying, I understand it's the same meaning as I said the peaks location change. Correct? 

 

 

 

Dear GumRai,

 
WHRoeder:

For every iteration, (except the first,) Fish1 is the value of the previous buffer element, but you don't initialize it to ExtBuffer1[limit].

So for the initial iteration (when limit == bars) you set ExtBuffer1[0] = 1.1*ExtBuffer1[1].

But for subsequent ticks (when limit == 1) you set ExtBuffer1[0] = 1.1*0.00001.

 

Dear WHRoeder,

 

Thank you very much and I see the issue a little better with your direction. 

However, may still need a few more questions to clarify further: 

1. You can see "double Fish1=0.00001; " is defined in the begining and out of all functions. 

   So it should be global variable and I understand it has been assigned with the last ExBuffer1[0] even though a new subsequent tick comes.

   Or it automatically recovers to "0.00001" every time if there's a new tick comes?

2. Now that every bar is painted differently with a single tick or many subsequent ticks, why can I see the re-painting of .., bar[8], ..., or bar[1], in a live M1 chart without any interrupting?  

3. Why are the locations of peaks changed after being refreshed? 

4. Why can I see some peaks(about 959870576) formed much, much less than "EMPTY_VALUE"(2147483647) in live M1 charts?

5. If there's a new bar comes out, previous ExtBuffer1[0] will change to ExtBuffer1[1] automatically. Correct? 

6. How to prevent any potential re-initialising or re-painting? 

Maybe I'm still confused on some critical points and need your great patience to help! It's greatly appreciated if you can help with the questions one by one!

 

Dear WHRoeder,GumRai,

I updated my indicator as the code below according to my understanding after reading your posts again. 

After using it for back testing, the result is much more consistent with the indicator. However, there are still 2 issues. Please refer to the screenshots below.

1. The trading takes place after 4 indicator signals at the beginning from the first order.

2. There is still one order change happens 4 bars ahead of the indicator signal. 

 

Below is the indicator code updated. 

#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.50"
#property strict
#property  indicator_separate_window
#property  indicator_buffers 2

extern int    period=35;
extern double smooth=0.3;

datetime       lastAlertTime;
double         ExtBuffer0[];
double         ExtBuffer1[];
double         ExtValue[];
double         Value1=0,Buffer0_1=0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorBuffers(3);
   SetIndexBuffer(0,ExtBuffer0); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,clrWhiteSmoke);
   SetIndexBuffer(1,ExtBuffer1); SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,clrGoldenrod);
   SetIndexBuffer(2,ExtValue);
   IndicatorShortName(" Solar Joy   ^v^  ");
   ArraySetAsSeries(ExtBuffer0,true);
   ArraySetAsSeries(ExtBuffer1,true);
   ArraySetAsSeries(ExtValue,true);

   SetIndexDrawBegin(1,period);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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[])
  {
   if(rates_total<=period)    return(0);

   int    i,limit;
   double price,MinL,MaxH;

   if(prev_calculated<rates_total-1) limit=rates_total-period-1;
   else                              limit=1;

   for(i=limit-1; i>=0; i--)
     {
      MaxH = High[iHighest(NULL,0,MODE_HIGH,period,i)];
      MinL = Low[iLowest(NULL,0,MODE_LOW,period,i)];
      price=(High[i]+Low[i])/2;
      if(limit==1)
        {
         Value1=ExtValue[1];
         Buffer0_1=ExtBuffer0[1];
        }
      ExtValue[i]=(1-smooth)*(2*(price-MinL)/(MaxH-MinL)-1.0) + smooth*Value1;
      ExtValue[i]=MathMin(MathMax(ExtValue[i],-0.999),0.999); // Value=Value>0.999?0.999:Value<-0.999?-0.999:Value;
      ExtBuffer0[i]=(1-smooth)*MathLog((1+ExtValue[i])/(1-ExtValue[i]))+smooth*Buffer0_1;
      Value1=ExtValue[i];
      Buffer0_1=ExtBuffer0[i];
      if(ExtBuffer0[i]>0) ExtBuffer1[i]=3;
      else ExtBuffer1[i]=-3;
     }

   return(rates_total);
  }
//+------------------------------------------------------------------+

 
jollydragon:

1. You can see "double Fish1=0.00001; " is defined in the begining and out of all functions. 

   So it should be global variable and I understand it has been assigned with the last ExBuffer1[0] even though a new subsequent tick comes.

   Or it automatically recovers to "0.00001" every time if there's a new tick comes?

No and no. What part of " but you don't initialize it to ExtBuffer1[limit]" was unclear?
if(prev_calculated<rates_total-1){limit=rates_total-period-1; Fish1=0.00001;       }
else                             {limit=1;                    Fish1=ExtBuffer0[1]; }
for(i=limit-1; i>=0; i--)
  {
   ExtBuffer1[i]=1.1*Fish1;
   Fish1=ExtBuffer1[i];
   if(Fish1>=EMPTY_VALUE)
      Fish1=1;
  }

Personally, I think the rates_total/prev_calculated/OnCalculate arguments are an abomination since charts/buffers are timeseries, and would do it the old way:
int counted = IndicatorCounted();
limit = Bars - MathMax(counted, period-1); // Lookback period-1
Fish1 = counted == 0 ? 0.00001 : ExtBuffer0[limit];
for(i=limit-1; i>=0; i--)
Reason: