Amibroker System Development

AceX

Active Member
#1
Hi All,

I was developing a trend following system in Amibroker and have come across several mind-numbing errors.

Consider for example, this snippet

Code:
[COLOR="Blue"]TimeFrameSet[/COLOR]([B]inWeekly[/B]);
LongTrend=[COLOR="Blue"]IIf[/COLOR]([COLOR="Blue"]EMA[/COLOR]([B]C[/B],11)>[COLOR="Blue"]EMA[/COLOR]([B]C[/B],22),1,0);
ShortTrend=[COLOR="Blue"]IIf[/COLOR]([COLOR="Blue"]EMA[/COLOR]([B]C[/B],11)<[COLOR="Blue"]EMA[/COLOR]([B]C[/B],22),1,0);
[COLOR="Blue"]TimeFrameRestore[/COLOR]();
Code:
...
code for buy/sell/short/cover
buy is dependent on LongTrend
Short is dependent on ShortTrend
...
Here, this is the basic trend marker. But inspite of bullish markets like 2006,2007, my system is initiating counter trend trades. Where am I going wrong, those days where the trade is taken, I have personally checked out the values, everything is what it should be.

More importantly,
My average trade length is just 1 bar. This is highly worrying.

Do advice.
AceX

P.S: Is it possible to see the raw signal values, after a backtest. That might help.
 
#2
Hi All,

I was developing a trend following system in Amibroker and have come across several mind-numbing errors.

Consider for example, this snippet

Code:
[COLOR="Blue"]TimeFrameSet[/COLOR]([B]inWeekly[/B]);
LongTrend=[COLOR="Blue"]IIf[/COLOR]([COLOR="Blue"]EMA[/COLOR]([B]C[/B],11)>[COLOR="Blue"]EMA[/COLOR]([B]C[/B],22),1,0);
ShortTrend=[COLOR="Blue"]IIf[/COLOR]([COLOR="Blue"]EMA[/COLOR]([B]C[/B],11)<[COLOR="Blue"]EMA[/COLOR]([B]C[/B],22),1,0);
[COLOR="Blue"]TimeFrameRestore[/COLOR]();
Code:
...
code for buy/sell/short/cover
buy is dependent on LongTrend
Short is dependent on ShortTrend
...
Here, this is the basic trend marker. But inspite of bullish markets like 2006,2007, my system is initiating counter trend trades. Where am I going wrong, those days where the trade is taken, I have personally checked out the values, everything is what it should be.

More importantly,
My average trade length is just 1 bar. This is highly worrying.

Do advice.
AceX

P.S: Is it possible to see the raw signal values, after a backtest. That might help.
Hello,

You are seeing only 1 bar trade because you are probably using single equality sign to check for value of ShortTrend and LongTrend. e.g. if your trading system asks you to buy when LongTrend value is 1 and Sell when ShortTrend Value is 1, you should write as :

Buy = LongTrend == 1;
Sell = ShortTrend == 1;

And not as :

Buy = LongTrend=1; //wrong code. You are assigning value 1 to ShortTrend in this code and not checking it.
Sell = ShortTrend=1; //Wrong code. Reason same as above.

Finally, when you backtest the trading system and are presented with results in Automatic Analysis window, you can either double-click on any of the rows to see the buy-sell arrows OR right-click on the chart and select "Show Arrows for Actual Trades" to see the Buy-Sell arrows generated in the chart.

I am enclosing herewith a Sample Trading System based on your information. This Sample Trading System buys when LongTrend is 1 and sells when ShortTrend is 1. Here, I have changed values of ShortTrend and LongTrend to 1000 (instead of 1) for visibility purpose. I have also plotted values of EMAs as well as ShortTrend / LongTrend for viewing. Also, code to directly show the Buy-Sell arrows in your chart (even without backtesting) is added in the end.

Sample snapshot for Nifty from 2004 till date with Buy-Sell signals generated as per the enclosed sample trading system is also enclosed.

I hope this helps.

Best regards,

AmiBroker-India



PS : If you too are plotting values of ShortTrend and LongTrend and trying to figure out what is happening from the chart, pay special attention to colours. You may make a mistake if you assign same colour as that of ShortEMA i.e. EMA(C,11) to ShortTrend and that of LongEMA to LongTrend. This is quite possible due to appearance of same word at the beginning of these variables. i.e. normally if you are plotting LongEMA as red and ShortEMA as blue, you have to plot LongTrend as blue (and not red) and ShortTrend as red. :)
Ignore if this is not what confused you.
 

Attachments

AceX

Active Member
#3
Man... Amibroker... thou rocketh! I have no other words for you. Thank you for taking so much of time and personal effort to answer it. ...

But:(, it didnt work...

I didnt assign any variable in the IIf, I just used their value as a Boolean for Logical Decisions to make Buy Signals or Short Signals.

Apparently, you system works better than mine :) in holding the trades. Wonder whats going wrong.

AceX
 

AceX

Active Member
#4
Hi has anybody noticed different results cropping from scan and backtesting?

I have used an extremely simple EMA crossover barebone strategy. Apparently, scan gives the perfect results but backtesting is just returning one of them?


Why is it so? Has anybody over here faced the same thing?



AceX
 

Similar threads