Debugging a script

Posted By: jcl

Debugging a script - 11/24/12 09:41

Often you want to debug a script and observe how its variables change in every run. We have a lite-C debugger, but it's not yet implemented in Zorro. Until then, you can debug a script with a simple message box. Example:

Code:
function run()
{
	var *Price = series(price());
	var *Trend = series(LowPass(Price,1000));
	Stop = 4*ATR(100);
	
// Display a message box with the variables to be observed
// Click [Yes] for a single step, [No] for closing the box
	static int debug = 1;
	if(debug) debug = msg(
		"Price = %.5f, Trend = %.5f, Stop = %.5f",
		Price[0],
		Trend[0],
		Stop);
	
	
	if(valley(Trend))
		enterLong();
	else if(peak(Trend))
		enterShort();
}

Posted By: Anonymous

Re: Debugging a script - 06/22/13 12:53

Originally Posted By: jcl
Often you want to debug a script and observe how its variables change in every run. We have a lite-C debugger, but it's not yet implemented in Zorro. Until then, you can debug a script with a simple message box. Example:

// Display a message box with the variables to be observed
// Click [Yes] for a single step, [No] for closing the box
static int debug = 1;
if(debug) debug =
msg(
"Price = %.5f, Trend = %.5f, Stop = %.5f",
Price[0],
Trend[0],
Stop);


While we (still) wait for the proper debugger, may I just add that thou shalt not be a smartass (like yours truly) and forget the bolded part above and use unprotected msg() in a loop. Lest you end up with an endless stream of popups that can be stopped only by forcefully pulling the plug from the damn machine. No, you can't just close the Zorro itself and stop the spam, because popups also take the focus away from the main window.

Fortunately, while I was learning the above wisdom on the back of my mouse, I had only about 1300 clicks to freedom... grin
© 2024 lite-C Forums