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)

Larry Connors RSI Amibroker AFL code

1 min read

What is Connors RSI?

Connors RSI is a composite indicator consist of 3 components:

1. Price Momentum: By default, ConnorsRSI uses a standard 3 period Wilder RSI for the 1st component.

2. Duration of Up Trend vs. Down Trend streak days. And applies a default 2 day Wilder RSI to this integer series.Connors research shows that the longer the number of consecutive days up or down, the more likely the security is likely to bounce when it reverts to the mean. Likewise, the *magnitude* of the mean reversion snap-back is correlated with the streak length. The 2nd indicator uses integer values to quantify the number of streak days, and applies a default 2 day Wilder RSI to this integer series.

3. Relative Magnitude of Price Change: This 3rd component uses the PercentRank function over a default value of 100 days (approx. 5 months) to measure price change as a percentage of the previous day’s price, and rank the current value over the lookback period. Large positive returns will have a rank closer to 100, large negative returns will have a percent rank closer to 0.

Connors RSI Amibroker AFL
[wp_ad_camp_5]

 
Connors RSI Formula

ConnorsRSI(3,2,100) = [RSI(Close,3) + RSI(Streak,2) + PercentRank(100)] / 3

Connor’s Research purports this robust indicator is more effective than any of the three components use individually, and in fact the blended effect of the mathematical summation allows the strong value from one indicator to compensate for a slightly weaker value from another, in a way yielding superior results than a voting system between the 3.

//Connor's RSI (Larry Connors).  Code for function provided by Connors Research

paramLenRSI = Param("RSI Closes Length", 3, 2, 100, 1);
paramLenUD = Param("RSI UpClose Length", 2, 2, 100, 1);
paramLenRank = Param("PerecentRank Length", 100, 10, 200, 1);

function ConnorsRSI(lenRSI, lenUD, lenROC)
{
      upDays = BarsSince(C <= Ref(C,-1));
      downDays = BarsSince(C >= Ref(C,-1));
      updownDays = IIf(upDays > 0, upDays, IIf(downDays > 0, -downDays, 0));
      crsi = ( PercentRank(ROC(C,1), lenROC) + RSIa(updownDays,lenUD) +RSI(lenRSI))/3;
      return crsi;
}

Plot( ConnorsRSI(paramLenRSI,paramLenUD,paramLenRank)
      , "ConnorsRSI("+paramLenRSI+","+paramLenUD+","+paramLenRank+")"
      , colorBlue, styleLine, 0, 100);

Download the free Ebook about how to trade with Larry Connors RSI – Pullback strategy

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

16 Replies to “Larry Connors RSI Amibroker AFL code”

      1. Sir . it’s 5.3
        Had read in TJ that some function ( percentrank or so) is absent in 5.3 and the member posted solution.
        But since i am newbie,will be kind of u if u can gimme some simple solution.
        thanks

  1. It gives following error.

    Line 12, Col: 27; Error 30: Syntex error
    Line 14, Col: 18; Error 29: Variable ‘crsi’ used without having initialized

    PLease help..

      1. Hi Rajandran,

        I’m using 5.30.4

        yes that is optional, crsi=0;
        In spite of adding it also, I’ve same issue.

        Once I remove “PercentRank(ROC(C,1), lenROC)”, No more issue.
        What is going wrong with it?

        Please share your thoughts and help us.

        Thanks
        Mahender

  2. Hi Rajandran,
    I have seen your supertrend indicator for metasock, I was wondering if you can/ have coded Connors RSI for metastock. Any help will be highly appreciated.
    Regards
    Mahesh

  3. Dear Mr. Rajandran,

    Please guide us how we can add explore code for connorsRSI for stock selection.

    Your help will highly appreciated.

    Regards,
    Chandrakant

  4. Dear Rajandran ,
    Is there any source from where i can get MCX-SX Currency EOD data in metastock form .

    Thanks & Regards
    Abhay Mehrotra

  5. pls correct this afl
    _SECTION_BEGIN(“sell buy”);

    SetChartOptions(1,chartShowArrows|chartShowDates|chartWrapTitle);
    Title = EncodeColor(colorYellow)+ Name() + ” – ” + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorSkyblue) +
    ” – ” + Date() +” – “+”
    ” +EncodeColor(colorYellow) +”Open-“+O+” “+”High-“+H+” “+”Low-“+L+” “+”Close-“+C+” “+ “Volume= “+ WriteVal(V);

    //SetBarsRequired(100000,0);
    GraphXSpace = 15;
    EntrySignal = F1();
    ExitSignal = F2();
    Color = IIf( EntrySignal, colorBlue, IIf( ExitSignal, colorRed, colorGrey50 ));
    Plot( C, “Price”, Color, styleBar | styleThick );

    SetChartBkColor(ParamColor(“Outer panel color “,colorLightYellow));
    SetChartBkColor(ParamColor(“BackGround Color”, colorDarkGrey));
    messageboard =ParamToggle(“Message Board”,”Show|Hide”,1);
    target = Optimize(“Target”,Param(“Target (Change To Optimise)”,10,0.05,1000,0.05),0.05,1000,0.05);
    AutoTarget = ParamToggle(“Auto Target Mode”, “Yes|No”,1);
    AudioAlert = ParamToggle(“Human Voice Alert”, “No|Yes”);
    EmailAlert = ParamToggle(“E-mail Alert”, “No|Yes”);
    AlertOutput = ParamToggle(“Alert Output”, “No|Yes”);
    starttime=Param(“Market Start Time”,091500,000000,235959,1 );
    endtime=Param(“Market End Time”,152500,000000,235959,1 );
    BackTestMode = ParamToggle(“Use Back Tester Settings”, “Yes|No”);
    Param_Margin = Param(“Margin required (used for backtesting only)”, 15,0.001,100,0.001);
    Param_LotSize = Param(“Lot Size (used for backtesting only)”, 50,1,50000,1);
    Param_NoOfLots = Param(“No of lots normally traded (used for backtesting only)”,1,1,10000,1);
    ConstantLot = ParamToggle(“Trade Constant Lot”, “No|Yes”);

    C13=20;
    C14=2.1;
    C15=12;
    Miny = Status(“axisminy”);
    Maxy = Status(“axismaxy”);
    lvb = Status(“lastvisiblebar”);
    fvb = Status(“firstvisiblebar”);
    pxwidth = Status(“pxwidth”);
    pxheight = Status(“pxheight”);

    #include_once “SS_include.afl”

    bars = LastValue( IIf(BarsSincebuy endtime AND NOT Relax)==1) Say(“Exit position in “+Name()+” at current market price “+C);
    if (SelectedValue(bookshort AND NOT Short AND NOT Relax)==1) Say(“Target achieved in short in “+Name()+” at “+tar);
    if (SelectedValue(booklong AND NOT Buy AND NOT Relax)==1) Say(“Target achieved in long in “+Name()+” at “+tar);
    }

    if (EmailAlert==True)
    {
    AlertIf( Buy, “EMAIL”, “Long signal generated on “+FullName(), 1 );
    AlertIf( booklong AND NOT Buy AND NOT Relax, “EMAIL”, “Target achieved in long in “+FullName(), 1 );
    AlertIf( Short, “EMAIL”, “Short signal generated on “+FullName(), 1 );
    AlertIf( bookshort AND NOT Short AND NOT Relax, “EMAIL”, “Target achieved in long in “+FullName(), 1 );
    AlertIf( TimeNum() > endtime AND NOT Relax, “EMAIL”, “Exit position in “+FullName(), 1 );
    }

    if (AlertOutput==True) {
    AlertIf( Buy, “”, “Buy Signal Generated”+Name(), 4 );
    AlertIf( booklong AND NOT Buy AND NOT Relax, “”, “Target achieved in long in “+Name(), 4 );
    AlertIf( Short, “”, “Short Signal Generated”+Name(), 4 );
    AlertIf( bookshort AND NOT Short AND NOT Relax, “”, “Target achieved in short in “+Name(), 4 );
    AlertIf( TimeNum() > endtime AND NOT Relax, “”, “Exit position in “+Name(), 4 );
    }

    if
    (messageboard == 1 )
    {

    GfxSelectFont( “Tahoma”, 13, 100 );

    GfxSetBkMode( 1 );

    GfxSetTextColor
    ( colorWhite );

    if ( SelectedValue( LastSignal ) == 1 )
    {
    GfxSelectSolidBrush( colorDarkBlue );
    }
    else
    {
    GfxSelectSolidBrush( colorDarkRed );
    }

    pxHeight = Status( “pxchartheight” ) ;

    xx = Status( “pxchartwidth”);

    Left = 1100;

    width = 310;

    x = 5;

    x2 = 290;

    y = pxHeight;

    GfxSelectPen
    ( colorLightBlue, 1); // border color

    GfxRoundRect
    ( x, y – 90, x2, y , 7, 7 ) ;

    GfxTextOut
    ( (“For Enquiry: buy sell”),13,y-85);

    GfxTextOut
    ( (“” + WriteIf(Buy, “Go Long At “+C+” – SL ” +sl,””)), 13, y-65);

    GfxTextOut
    ( (“” + WriteIf (Short, “Go Short At “+C+” – SL ” +sl,””)), 13, y-65);

    GfxTextOut
    ( (“” + WriteIf (TimeNum() > endtime AND NOT Relax, “Exit Position At “+C,””)), 13, y-65);

    GfxTextOut
    ( (“” + WriteIf (Long AND NOT Buy, “Long At “+BuyPrice+” – SL ” + sl + “”,””)), 13, y-65);

    GfxTextOut
    ( (“” + WriteIf (shrt AND NOT Short, “Short At “+ShortPrice+” – SL ” + sl + “”,””)), 13, y-65);

    GfxTextOut
    ( (“” + WriteIf (Relax, “Not In Trade – RELAX!!!”,””)), 13, y-65);

    GfxTextOut
    ( (“” + WriteIf (shrt AND NOT Short, “Current P/L: “+(ShortPrice-C)+” Points”,””)), 13, y-45);

    GfxTextOut
    ( (“” + WriteIf (Long AND NOT Buy, “Current P/L: “+(C-BuyPrice)+” Points”,””)), 13, y-45);

    GfxTextOut
    ( (“” + WriteIf (bookshort AND NOT Short AND NOT Relax, “Profit Booked: “+(ShortPrice-tar)+” Points”,””)), 13, y-45);

    GfxTextOut
    ( (“” + WriteIf (booklong AND NOT Buy AND NOT Relax, “Profit Booked: “+(tar-BuyPrice)+” Points”,””)), 13, y-45);

    GfxTextOut
    ( (“” + WriteIf (Long OR Buy OR Shrt OR Short, “Target: “+tar,””)), 13, y-25);

    GfxTextOut
    ( (“” + WriteIf (booklong AND NOT Buy AND NOT Relax, “Target Done: “+tar,””)), 13, y-25);

    GfxTextOut
    ( (“” + WriteIf (bookshort AND NOT Short AND NOT Relax, “Target Done: “+tar,””)), 13, y-25);
    }

    GfxSetBkMode( 1 );
    GfxSelectFont(“Tahoma”, Status(“pxheight”)/C13);
    GfxSetTextAlign( 6 );
    GfxSetTextColor( ColorRGB (217,217,213));
    GfxTextOut( “buy sell”, Status(“pxwidth”)/C14, Status(“pxheight”)/C15 );
    GfxSelectFont(“Tahoma”, Status(“pxheight”)/C13*0.5 );
    GfxSetTextColor( ColorRGB (103,103,103));
    GfxTextOut( “By”, Status(“pxwidth”)/C14, Status(“pxheight”)/C15*2.5 );
    GfxSelectFont(“Tahoma”, Status(“pxheight”)/C13*0.5 );
    GfxSetTextColor( ColorRGB (103,103,103));
    GfxTextOut( “buy sell”, Status(“pxwidth”)/C14, Status(“pxheight”)/C15*4 );
    GfxSelectFont(“MS Sans Serif”, 10, 500, False, False, 0);

    PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-25);
    PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-35);
    PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-30);
    PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=25);
    PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=35);
    PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-30);

    PlotShapes(IIf(TimeNum() > endtime AND Long, shapeHollowStar, shapeNone),colorGold, 0,H, Offset=15);
    PlotShapes(IIf(TimeNum() > endtime AND Shrt, shapeHollowStar, shapeNone),colorGold, 0,L, Offset=-15);

    PlotShapes(IIf(Sell AND NOT Short, shapeStar, shapeNone),colorRed, 0, H, Offset=15);
    PlotShapes(IIf(Cover AND NOT Buy, shapeStar, shapeNone),colorBlue, 0,L, Offset=-15);

    PlotShapes(IIf(booklong AND NOT Buy AND NOT Relax, shapeStar, shapeNone),colorRed, 0, H, Offset=15);
    PlotShapes(IIf(bookshort AND NOT Short AND NOT Relax, shapeStar, shapeNone),colorBlue, 0,L, Offset=-15);

    //Settings for Backtester
    if (BackTestMode==True)
    {
    SetOption(“AllowSameBarExit”, False);
    SetOption(“AllowPositionShrinking”, False);
    SetOption(“FuturesMode”, True);
    SetOption(“InterestRate”,0);
    SetOption(“MaxOpenPositions”,1);
    RoundLotSize = Param_LotSize;
    SetOption(“MinShares”,RoundLotSize);
    SetOption(“PriceBoundChecking”,False);
    //SetOption(“CommissionMode”,3);
    //SetOption(“CommissionAmount”,12.5/RoundLotSize);

    SetOption(“AccountMargin”,Param_Margin);
    SetOption(“ReverseSignalForcesExit”,True);
    SetOption(“UsePrevBarEquityForPosSizing”,True);
    ApplyStop(stopTypeTrailing, stopModePoint, TSL, True, True );

    if (ConstantLot==True)
    {
    PositionSize = C*RoundLotSize*Param_NoOfLots;
    }
    SetTradeDelays(0,0,0,0);
    BuyPrice = Close;
    SellPrice = Close;
    ShortPrice = Close;
    CoverPrice = Close;
    }
    _SECTION_END();

  6. Rajandren Sir, Did u correct Mr.Anil’s request ?
    it showing error in #include_once “SS_include.afl”
    Do we need SS_include.afl indicator ?
    Pls guide me

  7. hello
    i would like to know the above mentioned connors rsi work with esignal or it has to modified ,if so pls modify it , it will be helpfull.
    thanks.

  8. hello sir i am using MT4 demo softwar i want mcx commodity live chat for lowest cost pls help me sir

  9. Have you seen or do you know how to code connorsrsi for Excel?
    -T.M. in Scottsdale

  10. I too would love to have a copy of Connorsrsi for Excel, if anyone has it…
    Thank you
    JWT

Leave a Reply

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