{"id":664,"date":"2014-10-29T18:01:08","date_gmt":"2014-10-29T23:01:08","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/?p=664"},"modified":"2014-12-04T08:29:32","modified_gmt":"2014-12-04T13:29:32","slug":"using-per-symbol-parameter-values-in-charts","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2014\/10\/29\/using-per-symbol-parameter-values-in-charts\/","title":{"rendered":"Using per-symbol parameter values in charts"},"content":{"rendered":"

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\/<\/a> )<\/p>

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:<\/p>

  1. create several new chart windows using File->New->Blank Chart<\/strong> (or choosing New Blank Chart<\/strong> from the menu under +<\/strong> button in MDI tabs area)
    \"New<\/p>
  2. drag Price( all in one)<\/strong> formula or any other indicators onto each of the newly opened windows
    \"Drag-drop<\/p>
  3. select different active symbol for every chart
  4. define parameters individually and save the whole layout in the Layouts<\/strong> window<\/ol>

    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.<\/p>

    \"MDI<\/p>

    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<\/strong> statement:
    http:\/\/www.amibroker.com\/guide\/keyword\/switch.html<\/a><\/p>

    To display this chart, open the Formula Editor<\/strong>, enter the following code and then press Apply Indicator<\/strong> button.<\/p><\/span>\/\/ detect the active symbol and store in n variable
    <\/span>n <\/span>= <\/span>Name<\/span>();

    <\/span>\/\/ set parameter values based on the symbol name
    <\/span>switch ( <\/span>n <\/span>)
    {
    <\/span>\/\/ values for MSFT symbol
    <\/span>case <\/span>"MSFT"<\/span>:
        <\/span>MA1periods <\/span>= <\/span>10<\/span>;
        <\/span>MA2periods <\/span>= <\/span>21<\/span>;
        break;

    <\/span>\/\/ values for IBM and NVDA
    <\/span>case <\/span>"IBM"<\/span>:
    case <\/span>"NVDA"<\/span>:
        <\/span>MA1periods <\/span>= <\/span>30<\/span>;
        <\/span>MA2periods <\/span>= <\/span>40<\/span>;
        break;

    <\/span>\/\/ values for other tickers
    <\/span>default:
        <\/span>MA1periods <\/span>= <\/span>50<\/span>;
        <\/span>MA2periods <\/span>= <\/span>100<\/span>;
        break;
    }

    <\/span>Plot<\/span>( <\/span>Close<\/span>, <\/span>"C"<\/span>, <\/span>colorDefault<\/span>, <\/span>styleBar <\/span>);

    <\/span>Plot<\/span>( <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>MA1periods <\/span>) , <\/span>"MA(" <\/span>+ <\/span>MA1Periods <\/span>+ <\/span>")" <\/span>, <\/span>colorRed <\/span>);
    <\/span>Plot<\/span>( <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>MA2periods <\/span>) , <\/span>"MA(" <\/span>+ <\/span>MA2Periods <\/span>+ <\/span>")"<\/span>, <\/span>colorBlue <\/span>)<\/code>

    This way we can handle all individual parameter values within a single chart pane.<\/p>","protected":false},"excerpt":{"rendered":"

    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 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[53,55,24],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/664"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=664"}],"version-history":[{"count":2,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/664\/revisions"}],"predecessor-version":[{"id":672,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/664\/revisions\/672"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=664"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}