Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

Visualize your strategy using Amibroker Ribbons

13 sec read

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.

Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

[Live Coding Webinar] Build Your First Trading Bridge for…

In this course, you will be learning to build your own trading bridge using Python. This 60-minute session is perfect for traders, Python enthusiasts,...
Rajandran R
1 min read

[Webinar] Understanding and Mitigating Curve Fitting in System Trading

"Understanding and Mitigating Curve Fitting in System Trading"! This dynamic session aims to equip novice to intermediate traders, quantitative analysts, and financial engineers with...
Rajandran R
1 min read

P-Signal Strategy Long Only Strategy – Amibroker AFL Code

This tutorial provides an overview of the P-Signal reversal strategy, a quantitative trading strategy that utilizes statistical parameters and error functions to generate probabilistic...
Rajandran R
2 min read

12 Replies to “Visualize your strategy using Amibroker Ribbons”

  1. 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.

  2. 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

  3. 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();

  4. Hello Rajandran and Moh

    I am getting Error 31. Syntax Error, expecting ‘)’ or ‘,’ in Line 1 Column 16.
    How to rectify it?

  5. 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. 🙂

  6. @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

  7. 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,

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More