ZigZag

Posted By: SFF

ZigZag - 02/22/13 11:39

It says an error which is:
syntax error
< case 1: // look for peak
>
.

I don't know why this happen while cace 0 is fine?.


Code:
function run(){
	
	
BarPeriod = 15;
LookBack = 500;
StartDate = 20120201;
NumDays = 1;

  set(TICKS);
int ExtDepth=12;
int ExtDeviation=5;
int ExtBackstep=3;
int whatlookfor;
var curlow;
var curhigh;
var lastlow;
var lasthigh;
int lasthighpos;
int lastlowpos;
var res;
vars ZigzagBuffer= series(0.0);  
vars LowMapBuffer=series(0.0);
vars HighMapBuffer=series(0.0);

var val=LL(ExtDepth);
if(val==lastlow) val=0.0;
else 
        { 
         lastlow=val; 
         if((priceLow()-val)>(ExtDeviation*PIP)) val=0.0;
         else
           {
           	int back;
            for(back=1; back<=ExtBackstep; back++)
              {
               res=LowMapBuffer[0+back];
               if((res!=0)&&(res>val)) LowMapBuffer[0+back]=0.0; 
              }
           }
        } 
               
 if (priceLow()==val) LowMapBuffer[0]=val; else LowMapBuffer[0]=0.0;
 
 val=HH(ExtDepth);
      if(val==lasthigh) val=0.0;
      else 
        {
         lasthigh=val;
         if((val-priceHigh())>(ExtDeviation*PIP)) val=0.0;
         else
           {
           	int back;
            for(back=1; back<=ExtBackstep; back++)
              {
               res=HighMapBuffer[0+back];
               if((res!=0)&&(res<val)) HighMapBuffer[0+back]=0.0; 
              } 
           }
        }
      if (priceHigh()==val) HighMapBuffer[0]=val; else HighMapBuffer[0]=0.0;
      
      
      
      if (whatlookfor==0)
     {
      lastlow=0;
      lasthigh=0;  
     }
   else
     {
      lastlow=curlow;
      lasthigh=curhigh;
     }
   
      res=0.0;
      switch(whatlookfor)
        {
         case 0:
            if (lastlow==0 && lasthigh==0)
              {
               if (HighMapBuffer[0]!=0)
                 {
                  lasthigh=priceHigh();
                  lasthighpos=0;
                  whatlookfor=-1;
                  ZigzagBuffer[0]=lasthigh;
                  res=1;
                 }
               if (LowMapBuffer[0]!=0)
                 {
                  lastlow=priceLow();
                  lastlowpos=0;
                  whatlookfor=1;
                  ZigzagBuffer[0]=lastlow;
                  res=1;
                 }
                 }
              
             break;  
         case 1:
            if (LowMapBuffer[0]!=0.0 && LowMapBuffer[0]<lastlow && HighMapBuffer[0]==0.0)
              {
               ZigzagBuffer[lastlowpos]=0.0;
               lastlowpos=0;
               lastlow=LowMapBuffer[0];
               ZigzagBuffer[0]=lastlow;
               res=1;
              }
            if (HighMapBuffer[0]!=0.0 && LowMapBuffer[0]==0.0)
              {
               lasthigh=HighMapBuffer[0];
               lasthighpos=0;
               ZigzagBuffer[0]=lasthigh;
               whatlookfor=-1;
               res=1;
              }   
            break;               
         case -1: // look for lawn
            if (HighMapBuffer[0]!=0.0 && HighMapBuffer[0]>lasthigh && LowMapBuffer[0]==0.0)
              {
               ZigzagBuffer[lasthighpos]=0.0;
               lasthighpos=0;
               lasthigh=HighMapBuffer[0];
               ZigzagBuffer[0]=lasthigh;
              }
            if (LowMapBuffer[0]!=0.0 && HighMapBuffer[0]==0.0)
              {
               lastlow=LowMapBuffer[0];
               lastlowpos=0;
               ZigzagBuffer[0]=lastlow;
               whatlookfor=1;
              }   
            break;               
         default: return; 
        }
        plot("Signal", HighMapBuffer[0], 0, RED);
         plot("Signal2", LowMapBuffer[0], 0, RED);
     
     }

Posted By: jcl

Re: ZigZag - 02/22/13 14:33

If a line causes an error message although its syntax is ok, then the compiler expects something else here. The usual mistake is a bracket that's missing or superfluous in the lines before.

Aside from that, I see in your code several function calls, f.i. priceLow() etc. with missing parentheses. A function with no parentheses is not called, it's only a pointer.
Posted By: SFF

Re: ZigZag - 02/23/13 00:58

Thank you for your advice.
Yes, You are right and it is because of a missing bracket.

The working script is updated above but From plot, It looks something wrong.
Could you please check the plot?
Posted By: SFF

Re: ZigZag - 03/06/13 07:57

Hi JCL,

Could you have this code working correctly?

It can be compiled, but the plot looks wrong.
Posted By: jcl

Re: ZigZag - 03/06/13 09:55

You have probably taken over this script from somewhere else, and the original version certainly used global variables, not local variables. "lasthigh" etc. are supposed to keep their values between runs. So you must define those variables either outside the run function, as in the original script, or define them as "static".

When you convert a script, first understand how it works. If the converted version then behaves wrongly, check the behavior of its variables with the debugging method described under "Tips & Tricks". This way you can find out fast which variable gets a different value than you expect.
Posted By: SFF

Re: ZigZag - 03/06/13 10:02

Thanks.

The updated code is here but the plot looks right but the line is ugly in Zorro.
How Can I plot the zigzag line like in MT4?
The original version is a MT4 zigzag.

Code:
int ExtDepth=12;
int ExtDeviation=5;
int ExtBackstep=3;
int whatlookfor;
var curlow;
var curhigh;
var lastlow;
var lasthigh;
int lasthighpos;
int lastlowpos;
var res;

function run(){
	
	set(PLOTPRICE+PLOTNOW);
BarPeriod = 15;
LookBack = 500;
StartDate = 20120201;
NumDays = 1;
  set(TICKS);
  
  vars ZigzagBuffer= series(0.0);  
vars LowMapBuffer=series(0.0);
vars HighMapBuffer=series(0.0);


var val=LL(ExtDepth);
if(val==lastlow) val=0.0;
else 
        { 
         lastlow=val; 
         if((priceLow()-val)>(ExtDeviation*PIP)) val=0.0;
         else
           {
           	int back;
            for(back=1; back<=ExtBackstep; back++)
              {
               res=LowMapBuffer[0+back];
               if((res!=0)&&(res>val)) LowMapBuffer[0+back]=0.0; 
              }
           }
        } 
               
 if (priceLow()==val) LowMapBuffer[0]=val; else LowMapBuffer[0]=0.0;
 
 val=HH(ExtDepth);
      if(val==lasthigh) val=0.0;
      else 
        {
         lasthigh=val;
         if((val-priceHigh())>(ExtDeviation*PIP)) val=0.0;
         else
           {
           	int back;
            for(back=1; back<=ExtBackstep; back++)
              {
               res=HighMapBuffer[0+back];
               if((res!=0)&&(res<val)) HighMapBuffer[0+back]=0.0; 
              } 
           }
        }
      if (priceHigh()==val) HighMapBuffer[0]=val; else HighMapBuffer[0]=0.0;
      
      
      
      if (whatlookfor==0)
     {
      lastlow=0;
      lasthigh=0;  
     }
   else
     {
      lastlow=curlow;
      lasthigh=curhigh;
     }
   
      res=0.0;
      switch(whatlookfor)
        {
         case 0:
            if (lastlow==0 && lasthigh==0)
              {
               if (HighMapBuffer[0]!=0)
                 {
                  lasthigh=priceHigh();
                  lasthighpos=0;
                  whatlookfor=-1;
                  ZigzagBuffer[0]=lasthigh;
                  res=1;
                 }
               if (LowMapBuffer[0]!=0)
                 {
                  lastlow=priceLow();
                  lastlowpos=0;
                  whatlookfor=1;
                  ZigzagBuffer[0]=lastlow;
                  res=1;
                 }
                 }
              
             break;  
         case 1:
            if (LowMapBuffer[0]!=0.0 && LowMapBuffer[0]<lastlow && HighMapBuffer[0]==0.0)
              {
               ZigzagBuffer[lastlowpos]=0.0;
               lastlowpos=0;
               lastlow=LowMapBuffer[0];
               ZigzagBuffer[0]=lastlow;
               res=1;
              }
            if (HighMapBuffer[0]!=0.0 && LowMapBuffer[0]==0.0)
              {
               lasthigh=HighMapBuffer[0];
               lasthighpos=0;
               ZigzagBuffer[0]=lasthigh;
               whatlookfor=-1;
               res=1;
              }   
            break;               
         case -1: // look for lawn
            if (HighMapBuffer[0]!=0.0 && HighMapBuffer[0]>lasthigh && LowMapBuffer[0]==0.0)
              {
               ZigzagBuffer[lasthighpos]=0.0;
               lasthighpos=0;
               lasthigh=HighMapBuffer[0];
               ZigzagBuffer[0]=lasthigh;
              }
            if (LowMapBuffer[0]!=0.0 && HighMapBuffer[0]==0.0)
              {
               lastlow=LowMapBuffer[0];
               lastlowpos=0;
               ZigzagBuffer[0]=lastlow;
               whatlookfor=1;
              }   
            break;               
         default: return; 
        }
        plot("Signal", HighMapBuffer[0], 0, RED);
         plot("Signal2", LowMapBuffer[0], 0, BLUE);
         plot("Signal2", ZigzagBuffer[0], 0, RED);
     
     }

© 2024 lite-C Forums