Dear Praveen & Subratabera,
Thanx for providing me with the afl. My apologies for replying so late.
AFL works fine, but when i backtest it, it gives only for longs, whereas shorts should also be there. As per the system when a long is closed, then short is intiated at that very same time.
Is it possible to incorporate that too in AFL.
Thx for all the help and looking forward to an early reply.
Sunil
p.s. How do i add ur message while replying, at the moment i m just copying and pasting
Unread 22nd March 2007, 07:56 AM
bvpraveen bvpraveen is offline
Senior Member
Join Date: May 2006
Location: Bangalore
Posts: 605
bvpraveen is on a distinguished road
Default Re: AmiBroker formula Language
Quote:
Originally Posted by sunilhv0 View Post
...
Basically i m looking for an AFL for crossover of EMA 5 and EMA 13.
...
Hi,
To add to Subratabera's code, the below AFL is the generalized one. You can give any EMA periods to both short and long periods.
You can use it for Explore also in Automatic Analysis.
Code:
_SECTION_BEGIN("EmaCrossoverSystem");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
ShortPeriod = Param("ShortPeriod", 5, 2, 200, 1);
LongPeriod = Param("LongPeriod", 13, 2, 200, 1);
Buy=Cross(EMA(C,ShortPeriod),EMA(C,LongPeriod));
Sell=Cross(EMA(C,LongPeriod),EMA(C,ShortPeriod));
MYcolor = IIf( EMA(C,ShortPeriod) > EMA(C,LongPeriod) AND C>Peak(C,3,1), colorBrightGreen, IIf(EMA(C,LongPeriod) > EMA(C,ShortPeriod) AND C<Peak(C,3,1), colorRed, colorBlue));
PlotOHLC( Open, High, Low, Close, "", Mycolor, styleBar );
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ),0, IIf( Buy, Low, High ) );
Filter=Buy OR Sell;
SetOption("NoDefaultColumns", True );
AddColumn( DateTime(), "Date", formatDateTime );
AddTextColumn( FullName(), "Full name", 77 , colorDefault, IIf( Buy, colorGreen, colorRed ) );
AddColumn( IIf( Buy, 66, 83 ), "Signal", formatChar, colorDefault, bkcolor =IIf (Buy,colorGreen, colorRed ));
_SECTION_END();
Praveen.
Reply With Quote
Thanx for providing me with the afl. My apologies for replying so late.
AFL works fine, but when i backtest it, it gives only for longs, whereas shorts should also be there. As per the system when a long is closed, then short is intiated at that very same time.
Is it possible to incorporate that too in AFL.
Thx for all the help and looking forward to an early reply.
Sunil
p.s. How do i add ur message while replying, at the moment i m just copying and pasting
Unread 22nd March 2007, 07:56 AM
bvpraveen bvpraveen is offline
Senior Member
Join Date: May 2006
Location: Bangalore
Posts: 605
bvpraveen is on a distinguished road
Default Re: AmiBroker formula Language
Quote:
Originally Posted by sunilhv0 View Post
...
Basically i m looking for an AFL for crossover of EMA 5 and EMA 13.
...
Hi,
To add to Subratabera's code, the below AFL is the generalized one. You can give any EMA periods to both short and long periods.
You can use it for Explore also in Automatic Analysis.
Code:
_SECTION_BEGIN("EmaCrossoverSystem");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
ShortPeriod = Param("ShortPeriod", 5, 2, 200, 1);
LongPeriod = Param("LongPeriod", 13, 2, 200, 1);
Buy=Cross(EMA(C,ShortPeriod),EMA(C,LongPeriod));
Sell=Cross(EMA(C,LongPeriod),EMA(C,ShortPeriod));
MYcolor = IIf( EMA(C,ShortPeriod) > EMA(C,LongPeriod) AND C>Peak(C,3,1), colorBrightGreen, IIf(EMA(C,LongPeriod) > EMA(C,ShortPeriod) AND C<Peak(C,3,1), colorRed, colorBlue));
PlotOHLC( Open, High, Low, Close, "", Mycolor, styleBar );
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ),0, IIf( Buy, Low, High ) );
Filter=Buy OR Sell;
SetOption("NoDefaultColumns", True );
AddColumn( DateTime(), "Date", formatDateTime );
AddTextColumn( FullName(), "Full name", 77 , colorDefault, IIf( Buy, colorGreen, colorRed ) );
AddColumn( IIf( Buy, 66, 83 ), "Signal", formatChar, colorDefault, bkcolor =IIf (Buy,colorGreen, colorRed ));
_SECTION_END();
Praveen.
Reply With Quote