Gamestudio Links
Zorro Links
Newest Posts
Z9 getting Error 058
by k_ivan. 04/25/26 19:13
ZorroGPT
by TipmyPip. 04/25/26 16:09
Stooq now requires an API key
by jcl. 04/13/26 09:42
Strange "Alien" Skull created with >Knubber<
by NeoDumont. 04/10/26 18:58
400 free seamless texture pack downl. here !
by NeoDumont. 04/08/26 19:55
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (AndrewAMD), 3,675 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
valino, juergenwue, VladMak, Geir, ondrej
19209 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
if (comparison) #420713
04/01/13 14:27
04/01/13 14:27
Joined: Apr 2013
Posts: 2
J
joetrader Offline OP
Guest
joetrader  Offline OP
Guest
J

Joined: Apr 2013
Posts: 2
Zorro is a great program and looking fordward to getting some good results from it when I understand it better.
When the 'if' comparison is true it executes the command but when the 'if' comparison is false it sets the values to "0".
Example:
if(crossOver(Fast,Slow)) BuyStop = 1.4;
Whhen crossOver occurs BuyStop is set to 1.4 as expected. On the next bar when new data arrives and this 'if' evaluates false the BuyStop is changed to 0. I expected it to stay at 1.4 since this 'if' comparison is false. What changed it and how do I keep the BuyStop value at 1.4 until this logic changes it at the next crossOver.

Re: if (comparison) [Re: joetrader] #420729
04/02/13 06:58
04/02/13 06:58
Joined: Jul 2000
Posts: 28,094
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,094
Frankfurt
In your example, BuyStop just keeps its value when the 'if' condition is not true.

In a programming language, variables do not "change to 0" by themselves. When you define a variable, it gets an initial value. It is normally 0 if you have not defined it otherwise. The variable keeps this value until you explicitly set it to something else. So when you defined your variable just before that 'if' line, it stays 0 of course when the 'if' condition is not true.

Re: if (comparison) [Re: jcl] #420756
04/02/13 16:02
04/02/13 16:02
Joined: Apr 2013
Posts: 2
J
joetrader Offline OP
Guest
joetrader  Offline OP
Guest
J

Joined: Apr 2013
Posts: 2
You put me on the right track. The BuyStop changes to '0' because the variable is reset to '0' every the function is called. I added the word static infront of the var like this:

static var BuyStop;

This fixed the problem of variable resetting to 0. Thanks for the help.

Joe


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1