_SECTIONS are namespaces for params, was: Paramtoggle not working at some

Hi everyone!
I found something interesting, probably I do something wrong but can you explain please in following script:

_SECTION_BEGIN("Price");
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

Title=StrFormat("%.0f",ParamToggle("switch_","No|Yes", 0));

Switch does not work untill at least:

  1. Change section title from "Price" to anything else.
  2. Comment //Plot(
  3. Comment //_SECTION_BEGIN and //_SECTION_END
  4. Make Title= first row

(press Reset All - chart properties)

Amibroker 6.18.0 (x64)

What "does not work" mean? What exactly do you see on screen? And what do you expect? Please follow this advice: How to ask a good question

1 Like

Hello Tomasz, Sorry for that.
Let me explain in more details.
If you open default chart window and copy-paste my code

_SECTION_BEGIN("Price");
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

Title=StrFormat("%.0f",ParamToggle("switch_","No|Yes", 0));


There will be following output, please see my screenshots with comments:
When you click on No|Yes ParamToggle does not respond to changes:

but is some changes in script it works (press "Reset all" prior):




My Amibroker is 6.18.0 (64-bit) from Oct 16 2016.
I didnt find any limitations in ParamToggle reference.
Can you please help why is that?

This is NOT what I observe. On my end it RESPONDS to changes immediately right after copy-pasting your first code.

On a side note - you don't need to specify styleNoTitle in Plot, because Title assignment will overwrite everything. This flag only makes sense when you are not using Title variable.

What might have happened is that you moved ParamToogle between sections. You need to remember that parameters are PER-SECTION. I.e. the parameter "_switch" in section "A" is TOTALLY different than parameter "_switch" in section "B". They are independent and different. Sections work like namespaces.

_SECTION_BEGIN("A");
Param("my_param", 1, 1, 100 ); 
_SECTION_END();

_SECTION_BEGIN("A");
Param("my_param", 1, 1, 100 );  // THIS IS IDEPENDENT param!
_SECTION_END();

If you move parameters between sections they are treated as NEW ones (in new section) and any NEW parameter gets DEFAULT value (as specified in Param() calls).

You need to carefully read manual, especially "Special functions" part.
https://www.amibroker.com/guide/h_dragdrop.html

to understand SECTIONS. Also keep in mind that _SECTION_BEGIN/END calls are meant to be added automatically by AmiBroker during drag-drop operations and should NOT be written by hand (unless you understand how they work).

Hello Tomasz,
Thank you for your reply! So as I understand the code has to be assigned to some section anyway?

I changed the code that does not work anyway and switch_ appears in section Price though it is outside it (this is the only code of chart window nothing else):

_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), IIf( C > O, ParamColor("Up Color", colorGreen ), ParamColor("Down Color", colorRed ) ), ParamStyle( "Style", styleHistogram | styleThick, maskHistogram  ) );
_SECTION_END();

switch_=ParamToggle("switch_","No|Yes", 0);
_TRACE(StrFormat("%.0f", switch_));

But following code works fine as I put switch to a separate section:

_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), IIf( C > O, ParamColor("Up Color", colorGreen ), ParamColor("Down Color", colorRed ) ), ParamStyle( "Style", styleHistogram | styleThick, maskHistogram  ) );
_SECTION_END();

_SECTION_BEGIN("switch_");
switch_=ParamToggle("switch_2","No|Yes", 0);
_TRACE(StrFormat("%.0f", switch_));
_SECTION_END();

Can I attach a video for more info?

No, if there are no _SECTIONS, then parameter lives in "global" namespace (without section name).

When you manipulate code MANUALLY moving Params out and inside of sections -

you have to press "RESET ALL" button in Parameters window

As I wrote, _SECTIONS are meant to be added automatically by drag-drop operation, not via manual manipulation.

Users in their own formulas should NOT add _SECTIONS at all, unless they read the docs carefully and understand how things work. I wrote: everything is described in great detail in manual. SLOW READING is all that is required. If you manually play with sections you HAVE TO PRESS "RESET ALL" button in Parameters window as it informs AmiBroker to re-read all params from formula instead of relying on cached content.

So please do read the manual. It is not fun to repeat everything over and over again when everything is explained in manual.

1 Like

Hello Tomaz, thank you for your reply!
Can you look ant my video please?
I really understand that users like me ask you same thing for a million times and you have to reply same, but I think something is not ok with ParamToggle depending where it is situated in script.

As I wrote - ParamToggle works ALWAYS for me.

You don't seem to be using "APPLY INDICATOR". Use APPLY INDICATOR.

Use current official version 6.40 instead of some old beta (6.18 is a BETA and OLD BETA for that matter)

Yes! The solution was to press Apply Indicator! After that everything started working in my 6.18 beta as well!
Looks like ApplyIndicator button sets remaining unassigned sections inside script and after that they work fine!
Thanks!

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.