Zigzag indicator

 

Hello,

I would like to use the values of the Zigzag indicator in my EA for define the stoploss value.

How can I do??

Thank you.

 

Antoine. 

 
Please read this help topic at first.
 

Ok but I have to use values calculated by the Zigzag indicator, and the iZigzag handle doesn't exist and I can't use values calculated on the OnCalculate part in the OnTick part .

So there is another solution or am I wrong???

 
Antoine:

Ok but I have to use values calculated by the Zigzag indicator, and the iZigzag handle doesn't exist and I can't use values calculated on the OnCalculate part in the OnTick part .

So there is another solution or am I wrong???

How did you get to know that handle doesn't exist? Did you call the GetLastError() function?
Documentation on MQL5: Checkup / GetLastError
  • www.mql5.com
Checkup / GetLastError - Documentation on MQL5
 

I tried to write indicatorHandle=iZigzag() but no information appear (like when you write iMACD()).

 
Antoine:

I tried to write indicatorHandle=iZigzag() but no information appear (like when you write iMACD()).

There is no function like iZigZag (or something like this) in MQL5. This indicator is implemented into standard delivery only as custom indicator (https://www.mql5.com/en/docs/indicators). So to get handle to ZigZag indicator you should use function iCustom(...)

Documentation on MQL5: Technical Indicators
  • www.mql5.com
Technical Indicators - Documentation on MQL5
 

Thank you but I don't really confortable with the function iCustom()... I'm a newbie with MQL5 and progamation in general...

Can you help me for implement the code for the zigzag indicator please??...

 Thank you.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events
  • www.mql5.com
Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events - Documentation on MQL5
 

See attach my code which run well if someone need....

It searchs and store values in 2 variables for High and Low values 

//+------------------------------------------------------------------+
//|                                                   ZigzagTest.mq5 |
//|                                                    Antoine Blanc |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Antoine Blanc"
#property link      "http://www.mql5.com"
#property version   "1.00"

int ZigzagHandle;

//--- input parameters
input int      ExtDepth=12;
input int      ExtDeviation=5;
input int      ExtBackstep=3;

//--- indicator buffers
double         ZigzagBuffer[];      // main buffer
double         HighMapBuffer[];     // highs
double         LowMapBuffer[];      // lows
int            level=3;             // recounting depth
double         deviation;           // deviation in points

//--- Stochastic values
double Zigzag2P=0.00000;
double Zigzag2N=0.00000;
double Zigzag1P=0.00000;
double Zigzag1N=0.00000;
double ZigzagP=0.00000;
double ZigzagN=0.00000;

datetime DateZigzagP=0;
datetime DateZigzagN=0;
datetime Date1ZigzagP=0;
datetime Date1ZigzagN=0;
datetime Date2ZigzagP=0;
datetime Date2ZigzagN=0;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {

//--- indicator buffers mapping
   SetIndexBuffer(0,ZigzagBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,HighMapBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,LowMapBuffer,INDICATOR_CALCULATIONS);
  
   ZigzagHandle=iCustom(Symbol(),Period(),"Examples\\ZigZag",ExtDepth,ExtDeviation,ExtBackstep);
  
   if(ZigzagHandle<0)
     {
      Alert("Error Creating Handles for indicators - error: ",GetLastError(),"!!");
      return(-1);
     }

//---
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   IndicatorRelease(ZigzagHandle);
  }
  
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---  
   double High[];      //array for higher prices
   double Low[];       //array for Lower prices

   static datetime Old_Time;
   datetime New_Time[1];
   bool IsNewBar=false;

// copying the last bar time to the element New_Time[0]
   int copied=CopyTime(_Symbol,_Period,0,1,New_Time);
   if(copied>0) // ok, the data has been copied successfully
     {
      if(Old_Time!=New_Time[0]) // if old time isn't equal to new bar time
        {
         IsNewBar=true;   // if it isn't a first call, the new bar has appeared
         if(MQL5InfoInteger(MQL5_DEBUGGING)) Print("We have new bar here ",New_Time[0]," old time was ",Old_Time);
         Old_Time=New_Time[0];            // saving bar time
        }
     }
   else
     {
      Alert("Error in copying historical times data, error =",GetLastError());
      ResetLastError();
      return;
     }

//--- EA should only check for new trade if we have a new bar
   if(IsNewBar==false)
     {
      return;
     }
   ArraySetAsSeries(High,true); //set High[] array as timeseries
   ArraySetAsSeries(Low,true); //set Low[] array as timeseries

   ArraySetAsSeries(ZigzagBuffer,true);
   ArraySetAsSeries(HighMapBuffer,true);
   ArraySetAsSeries(LowMapBuffer,true);
  
   CopyHigh(_Symbol,_Period,0,11,High);//filling the High[] array with current values
   CopyLow(_Symbol,_Period,0,11,Low);//filling the Low[] array with current values
  
   if(CopyBuffer(ZigzagHandle,0,0,3,ZigzagBuffer)<=0)
     {
      Print("Getting ZigzagBuffer is failed! Error",GetLastError());
      return;
     }

   if(CopyBuffer(ZigzagHandle,1,0,3,HighMapBuffer)<=0)
     {
      Print("Getting HighMapBuffer is failed! Error",GetLastError());
      return;
     }

   if(CopyBuffer(ZigzagHandle,2,0,3,LowMapBuffer)<=0)
     {
      Print("Getting LowMapBuffer is failed! Error",GetLastError());
      return;
     }
    
   if(ZigzagBuffer[1]==High[1])
     {
      ZigzagP=ZigzagBuffer[1];
      DateZigzagP=TimeCurrent();
      Zigzag2N=Zigzag1N;
      Zigzag1N=ZigzagN;
      Date1ZigzagN=DateZigzagN;
     }

   if(ZigzagBuffer[1]==Low[1])
     {
      ZigzagN=ZigzagBuffer[1];
      DateZigzagN=TimeCurrent();
      Zigzag2P=Zigzag1P;
      Zigzag1P=ZigzagP;
      Date1ZigzagP=DateZigzagP;
     }
  }
//+------------------------------------------------------------------+

 

 

Hello Antoine.

 

Are u stiill here? Do u have idea how to translate this code to the MetaTrader 4. There are no functions as CopyHigh, CopyLow, CopyBuffer. Do u have any idea? 

 

OR

 

Your code is nice. I would like to made code what will store last few highs and lows of ZIGZAG.. And after that I wanna do some comparisions and get to the long or short after known rule 1-2-3.

Of course after some other filters will be applied.

But first i really would like to know how to develop easy strategy for known 1-2-3 (A-B-C) using ZIGZAG with pending stop orders.

So, please, do u know about anything what is clear to understanding? 

 

Thank you in advance. Have a nice day!