Boolean array in debugger

Hi

I put an array of boolean values in the watch tab. Strangely all values appear as 0 (false) although some of them are true.

If I do printf some of them print as 1 (true).

I am trying to replicate it with some simpler code and I can't do it yet.

Is this something anybody has noticed? Is this working as expected and I am missing something?

AB 6.27.1 beta, 64bit version.

Here is sample code:

SetBarsRequired(sbrAll,sbrAll);

pr=Param("ZigZag change amount", 0.1, 0.01,100,0.01);

zzHi=Zig(High,pr);
isPeak = (Ref(zzHi,-1) < zzHi) and (zzHi > Ref(zzHi,1) );  // True if the bar is a peak
ispeak[124]=TRUE;
ispeak[125]=39;
printf("--------------ispeak =%g\n",ispeak );
printf("--------------ispeak[127] =%g\n",ispeak[127] );

Plot( zzHi, "zzHi", colorBlue, ParamStyle("Style"), Null, Null, Null, 1);

printf("Barindex() =%g\n",Barindex() );

ispeak[127] is TRUE. printf reports this correctly. However the debug windows says that ispeak[127]=0.

The debug window correctly reports that ispeak[124]=1 and ispeak[125]=39.

p1

p2

There isn't anything strange. But yes, you are missing something.

Obviously your debugger operates on BASE INTERVAL (it is default setting)!

So simply set it to "Use current chart interval".

Also check the DATE/TIMES (column of debugger)! The debugger counts the set bars backwards.

191438

Hi fxshrat

I rushed to change it as you suggested, but it was already set to "Use current chart interval".

So it must be something else.

The date/times are correct. 11-4-14, 19:30.

p4

p3

The "limit barcount to:" is set to 20.000, if this means anything.

Then you are doing something wrong (for whatever reason) or you still don't get it how it works.

Here it works just fine (i.e barcount being more than 15000 bars and debugger limit barcount set to 20000. And debugger set to use current chart interval).

Result is as expected (== matching).
194836

Sorry, but I will not waste more time on this. (Honestly I am already regretting it to have responded to this thread since from experience I should have known better before that it would end up in thread being as long as Chinese Wall again.)

BTW, AmiBroker is professional progamming software. Pay attention to word "professional".

  1. Debugger runs the code indepenently from chart (it is separate).
  2. Debugger runs in "backtest" (actionBacktest) context. Parameters ONLY apply to CHARTS. Parameters in debugger ARE INDEPENDENT (use chartID = 0 - i.e. Analysis)
  3. Debugger may use different number of bars than chart, as chart uses QuickAFL
    http://www.amibroker.com/kb/2014/09/22/do-not-make-assumptions-on-number-of-bars/ and http://www.amibroker.com/kb/2008/07/03/quickafl/

If your formulas:

  • use code that produces different results depending on number of bars, OR
  • use Parameters that are changed for given CHART, but not for Analysis.

you would get different outcome because input data and/or parameters are different. To trace things in formula executing in CHART you should use _TRACE, not printf.

2 Likes

Hi Tomasz

I had already thought about point #3, so have already used this statement:
SetBarsRequired(sbrAll,sbrAll);

About points #1 and #2, is there an article I can read about? I am sorry, I don't understand them.
You mean that when I go through the debugger in step-by-step mode, aren't those steps applied to the chart and output area? In the order I see in execution?

+++++
If your formulas:
use code that produces different results depending on number of bars, OR
use Parameters that are changed for given CHART, but not for Analysis.
+++++
From what I understand I do not do any of the above. Did you notice the opposite in my code?

I'll try _TRACE instead of printf().

My problem is that the isPeak array seems to have different values on the chart and different in the debugger. What method should I use to reliably examine the contents of the ispeak array?

Also, how come fxshrat got correct vales in the debugger running the same code I run ? I think there must be a different in the Amibroker settings or the database.

Yes you do. You have Param() in your code. @fxshrat simply may have different param value (probably default and that why it works for him). You should RESET parameters in chart back to default. As I wrote debugger runs in backtester (Analysis) context, which means that any changes to parameters IN THE CHART do NOT apply in the debugger. This can be easily seen if you add this (at the bottom).

_TRACE("Running with ChartID = %g, Param pr = %g", GetChartID(), pr );

If you run that in chart and in the debugger you will see that debugger runs the code with ChartID=0, and chart with different (NON-ZERO) ID, and this means that parameter changes done in chart DO NOT affect code that run in debugger.
http://www.amibroker.com/kb/2014/10/06/relationship-between-chart-panes/

1 Like

Thank you so much for the 2nd explanation!

I removed the PARAM code, I hardcoded this and it worked as expected:

zzHi=Zig(High,0.1);
isPeak = (Ref(zzHi,-1) < zzHi) and (zzHi > Ref(zzHi,1) );  // True if the bar is a peak

I did try the RESET. For some reason the problem remained. I deleted the debug file (.dbg) and recreated it. Same thing. Only when I hardcoded the 0.1 zig change, it worked.

I will test more with the fishing poles you gave me, as I had similar problems before and I need to comprehend this perfectly. It cost me more than 10 hours up to now.

Yesterday night I was so tired and frustrated when I read your first post, you wrote PARAMETERS, I understood VARIABLES and I thought you were writing in Chinese.

Thanks again.

Hi Tomasz

I keep reseting the PARAMS, but in debug mode it never goes to the default value (set to 0.2). For some reason pr=5 in the debugger. Obviously this value (5) is saved from some other instance. What is happening?

SetBarsRequired(sbrAll,sbrAll);

pr=Param("ZigZag change amount", 0.2, 0.01,100,0.01);

zzHi=Zig(High,pr);
isPeak = (Ref(zzHi,-1) < zzHi) and (zzHi > Ref(zzHi,1) );  // True if the bar is a peak
ispeak[124]=TRUE;
ispeak[125]=39;
printf("--------------ispeak =%g\n",ispeak );
printf("--------------ispeak[127] =%g\n",ispeak[127] );

Plot( zzHi, "zzHi", colorBlue, styleline, Null, Null, Null, 1);

printf("Barindex() =%g\n",Barindex() );

SetChartOptions( 0, chartShowArrows | chartShowDates );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );

_TRACE("Running with ChartID = " + GetChartID() + " Param pr = "+ pr );
printf("printf:Running with ChartID = %g, Param pr = %g", GetChartID(), pr );
x=3;

p

As I wrote - debugger and chart are SEPARATE.
They use separate parameters. Chart is using parameter set in CHART (right click).
Debugger runs in context of backtest (chartID=0) therefore it uses parameter from Analysis. To reset it you would need to go to Analysis window and open parameters from Analysis toolbar and THERE reset.

2 Likes

Thank you very much again for the explanation. Now it is very clear to me.

1 Like