{"id":36,"date":"2006-09-29T06:55:36","date_gmt":"2006-09-29T11:55:36","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/2006\/09\/29\/how-to-set-individual-trading-rules-for-symbols-in-the-same-backtest\/"},"modified":"2014-12-04T08:23:15","modified_gmt":"2014-12-04T13:23:15","slug":"how-to-set-individual-trading-rules-for-symbols-in-the-same-backtest","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2006\/09\/29\/how-to-set-individual-trading-rules-for-symbols-in-the-same-backtest\/","title":{"rendered":"How to set individual trading rules for symbols in the same backtest"},"content":{"rendered":"
The following code shows how to use separate trading rules for several symbols included in the same backtest. <\/p> Note that different per-symbol stops (ApplyStop) are possible only in regular (non-rotational) backtest.<\/p>","protected":false},"excerpt":{"rendered":" The following code shows how to use separate trading rules for several symbols included in the same backtest.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[53,14,15],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/36"}],"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\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=36"}],"version-history":[{"count":1,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/36\/revisions"}],"predecessor-version":[{"id":825,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/36\/revisions\/825"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=36"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=36"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
<\/span>\/\/ default trading rules if the symbol is not specified below:
<\/span>Buy <\/span>= <\/span>Cross<\/span>( <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>20<\/span>), <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>50<\/span>) );
<\/span>Sell <\/span>= <\/span>Cross<\/span>( <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>50<\/span>), <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>20<\/span>) );
<\/span>\/\/ individual trading rules for selected symbols
\/\/ that will overwrite the above default rules
\/\/ if particular symbol is detected
\/\/ system for MSFT
<\/span>if( <\/span>Name<\/span>() == <\/span>"MSFT" <\/span>)
{
<\/span>Buy <\/span>= <\/span>Cross<\/span>( <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>50<\/span>), <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>100<\/span>) );
<\/span>Sell <\/span>= <\/span>Cross<\/span>( <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>100<\/span>), <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>50<\/span>) );
}
<\/span>\/\/ system for IBM
<\/span>if( <\/span>Name<\/span>() == <\/span>"IBM" <\/span>)
{
<\/span>Buy <\/span>= <\/span>Cross<\/span>( <\/span>MACD<\/span>(), <\/span>Signal<\/span>() );
<\/span>Sell <\/span>= <\/span>Cross<\/span>( <\/span>Signal<\/span>(), <\/span>MACD<\/span>() );
}
<\/span>\/\/ system for NVDA
<\/span>if( <\/span>Name<\/span>() == <\/span>"NVDA" <\/span>)
{
<\/span>Buy <\/span>= <\/span>Cross<\/span>( <\/span>RSI<\/span>(), <\/span>30<\/span>);
<\/span>Sell <\/span>= <\/span>0<\/span>;
<\/span>ApplyStop<\/span>( <\/span>stopTypeNBar<\/span>, <\/span>stopModeBars<\/span>, <\/span>10<\/span>);
<\/code>