How to calculate min Y max Y in a default chart setting?

I would like to know how min Y and max y are calculated in a default chart setting. Any help would be appreciated.

If you mean to retrieve those values, then you can use Status()
https://www.amibroker.com/guide/afl/status.html

minY = Status( "axisminy" );
maxY = Status( "axismaxy" );

How they are internally calculated will obviously be a certain %margin above and below the Highest and Lowest visible values pertaining to the Y-Axis.

1 Like

yes, those function does define the min y and max y but those values are 0 when we use our formula in analysis window , that's why i wanted know how they are calculated , Can you tell me what is the % margin used in default chart ?

@tarscase1,

analysis is not equal to chart. axisminy and axismaxy of chart are chart features. So since analysis does not have any chart in analysis those status codes return zero.
In addition each chart has different chart ID (see GetChartID() function) while analysis' chart ID is always zero too.

So if you want to get miny and maxy of a specific chart's axis then you have to store those two values to static variables (via StaticVarSet()) and then call them in analysis via StaticVarGet(). Note: if you apply static variables storage to multiple chart panes then keep in mind that each one may have different miny and maxy values getting returned. So use GetChartID() within varname argument of static var functions (StaticVarSet()). In StaticVarGet call(s) you then insert the 4-digit chart ID manually to call specific chart pane's values.

Chart code:


/// Chart code

miny = Status( "axisminy" );
maxy = Status( "axismaxy" );

cid = NumToStr(GetChartID(), 1, False);
printf( "Chart ID: " + cid);

uniquename = Name() + "_" + cid;

StaticVarSet( uniquename + "_axisminy", miny);
StaticVarSet( uniquename + "_axismaxy", maxy);

Analysis code:


/// analysis code

// in analysis set to same symbol as the one of chart

// insert chart ID of specific chart pane
// having stored miny and maxy
// (see printf output of chart code to get chart ID)
cid = "1234";

uniquename = Name() + "_" + cid;

miny = StaticVarGet( uniquename + "_axisminy" );
maxy = StaticVarGet( uniquename + "_axismaxy" );

Filter = Status( "lastbarinrange" );
AddColumn( miny, "miny", 1.4 );
AddColumn( maxy, "maxy", 1.4 );

4 Likes