Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by M_D. 04/26/24 20:22
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (M_D, AndrewAMD, Quad, Ayumi), 806 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Going crazy - maybe for the while loop? #471336
02/28/18 13:17
02/28/18 13:17
Joined: Feb 2018
Posts: 68
T
tomaslolo Offline OP
Junior Member
tomaslolo  Offline OP
Junior Member
T

Joined: Feb 2018
Posts: 68
Hello, I´m coding a simple strategy, beginner (very) and I get stuck every step I take (no matter I want to learn). I spent 2 hours or more yestrerday with this simple code:

Code:
// MINUTE TRADES TEST //

void run()
{
  vars Open = series(priceOpen());
  vars High = series(priceHigh());
  vars Low = series(priceLow());
  vars Close = series(priceClose());
  BarPeriod = 1;
  LookBack = 5;
  StartDate = 20170601;
  EndDate = 20170831;
  
  int opentime=08; //0800
  int closingtime=23; //2300

  // OPEN LONG CODITIONS AND CLOSE IF SEEMS TO GO BAD
if ((!TradeIsOpen) and (tod(0)>=opentime) and (tod(0)<=closingtime)){
  if (Close[1]<Close[0])
		{	 
		enterLong();
		} }
	 
while(TradeIsLong){
		if ((Close [1]> Close[0])  or (tod(0)>=closingtime))
	  {	 
     exitLong();
	  }}

  // OPEN SHORT CODITIONS AND CLOSE IF SEEMS TO GO BAD	  
if ((!TradeIsOpen) and (tod(0)>=opentime) and (tod(0)<=closingtime)) {
  if (Close[1]>Close[0])
			{	
			enterShort();
			}}
	 
while(TradeIsShort){
	if ((Close[1]<Close[0]) or (tod(0)>=closingtime))
	  {	 
     exitShort();
	  } }
	  
}




I just wanted to test my skills and I crashed. If I code a simple short term (minutes) strategy like this one, Why does Zorro keep compiling until I get tired and finally have to kill the process?

Is there a problem in MY "while" loop? Maybe I misundestood the "while" condition.

Any help? Thank you.

tomas

Re: Going crazy - maybe for the while loop? [Re: tomaslolo] #471337
02/28/18 13:48
02/28/18 13:48
Joined: Sep 2017
Posts: 235
H
Hredot Offline
Member
Hredot  Offline
Member
H

Joined: Sep 2017
Posts: 235
You want "if" instead of "while" there. The whole run() function normally is repeated every minute with new prices. If you put a while with a condition that is always satisfied, it will get stuck there forever and nothing gets repeated.

Last edited by Hredot; 02/28/18 13:49.
Re: Going crazy - maybe for the while loop? [Re: Hredot] #471362
03/01/18 08:22
03/01/18 08:22
Joined: Feb 2018
Posts: 68
T
tomaslolo Offline OP
Junior Member
tomaslolo  Offline OP
Junior Member
T

Joined: Feb 2018
Posts: 68
Thank you very much for your help.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1