October 29, 2014
Using per-symbol parameter values in charts
Parameter values in AmiBroker are stored separately for each ChartID. A ChartID is a number that uniquely identifies chart. This makes it possible that parameters having same name can hold different values when they are used in different charts (different ChartIDs). This also allows to share parameters if two panes use same ChartID. (A detailed explanation can be found here: http://www.amibroker.com/kb/2014/10/06/relationship-between-chart-panes/ )
For this reason, if we want to have separate chart parameters for each symbol, we need to set up separate chart for every symbol. To do so, follow these steps:
- create several new chart windows using File->New->Blank Chart (or choosing New Blank Chart from the menu under + button in MDI tabs area)
- drag Price( all in one) formula or any other indicators onto each of the newly opened windows
- select different active symbol for every chart
- define parameters individually and save the whole layout in the Layouts window
As a result – we have a setup of several chart windows, where we can quickly access given symbol showing chart with its separately stored parameters.
There is also a way to handle the chart parameter values directly from the AFL formula, which would detect the active symbol and set the parameter values accordingly. Here is an example of such implementation using switch statement:
http://www.amibroker.com/guide/keyword/switch.html
To display this chart, open the Formula Editor, enter the following code and then press Apply Indicator button.
// detect the active symbol and store in n variable
n = Name();
// set parameter values based on the symbol name
switch ( n )
{
// values for MSFT symbol
case "MSFT":
MA1periods = 10;
MA2periods = 21;
break;
// values for IBM and NVDA
case "IBM":
case "NVDA":
MA1periods = 30;
MA2periods = 40;
break;
// values for other tickers
default:
MA1periods = 50;
MA2periods = 100;
break;
}
Plot( Close, "C", colorDefault, styleBar );
Plot( MA( Close, MA1periods ) , "MA(" + MA1Periods + ")" , colorRed );
Plot( MA( Close, MA2periods ) , "MA(" + MA2Periods + ")", colorBlue )
This way we can handle all individual parameter values within a single chart pane.
Filed by Tomasz Janeczko at 6:01 pm under Indicators
Comments Off on Using per-symbol parameter values in charts