Debugging

 

Anyone got any input on how to debug scripts ?

I have been starting to try to convert some Easy Language code to MQL4 and am still trying to understand how the plotting of indicator values works.

This snippet below is from an indicator I found on this board, but when I apply it my system locks up. From someone used to coding in Visual Studio, how do you overcome the inability to step through your code to check values etc. In another indicator I wrote I was able to compile it but when I applied it all I got was divide by zero errors. When I added lots of if(var > 0) type stuff it also locked up. So question 2 would be how do you recover your setup if an indicator has been applied that locks the system up. i.e. is there some config file somewhere that tells the system what indicators to apply at startup that can be hacked to remove duff indicators.

Thanks.

Paz

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

int counted_bars=IndicatorCounted();

//----

i=Bars-counted_bars-1;

while(i>=0)

{

double high =High;

double low =Low;

double open =Open;

double close=Close;

ExtMapBuffer1=(close-low)-(high-close);

level = close;

}

//----

return(0);

}

edited cos I carn't spell

 

You're stuck in a the while loop because you never change the value of i. See the line in red below.

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

int counted_bars=IndicatorCounted();

//----

i=Bars-counted_bars-1;

while(i>=0)

{

double high =High;

double low =Low;

double open =Open;

double close=Close;

ExtMapBuffer1=(close-low)-(high-close);

level = close;

i--;

}

//----

return(0);

}

 

Unfortunately, the only thing we have at our disposal is the good ol' Print() function. I normally put an

extern bool Debugging = true;

and then before each print statement do:

if (Debugging) Print ("MyVar="+MyVar);

because every time I take them out, I always need the buggers again.

The print statements come out on the Experts tab of the "Terminal" window.

Anyway, I use them all the time to debug crap. Its a big PITA, but it works. The MetaEditor is a big tease. It even lets you set break points, but there is no debugging. Oh well, at least they don't make us write with EMACS or vi.

Cheers,

CS

BTW - you CAN write custom DLL's in VC++. Check out the doc for how....

Q0paz:
Anyone got any input on how to debug scripts ?

I have been starting to try to convert some Easy Language code to MQL4 and am still trying to understand how the plotting of indicator values works.

This snippet below is from an indicator I found on this board, but when I apply it my system locks up. From someone used to coding in Visual Studio, how do you overcome the inability to step through your code to check values etc. In another indicator I wrote I was able to compile it but when I applied it all I got was divide by zero errors. When I added lots of if(var > 0) type stuff it also locked up. So question 2 would be how do you recover your setup if an indicator has been applied that locks the system up. i.e. is there some config file somewhere that tells the system what indicators to apply at startup that can be hacked to remove duff indicators.

Thanks.

Paz

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

int counted_bars=IndicatorCounted();

//----

i=Bars-counted_bars-1;

while(i>=0)

{

double high =High;

double low =Low;

double open =Open;

double close=Close;

ExtMapBuffer1=(close-low)-(high-close);

level = close;

}

//----

return(0);

}

edited cos I carn't spell
 

Thanks very much for the comments.