How to get information from the ZigZag indicator?

 

Hello to the MQL community,

I'm using the ZigZag indicator for my strategy and building an EA for that porpuse. Is there a way for getting info. from this indicator?

The info. that i need, is the price at the last top "zigzag", and the price at the last bottom "zigzag".

I enclose a picture illustration

Thank you for the help!

 

I should warn you ... all those zigs & zags (e.g. that 'last bottom zigzag price' at midnight) were not indicated at that time, but several bars later. It 'repaints'

To verify, check it out on a 1 minute chart.

 
Roller555:

Hello to the MQL community,

I'm using the ZigZag indicator for my strategy and building an EA for that porpuse. Is there a way for getting info. from this indicator?

The info. that i need, is the price at the last top "zigzag", and the price at the last bottom "zigzag".

I enclose a picture illustration

Thank you for the help!


Hi,

in the codebase was an indicator called AutoFibAutoTrend.mq4 using the zigzag.

Will help you for your question, take care about repainting like brewmanz was telling you before !!1

 

Some things i notice during the developement of the AutoFibAutoTrend, the repainting in general is not an issue if you don't use the last value as the OP showed in the picutre. The biggest problem regarding the ZigZag is that in some cases it draws to bottom Zag's without a upper Zig in the middle,

I suggest to:

  1. use a non repainting zigzag from the codebase
  2. impelment a checkZZ() function wich makes sure that: ( (zz1>zz2 && zz2<zz3) || (zz1<zz2 && zz2>zz3) )
  3. I do think now, after i have done more work with the standart zz that it is not well coded, because we can life with some recalculations, but this indicator in also not always the same when we reattach it to the screen. This point makes it really hard to develope a system based on it.
  4. I made a "MA cross based ZigZag" which does not repaint. It might lag a bit. There was also released another really intersting ZigZag variation on the same day as mine. I suggest you try these two and the that one which fits better your tradingstyle.
  5. Attach the zigzag in Visual Tester mode to see how it behaves, this is always recommend when you test a "new" indicator.
 

i used this code for get price from high and low of zigzag

int zigZagHandle=INVALID_HANDLE;
double ExtZigZagLowBuffer[];

int OnInit(){

   if( (zigZagHandle=iCustom(_Symbol, _Period, "::Indicators\\Examples\\ZigZag.ex5", 5, 3, 3)) == INVALID_HANDLE )
      return(INIT_FAILED);
 
   return(INIT_SUCCEEDED);
   
}

if(CopyBuffer(zigZagHandle, 2, 0, 100, ExtZigZagLowBuffer) <= 0)
ArraySetAsSeries(ExtZigZagLowBuffer,true); 

void fn(){
        double stopLoss;
        for(int i=0;i<99;i++){
                if(ExtZigZagLowBuffer[i] > 0){
                        stopLoss = iLow(Symbol(), Period(), i);
                        printf("stopLoss=" + stopLoss);
                        break;
                }
                  
        }
}