ZIGZAG support and resistance issue

 

Hi
I found this code base on ZIGZAG support and resistance good to complete my strategy.

extern int ExtDepth=12;
extern int ExtDeviation=5;
extern int ExtBackstep=3;

int start()
  {

   int n=0, i;
   double p0=0, p1=0, p2=0;

   i=0;
      while(n<2)
      {
      if(p0>0) {p2=p1; p1=p0;}
      p0=iCustom(Symbol(),0,"zigzag",ExtDepth,ExtDeviation,ExtBackstep,0,i);
      if(p0>0) n+=1;
      i++;
      }
      
//------------------------------------------------------------------- Drawing Begin
      ObjectDelete("Res");
      ObjectCreate("Res",OBJ_HLINE,0,0,p0);
      ObjectSet("Res",OBJPROP_COLOR,Red);
      ObjectSet("Res",OBJPROP_WIDTH,2);
      ObjectSet("Res",OBJPROP_STYLE,STYLE_SOLID);
      ObjectSet("Res",OBJPROP_RAY,false);
      ObjectSetText("Res","Up & Price Down "+string(p0),10,"Times New Roman",Red);

      ObjectDelete("Sup");
      ObjectCreate("Sup",OBJ_HLINE,0,0,p1);
      ObjectSet("Sup",OBJPROP_COLOR,Blue);
      ObjectSet("Sup", OBJPROP_WIDTH,2);
      ObjectSet("Sup",OBJPROP_STYLE,STYLE_SOLID);
      ObjectSet("Sup",OBJPROP_RAY,false);
      ObjectSetText("Sup","Down & Price Up "+string(p1),10,"Times New Roman",Blue);
  //------------------------------------------------------------------- Drawing End

   Comment("Price 0: " ,p0,", Price 1: " ,p1); }

The p1 is line for support or resistance which changes following the trend.

I tried unsuccessfully to create a signal as soon as the line of support and resistance changed.

So I tried this conditions to look at the state of the resistance line at the last bar [1] and where it is now [0].(looking for the moment of change ).  

   if(Low[1]>p1 && High[0]<=p1) Print("Trend Down Change to Up");
   if(Low[1]>p1 && p1>p0) Print("Trend Down Change to Up");

It's very important to mention that I'm Newbies.

I really need your help please

(Attached the ZIGZAG indicator I am using)

Thanks in advance

Shay

Files:
ZigZag.mq4  9 kb
 
Shay Matityahu :

Hi
I found this code base on ZIGZAG support and resistance good to complete my strategy.

The p1 is line for support or resistance which changes following the trend.

I tried unsuccessfully to create a signal as soon as the line of support and resistance changed.

So I tried this conditions to look at the state of the resistance line at the last bar [1] and where it is now [0].(looking for the moment of change ).  

It's very important to mention that I'm Newbies.

I really need your help please

(Attached the ZIGZAG indicator I am using)

Thanks in advance

Shay

This is an example for extracting a signal.

When the price is on the turning point of the trend, it enter "High" or "Low" and when no signal enter "Non" in "signal", and is displayed in the comment.

Maybe you will understand it if you also display Zigzag on this. But since it repaints, it can not be used for EA.

#property indicator_chart_window
#property strict

extern int ExtDepth=12;
extern int ExtDeviation=5;
extern int ExtBackstep=3;
extern int SignalBar = 0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {

   int n=0,i;
   double p0=0,p1=0,p2=0;
   string signal;

   i=0;
   while(n<2)
     {
      if(p0>0) {p1=p0;}   //if(p0>0) {p2=p1; p1=p0;}
      p0=iCustom(Symbol(),0,"zigzag",ExtDepth,ExtDeviation,ExtBackstep,0,i);
      if(p0>0) n+=1;
      
      if (i == SignalBar)
      {
        if (p0 == High[SignalBar])
                signal = "High";
        else if (p0 == Low[SignalBar])
                signal = "Low";
        else
                signal = "Non";
      }
      
      i++;
     }

        if (p0 < p1)
        {
                p2 = p0;
                p0 = p1;
                p1 = p2;
        }
//------------------------------------------------------------------- Drawing Begin
   ObjectDelete("Res");
   ObjectCreate("Res",OBJ_HLINE,0,0,p0);
   ObjectSet("Res",OBJPROP_COLOR,Red);
   ObjectSet("Res",OBJPROP_WIDTH,2);
   ObjectSet("Res",OBJPROP_STYLE,STYLE_SOLID);
   ObjectSet("Res",OBJPROP_RAY,false);
   ObjectSetText("Res","Up & Price Down "+string(p0),10,"Times New Roman",Red);

   ObjectDelete("Sup");
   ObjectCreate("Sup",OBJ_HLINE,0,0,p1);
   ObjectSet("Sup",OBJPROP_COLOR,Blue);
   ObjectSet("Sup",OBJPROP_WIDTH,2);
   ObjectSet("Sup",OBJPROP_STYLE,STYLE_SOLID);
   ObjectSet("Sup",OBJPROP_RAY,false);
   ObjectSetText("Sup","Down & Price Up "+string(p1),10,"Times New Roman",Blue);
//------------------------------------------------------------------- Drawing End

   Comment("Price 0: ",p0,", Price 1: ",p1, ", Signal: ",signal); //Comment("Price 0: ",p0,", Price 1: ",p1);
   
   return(0);
  }
//+------------------------------------------------------------------+
 
Naguisa Unada:

This is an example for extracting a signal.

When the price is on the turning point of the trend, it enter "High" or "Low" and when no signal enter "Non" in "signal", and is displayed in the comment.

Maybe you will understand it if you also display Zigzag on this. But since it repaints, it can not be used for EA.


Hi Naguisa,

Thanks for your quick response

It's very nice but not exactly what I meant.

In your example every time when price = p1 it enter high signal.

I would like the trigger every time p1 replaces its role, something like: if p1<p0 and then p1>p0

Thanks

Shay

 
Shay Matityahu :

In your example every time when price = p1 it enter high signal.

I would like the trigger every time p1 replaces its role, something like: if p1<p0 and then p1>p0

Thanks

Shay

I do not know which part is mentioned.

As the following line shows, p1 is a support line, so it always show lower price.

Also, it is impossible to program like "if (p1 <p0) and then if (p1> p0)". The program needs to be changed drastically.

 ObjectCreate ( "Sup" , OBJ_HLINE , 0 , 0 ,p1);

By checking the value of p0 as below, you can achieve the purpose of "if (p1 <p0) and then if (p1> p0)" which you mentioned.

 if (p0 == High [SignalBar])

 else if (p0 == Low [SignalBar])

I do not know what program you want to create, so I can not answer any more.

Reason: