Strategy Test become drastically slow (Visual Mode) after adding this indicator class to my strategy - page 2

 
Amir Yacoby #:

Try with first limit calculation before first loop:

And second limit calculation before second loop 

@Amir Yacoby

Wollah ... yes it resolved the issue man.

I am so grateful for your support and taking time off to resolve the issue. Hats off to the real Guru :)

 
Amir Yacoby #:

Try with first limit calculation before first loop:

And second limit calculation before second loop 

@Amir Yacoby

Dear Amir

As I worked on my strategy further, I noticed that the revised settings have some problem. I have taken two screen shots and have also placed on ZigZag indicator from MQL Examples too, to show you the error areas.

limit  = MathMax((int)(rates_total-prev_calculated-SlowLength-1),(int)(SlowLength+1));

limit  = MathMax((int)(rates_total-prev_calculated-FastLength-1),(int)(FastLength+1));
    Swing   = 0;

Before Changes to limit statement

after changes as suggested by you

after change

Hope you will find time to find the correct solution.

I have created an Test EA to run these and might be helpful to you, in case you want to run it.

regards.

Files:
 

I think you need to define exactly what you want it to do, in words, in order to anyone to be able to check the logic.

Also it's advisable to use meaningful variable names, not zu/zd/BL/BH etc.. 

About the limit calculation, it is just a standard means in indicators. 
It runs on total bars on the first tick, and on the next ticks it runs only on the SlowLength/FastLenght last number of bars (depending on if you calculate the major or minor). 

What do you try to do when starting those variables before working  

    zu      = limit;
    zd      = limit;
    BH      = high[limit];
    BL      = low[limit];
 
Amir Yacoby #:

I think you need to define exactly what you want it to do, in words, in order to anyone to be able to check the logic.

Also it's advisable to use meaningful variable names, not zu/zd/BL/BH etc.. 

About the limit calculation, it is just a standard means in indicators. 
It runs on total bars on the first tick, and on the next ticks it runs only on the SlowLength/FastLenght last number of bars (depending on if you calculate the major or minor). 

What do you try to do when starting those variables before working  

@Amir Yacoby

Thanks for reviewing my post.

I will admit you that this is not my code (I have not yet reached that level of expertise). I have used 'Boa_ZigZag_Arrows_Duplex' indicator from the forum, as it provided separate buffers for LO/HI as well as allows two periods (for Slow and Fast ZigZag calculations). I have made some cosmetic changes for the easy reading without disturbing the logic of the indicator. Yes I did faced the same problem about the variable names. That seems due to the conversion of indicator from Russian to English.

My requirements are simple, get Swing LO/HI values for Single period (Depth) and better if can have two periods. 'Boa_ZigZag_Arrows_Duplex' indicator does not consider Deviation and BackStep variables of MQL Standard ZigZag indicator. It really did not affect me, as the values shown for two depth periods are fine for me.

I am now trying to use MQL standard Examples\ZigZag.mq5 indicator and create a class where I can have two instances (for two periods) of the same. Challenge is to separate LO/HI values from the single LO/HI buffer. I can then use this class to create my own indicator to display ZigZag in my preferred way as arrows instead of lines and in my EA Calculations.

I will revert back to you, if I fail to do this ...

Once again thanks a lot and best regards.

 
Anil Varma #:

@Amir Yacoby

Thanks for reviewing my post.

I will admit you that this is not my code (I have not yet reached that level of expertise). I have used 'Boa_ZigZag_Arrows_Duplex' indicator from the forum, as it provided separate buffers for LO/HI as well as allows two periods (for Slow and Fast ZigZag calculations). I have made some cosmetic changes for the easy reading without disturbing the logic of the indicator. Yes I did faced the same problem about the variable names. That seems due to the conversion of indicator from Russian to English.

My requirements are simple, get Swing LO/HI values for Single period (Depth) and better if can have two periods. 'Boa_ZigZag_Arrows_Duplex' indicator does not consider Deviation and BackStep variables of MQL Standard ZigZag indicator. It really did not affect me, as the values shown for two depth periods are fine for me.

I am now trying to use MQL standard Examples\ZigZag.mq5 indicator and create a class where I can have two instances (for two periods) of the same. Challenge is to separate LO/HI values from the single LO/HI buffer. I can then use this class to create my own indicator to display ZigZag in my preferred way as arrows instead of lines and in my EA Calculations.

I will revert back to you, if I fail to do this ...

Once again thanks a lot and best regards.

@Amir Yacoby

Hi Amir

Here is update for you.

MQL5 ZigZag seems more complicated and reading multiples review of the same, indicate that it is also slower.

Anyway, I tried to get values from its buffer 0, thinking that it will contain LOW AND HIGH values. But what it is returning is only HIGH Values. I have tried following code.

                mLookBackZZs = pLookBack * 2;                                                                                                                                                                   // ZZ LOW + ZZ HIGH = pLookBack * 2

                // MQL ZIGZAG INDICATOR HAS SINGLE BUFFER[0] FOR LOW AND HIGH VALUES, WE NEED TEMPORARY BUFFER TO GET THESE VALUES
                SZigZag BufferZZ[];
                ArraySetAsSeries(BufferZZ,true);
                ArrayResize(BufferZZ,mLookBackZZs + 1);                                                                                                                         // mLookBackZZs + 1 FOR ELEMENT[0]

                // LOOP UNTIL REQUIRED NUMBER (i.e. mLookBackZZs * 2) OF ZIG ZAG LOW AND HIGH VALUES FOUND
                int      count   = 0;
                double priceZZ = 0.00;

                for(int i = mBarStart; i <= mLookBackBars; i++) {                                                                                       // mLookBackBars SET AS MAX 1000 BARS TO LOOK BACK

            priceZZ = GetIndexZZ(bufferMajorLO,i);                                                                                                                      // GET ZigZag[i] VALUE
                        if(priceZZ == 0.00)                                                      continue;                                                                                                               // CONTINUE TO NEXT ELEMENT IN THE ARRAY

            if(count <= mLookBackZZs) {                                                                                                                                                         // ADD VALUE TO pMajorLO ARRAY
              BufferZZ[count+1].idx     = i;                                                                                                                                                    // ON FIRST MajorLO, count = 0 + 1 FOR INDEX[1]
              BufferZZ[count+1].price = priceZZ;
              count++;
                                //PrintFormat("i=[%i] count=[%i] BufferZZ[%i][%.2f]",i,count,BufferZZ[count].idx,BufferZZ[count].price);
            }
            if(count >= mLookBackZZs)                   break;                                                                                          // EXIT, LOOP WHEN REQUIRED VALUES ARE FOUND
          }

this is the result and all of them are swing high values.

[10][29431.1] [9][29645.2] [8][29543.3] [7][29655.3] [6][29628.3] [5][29872.9] [4][29967.4] [3][29910.9] [2][30313.8] [1][30338.3] [0][0.0]


 

@Amir Yacoby

It looks like both 'Boa_ZigZag_Arrows_Duplex' and MQL5 ZigZag indicators are repainting.

Hence when I see it on historical data in MetaTrader5, it shows me correct ZigZag points. However when I run tester for the same period, both of them show the different values.

Is there any work around to handle this problem ?

regards. 

 
Anil Varma #:

@Amir Yacoby

It looks like both 'Boa_ZigZag_Arrows_Duplex' and MQL5 ZigZag indicators are repainting.

Hence when I see it on historical data in MetaTrader5, it shows me correct ZigZag points. However when I run tester for the same period, both of them show the different values.

Is there any work around to handle this problem ?

regards. 

They are repainted for the last zigzag point. On historic data, all is already known, only the last point might change (or not).

On live run, you have to treat the last point as temporary until a newer point is formed.

Reason: