This is a simple program to demonstrate that how to visualize your strategy using Amibroker Ribbon function. The purpose is to visualise how long a buy or sell signal holds. Let take 3EMA/23 EMA crossover strategy in our Example
[wp_ad_camp_5]
Steps Involved in Building the code
1)Plot the EMA3/EMA23
2)Buy or Sell Condtion i.e Buy = 3EMA>21EMA and Sell=3EMA<21EMA
3)Plot Arrows on the chart Green Arrow = Buy Signal and Red Arrow = Sell signal
4)Plot the Ribbon. Green Ribbon indicates the length of the Buy signal and Red indicates the sell signal
Now combining everything in one single AFL code
_SECTION_BEGIN(“Price”);
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat(“{{NAME}} – {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}”, O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, “Close”, ParamColor(“Color”, colorBlack ), styleNoTitle | ParamStyle(“Style”) | GetPriceStyle() );/*Buy or Sell Condition*/
Buy = Cross(EMA( Close , 3 ),EMA( Close , 23 ));
Sell = Cross(EMA( Close , 23 ),EMA( Close , 3 ));/*Plot Buy or Sell Arrows*/
PlotShapes(IIf(Sell==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-20);
PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-20);/*Plot EMA*/
Plot( EMA( Close,23), “23 EMA”,ParamColor(“Color”, colorRed ),styleNoRescale);
Plot( EMA( Close,3), “3 EMA”,ParamColor(“Color”, colorBlue ),styleNoRescale);/*Plot Ribbon */
Ribbon1=IIf( EMA( Close , 3 )>EMA( Close , 23 ) ,colorGreen, IIf(EMA( Close , 23 )>EMA( Close , 3 ), colorRed,colorYellow));
Plot(6, “Ribbon”, Ribbon1, styleOwnScale| styleArea| styleNoLabel,-0.5,100);
_SECTION_END();
Download the Amibroker Ribbon AFL code here
In such a way you can visualise any kind of strategy using the ribbons and arrows. Even sometimes multiple ribbon colors are also used to denote multiple actions like buy,sell,sideways movement in one signle band of Ribbon. Amibroker also supports multiple ribbons in one single chart to visualize multiple strategies in one single chart.
Thank you very much!
But what to do, if i add one more EMA – say, EMA 50 and i want the colour of ribbon to be Blue when EMA 3 and EMA 23 is above EMA 50 and colour of ribbon to be Pink when EMA 50 is above EMA 23 but below EMA 3.
Hi RR, as usual another nice presentation by you. Thanks.
I thought of sending an addition to this code for Aman, with more flexibility than he asked. There are 6 combinations here:
3>23>50 blue
3>50>23 pink
23>3>50 green
23>50>3 orange
50>3>23 brown
50>23>3 yellow
The Code is:
_SECTION_BEGIN(“Ribbon”);
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat(“{{Name}} – {{Interval}} {{Date}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}”, O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, “Close”, ParamColor(“Color”, colorBlack ), styleNoTitle | ParamStyle(“Style”) | GetPriceStyle() );
/*Buy or Sell Condition*/
AA=EMA(C,3);
BA=EMA(C,23);
CA=EMA(C,50);
Buy = Cross(AA,BA);
Sell = Cross(BA,AA);
/*Plot Buy or Sell Arrows*/
PlotShapes(IIf(Sell==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-20);
PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-20);
/*Plot EMA*/
Plot( CA, “50 EMA”,colorGreen,styleNoRescale);
Plot( BA, “23 EMA”,colorRed,styleNoRescale);
Plot( AA, “3 EMA”,colorBlue,styleNoRescale);
/*Plot Ribbon */
rc=IIf (AA>BA AND BA>CA, rc=colorBlue,IIf (AA>CA AND CA>BA, colorPink,IIf (BA>AA AND AA>CA, colorGreen,IIf (BA>CA AND CA>AA, colorOrange,IIf (CA>AA AND AA>BA, colorBrown,IIf (CA>BA AND BA>AA, colorYellow,colorWhite))))));
Plot (6,”RIBBON”,RC,styleOwnScale|styleArea|styleNoLabel,-0.5,100);
_SECTION_END();
I wish i should have a like button in the comment coloumn. Thanks Moh!
The only mod being the IIF condition in the choosing color.
bye RR.
Thanks moh 🙂
Hello Rajandran and Moh
I am getting Error 31. Syntax Error, expecting ‘)’ or ‘,’ in Line 1 Column 16.
How to rectify it?
Aman,
The blog formatting has printed the ” in different ascii code.
After copying, replace ALL the ” marks in the file to the ” quote mark on your keyboard, and save. It will work.
HOw to find if the ” code in your file is faulty :
The quote mark should be vertical,
and NOT slanted right or left.
If you try to do this out patiently you will be able to solve similar problems in other codes you get on net.
Hope this helps.
————————————————-
@ RR,
Hi RR, if you can,
kindly do this change and put it as Your Downloadable Text file.
That may solve the problem.
Also, the NAME INTERVAL DATE have to be capitalized for it to work.
Now it [in my comment] shows in Proper which will show data as Empty.
Thanks RR, You are doing a lot for all of us. 🙂
@Moh
Hi Snapshot and AFL code enclosed herewith
@Aman : Download the AFL code from Moh
Also whenever you are copy the afl text from the blog directly and pasting it in the your amibroker… you will notice that the double quotes might be little bit different from the usual one. So when you are doing a copy+paste work then you need to check this out and modify those quotes with the orginal double quotes
Thanks Rajandran. Working perfectly now and understood my mistake too. Thanks!
but this strateji how to measure these harmonic pattern eg rcom daily
sir iam a new user of amibroker.i need help to plot buy,sell,target and stoploss signals how shouild i insert in graph please iam very needful,