Going crazy - maybe for the while loop?

Posted By: tomaslolo

Going crazy - maybe for the while loop? - 02/28/18 13:17

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
Posted By: Hredot

Re: Going crazy - maybe for the while loop? - 02/28/18 13:48

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.
Posted By: tomaslolo

Re: Going crazy - maybe for the while loop? - 03/01/18 08:22

Thank you very much for your help.
© 2024 lite-C Forums