Why this code shows a wrong result?

 
Hello pals,
Hope you are happy today.

I wanted to calculate and comment Maximal Drawdown and Relative DD for each tick.
But the commented Maximal DD and Relative DD results are different from what is presented in backtest report.
It would be greatly appreciated to point me where my mistake is.

P.S.
1.I know how to use GVs to store values, this code is just for backtest.
2.I used arrays because I want to do some work on each my Drawdowns after this.
        //global area
        double MaxAccountEquity[3],MinAccountEquity[3];
        double LastMaxAccountEquityShiftTime,LastMinAccountEquityShiftTime;
        double RelativeDrawdown[3],Drawdown[3],MaximalDrawdown;

        int OnInit()
        {
            MaxAccountEquity[0]=AccountBalance();
            MinAccountEquity[0]=AccountBalance();
            MaxAccountEquity[1]=AccountBalance();
            MinAccountEquity[1]=AccountBalance();
            MaxAccountEquity[2]=AccountBalance();
            MinAccountEquity[2]=AccountBalance();

         return(INIT_SUCCEEDED);
         }

        void OnTick()
        {
         if(AccountEquity()>MaxAccountEquity[0])
         {
            if(LastMaxAccountEquityShiftTime>=LastMinAccountEquityShiftTime)
            {
               MinAccountEquity[1]=MinAccountEquity[0];
               LastMinAccountEquityShiftTime=(double)TimeCurrent();
            }
            
            MaxAccountEquity[0]=AccountEquity();
         }
         
         if(AccountEquity()<MinAccountEquity[0])
         {
            if(LastMaxAccountEquityShiftTime<=LastMinAccountEquityShiftTime)
            {
               MaxAccountEquity[1]=MaxAccountEquity[0];
               LastMaxAccountEquityShiftTime=(double)TimeCurrent();
            }
            
            MinAccountEquity[0]=AccountEquity();
            
            Drawdown[0]=MathAbs(MinAccountEquity[0]-MaxAccountEquity[1]);
            RelativeDrawdown[0]=(Drawdown[0]/MaxAccountEquity[1])*100;
         }
            MaximalDrawdown=MathMax(MaximalDrawdown,RelativeDrawdown[0]);
         
         Comment("MaximalDrawdown = ", MaximalDrawdown);
        }

The question is: Why this code shows different MaximalDD from my backtest report?

Testing trading strategies on real ticks
Testing trading strategies on real ticks
  • www.mql5.com
The article provides the results of testing a simple trading strategy in three modes: "1 minute OHLC", "Every tick" and "Every tick based on real ticks" using actual historical data.
 
HosseinKOGO:
Hello pals,
Hope you are happy today.

I wanted to calculate and comment Maximal Drawdown and Relative DD for each tick.
But the commented Maximal DD and Relative DD results are different from what is presented in backtest report.
It would be greatly appreciated to point me where my mistake is.

P.S.
1.I know how to use GVs to store values, this code is just for backtest.
2.I used arrays because I want to do some work on each my Drawdowns after this.

The question is: Why this code shows different MaximalDD from my backtest report?

this doesnt work for boom and crash indexes as the spike is a reset of the price i am very confident this is what you are trying to do 

 
Amos Tsopotsa #:

this doesnt work for boom and crash indexes as the spike is a reset of the price i am very confident this is what you are trying to do 

I can not understand you, would you please explain more?
 
HosseinKOGO:
Hello pals,
Hope you are happy today.

I wanted to calculate and comment Maximal Drawdown and Relative DD for each tick.
But the commented Maximal DD and Relative DD results are different from what is presented in backtest report.
It would be greatly appreciated to point me where my mistake is.

P.S.
1.I know how to use GVs to store values, this code is just for backtest.
2.I used arrays because I want to do some work on each my Drawdowns after this.

The question is: Why this code shows different MaximalDD from my backtest report?

Could anybody help me please?
I'm still stuck :(