Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, monk12, TipmyPip, Quad, aliswee), 1,029 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Issue with initialization of bool variable #478846
12/31/19 14:10
12/31/19 14:10
Joined: Nov 2016
Posts: 5
M
mey Offline OP
Newbie
mey  Offline OP
Newbie
M

Joined: Nov 2016
Posts: 5
Hello community,

I have a strange behavior of a bool variable, which value remains „true“ despite initialization with “false” for each bar run.
Even “dead certain” comparisons like “if (1 == 2) Cond2 = true;” will be set to “true” in the 14. call of following function.
Also strange: all bool flags show always the same value at the same time in the plot, although this is impossible.

Has somebody an idea why this happens? The instruction “watch("!Cond2",Cond2);” shows that the value changes, but not why.

Thanks so much for every hint!

Code
bool check_long_signal(void)
{
// Variables

	int i;
	bool TmpLongSignal[5] = {false};
	bool LongSignal = false;
	bool QLSMALongsignal = false;	
	
// check conditions

	bool	Cond1 = false;
	bool	Cond2 = false;
	bool	Cond3 = false;
	bool	Cond4 = false;	
	bool	Cond5 = false;	
	bool	Cond6 = false;	
		
	watch("!Cond2",Cond2); 

	counter_checklong = counter_checklong +1;	
	printf("\n counter_checklong:  %d\n", counter_checklong);  	
	
	printf("\n\nCond1 bis Cond6  DIREKT NACH INITIALISIERUNG in check_long_signal: \n");  
	printf("\n LongSignal: "); if (LongSignal == true) printf ("true"); else printf ("false");
	
	printf("\n Cond1: QLSMA 2: "); 
	if (Cond1 == true) 
	{
		printf ("true");
	//	plot("Cond1", Cond1, NEW, GREEN);
	}
	else 
	{
		printf ("false");
	//	plot("Cond1", Cond1, LINE, RED);
	}
	printf("\n Cond2: Keltner: "); if (Cond2 == true) printf ("true"); else printf ("false");	printf("\n Cond3: RMI : "); 	 if (Cond3 == true) printf ("true"); else printf ("false");
	printf("\n Cond4: SAR :  ");   if (Cond4 == true) printf ("true"); else printf ("false");	
	printf("\n Cond5: Stochhastik :  "); if (Cond5 == true) printf ("true"); else printf ("false");
	printf("\n cond6: MACD :  "); if (Cond6 == true) printf ("true"); else printf ("false");	
	printf("\n\n\n");		
	
// conditions

	if (QLSMALongsignal)				Cond1 = true; 
//	if (valley(Keltner_lowerBand1))			Cond2 = true;	
	if (1 == 2)		 			Cond2 = true;	
//	if (valley(myRmi))				Cond3 = true;	
	if (3 == 4)					Cond3 = true;		
 	if (valley(MySAR_02))				Cond4 = true;	
	if (valley(MyStochFastK)) 			Cond5 = true;	
	if (valley(MACDLine))				Cond6 = true;	


if ((Cond1 == true) || (Cond2 == true) || (Cond3 == true) ||  (Cond4 == true) ||  (Cond5 == true) ||  (Cond6 == true)) 
{	
	LongSignal = true;
	printf("\n\n\n Bin in check_long_signal NACH VERGLEICH\n");	
	printf("\n LongSignal in check_long_signal: "); 		 if (LongSignal == true) printf ("true"); else printf ("false");	
	printf("\n Cond1: QLSMA 2: "); if (Cond1 == true) printf ("true"); else printf ("false");
	printf("\n Cond2: Keltner : "); if (Cond2 == true) printf ("true"); else printf ("false");
	printf("\n Cond3: RMI : "); 	 if (Cond3 == true) printf ("true"); else printf ("false");
	printf("\n Cond4: SAR :  ");   if (Cond4 == true) printf ("true"); else printf ("false");	
	printf("\n Cond5: Stochhastik :  "); if (Cond5 == true) printf ("true"); else printf ("false");
	printf("\n cond6: MACD :  "); if (Cond6 == true) printf ("true"); else printf ("false");	
	printf("\n\n\n");		
	
 	plot("Cond1", Cond1, NEW, RED);
	plot("Cond2", Cond2, NEW, RED);		
	plot("Cond3", Cond3, NEW, RED);		
	plot("Cond4", Cond4, NEW, RED);		
	plot("Cond5", Cond5, NEW, RED);		
	plot("Cond6", Cond6, NEW, RED);		
	plot("LongSignal", LongSignal, NEW, BLUE); 
	plot("check_long_signal",Closes,NEW,CYAN);	

	}
	else
	{
		LongSignal = false;
	}
	
	LongSignal = false;
	printf("\n\n LongSignal vor Übergabe: \n\n"); if (LongSignal == true) printf ("true"); else printf ("false");
	return (LongSignal);
	
}



Here us the log:

Log:

Cond1 bis Cond6 DIREKT NACH INITIALISIERUNG in check_long_signal:

LongSignal: false
Cond1: QLSMA 2: false
Cond2: Keltner : false
Cond3: RMI : false
Cond4: SAR : false
Cond5: Stochhastik : false
cond6: MACD : false

Bin in check_long_signal NACH VERGLEICH

LongSignal in check_long_signal: true
Cond1: QLSMA 2: false
Cond2: Keltner : false
Cond3: RMI : false
Cond4: SAR : false
Cond5: Stochhastik : false
cond6: MACD : true

This is how it should work.
But with the 14. call of check long signal, this happens:

[GER30::L] Skipped (outside bars 1503..2008)
Main: Long Trade entered

[1115: Thu 16-03-17 16:05] 9853.50/9861.20\9842.00/9846.20 -1.00
Bin in new trades allowed

New_Trade_ok: true
counter_checklong: 14

Cond1 bis Cond6 DIREKT NACH INITIALISIERUNG in check_long_signal:

LongSignal: true
Cond1: QLSMA 2: true
[color:#FFFF66] Cond2: Keltner: true
Cond3: RMI : true

Cond4: SAR : true
Cond5: Stochhastik : true
cond6: MACD : true[/color]

Bin in check_long_signal NACH VERGLEICH

LongSignal in check_long_signal: true
Cond1: QLSMA 2: true
Cond2: Keltner: true
Cond3: RMI : true
Cond4: SAR : true
Cond5: Stochhastik : true
cond6: MACD : true

LongSignal vor Übergabe:

true


Attached Files Plot_Conditions.JPG
Last edited by mey; 12/31/19 16:25.
Re: Issue with initialization of bool variable [Re: mey] #478859
01/02/20 13:07
01/02/20 13:07
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
I do not see immediately a bug with bool variables in your code, so it might be caused by a particular type of bug in the rest of your script. When it happens after the 14th call, check what your code is doing after 14 bars. If you can't find the bug quickly, comment out parts of your code step by step until the problem disappears. The bug was then in the last removed code part.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1