June 11, 2014

Removing excessive signals in Amibroker

Very often, when you write a code for trading signals, you get multiple signals. What you are interested is in the first signal and you would like to ignore the subsequent ones.

This AFL will help you achieve this.


Let us assume you have a system where you buy a stock if it closes above 20 days high and short if it closes below 20 days low

The initial AFL (scanner mode) is:

Buy=Cross(C,Ref(HHV(H,20),-1)); 

Sell=Cross(Ref(LLV(L,20),-1),C);

The above code will generate multiple buy / sell signals for the same stock.

Since you want to remove the excessive signals, use the ExRem function:

Buy=ExRem(Buy,Sell); 

Sell=ExRem(Sell,Buy); 

Now when you run the script only the first signal will be shown and others will be captured.

The opposite of ExRem is FLIP... this is rarely used.

Chart: Following chart shows mutliple arrows pointing in same direction. The code will capture the first signal / arrow and ignore the rest.


After using the ExRem function, the chart looks like this.


Now we have only the first arrow or signal being shown.

Hope this helps.

No comments:

Post a Comment