Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/19/24 18:45
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (7th_zorro, AndrewAMD, TedMar), 837 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
ZigZag #418229
02/22/13 11:39
02/22/13 11:39
Joined: Nov 2012
Posts: 209
S
SFF Offline OP
Member
SFF  Offline OP
Member
S

Joined: Nov 2012
Posts: 209
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);
     
     }


Last edited by SFF; 02/23/13 00:55.
Re: ZigZag [Re: SFF] #418244
02/22/13 14:33
02/22/13 14:33
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
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.

Re: ZigZag [Re: jcl] #418293
02/23/13 00:58
02/23/13 00:58
Joined: Nov 2012
Posts: 209
S
SFF Offline OP
Member
SFF  Offline OP
Member
S

Joined: Nov 2012
Posts: 209
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?

Re: ZigZag [Re: SFF] #419092
03/06/13 07:57
03/06/13 07:57
Joined: Nov 2012
Posts: 209
S
SFF Offline OP
Member
SFF  Offline OP
Member
S

Joined: Nov 2012
Posts: 209
Hi JCL,

Could you have this code working correctly?

It can be compiled, but the plot looks wrong.

Re: ZigZag [Re: SFF] #419098
03/06/13 09:55
03/06/13 09:55
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
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.

Re: ZigZag [Re: jcl] #419099
03/06/13 10:02
03/06/13 10:02
Joined: Nov 2012
Posts: 209
S
SFF Offline OP
Member
SFF  Offline OP
Member
S

Joined: Nov 2012
Posts: 209
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);
     
     }


Last edited by SFF; 03/06/13 10:04.

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1