Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, 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. Now the recent curiosity on building Trading AI Agents.

Larry Connors RSI Amibroker AFL code

4 min read

Blog updated on 8th July 2025 (refreshed with formula details, backtest code and FAQ in November 2026).

Connors RSI AFL lets you plot Larry Connors’ three-part momentum oscillator in AmiBroker. The formula is CRSI = [RSI(Close, 3) + RSI(Streak, 2) + PercentRank(ROC(1), 100)] / 3, and it swings between 0 and 100 much faster than the standard 14-period RSI, which makes it suited to short-term mean reversion. Below you will find the formula explained, the AFL code, a ready-to-test pullback strategy and the settings Connors recommends.

The Connors RSI (CRSI) is a composite indicator developed by Larry Connors, designed to capture short-term mean reversion opportunities in the market. Unlike the traditional RSI, Connors RSI combines three distinct components to produce a more responsive momentum oscillator that works especially well on short timeframes.

OpenAlgo: one API for 35+ Indian brokers

FREE AND OPEN SOURCE

OpenAlgo: one API for 35+ Indian brokers

Self-hosted algo trading platform. Send orders from Python, AmiBroker, TradingView, Excel or a no-code flow through one consistent API.

  • Unified REST and WebSocket API
  • Works with AmiBroker, TradingView, ChartInk and Excel
  • Sandbox mode to test before going live
Get OpenAlgo →by Marketcalls

What is Connors RSI?

The indicator blends:

  1. Short-Term RSI of closing prices, typically with a length of 3, capturing recent momentum shifts.
  2. RSI of the streak length (up/down days), measures how extended the current trend is by counting consecutive up or down closes.
  3. Percent Rank of the daily change over a certain period, it ranks today’s return among past N days, showing how extreme the move is.

Connors RSI formula

With the default settings recommended by Connors Research (3, 2 and 100), the indicator is:

CRSI = ( RSI(Close, 3) + RSI(UpDownStreak, 2) + PercentRank(ROC(Close, 1), 100) ) / 3
  • RSI(Close, 3): a very short RSI of closing prices.
  • Up/down streak: +1, +2, +3 for consecutive higher closes, -1, -2, -3 for consecutive lower closes, and 0 when the close is unchanged. A 2-period RSI of this streak shows how stretched the run is.
  • PercentRank of ROC(1): the percentage of the last 100 one-day returns that are smaller than today’s return.

Worked example: suppose a stock has closed lower for three straight days (streak = -3), the 3-period RSI reads 12, the streak RSI reads 8 and today’s fall is larger than 95 of the last 100 daily changes, so its PercentRank is 5. CRSI = (12 + 8 + 5) / 3 = 8.3, a deeply oversold reading.

All three values are averaged to give a single CRSI value, generally oscillating between 0 and 100. Overbought/oversold levels like 70/30 are commonly used to identify potential reversal zones.

On the levels: while 70/30 works as a starting point, Connors recommends 90 and 10 as overbought and oversold for CRSI because it moves faster than the traditional RSI, and some chartists use 95 and 5 for very volatile stocks (StockCharts ChartSchool). The AFL plots 70 and 30; change those two Plot() lines if you prefer 90/10.

Why use Connors RSI?

This indicator is particularly popular for short-term traders who rely on quick mean-reversion setups. By factoring in both price momentum and streak behavior, it helps identify when a stock might be overextended and due for a pullback.

Connors RSI vs RSI vs RSI(2)

RSI (14)RSI (2)Connors RSI (3, 2, 100)
InputsClosing price momentumClosing price momentumPrice momentum, streak length and size of today’s move
SpeedSlowVery fastFast, smoother than RSI(2)
Typical levels70 / 3090 / 1090 / 10 (or 95 / 5)
Best useTrend and divergence analysisShort-term pullbacksShort-term mean reversion, 1 to 5 day swings

If you want to compare with the plain 2-period approach on the Indian index, see the 2-period RSI trading systems for Nifty.

AmiBroker AFL Code for Connors RSI

Below is a simple AFL script for plotting Larry Connors’ RSI in AmiBroker. It provides parameters to adjust the lengths of RSI, up-down streak RSI, and PercentRank, allowing you to experiment and optimize for your market.

_SECTION_BEGIN("Connors RSI");

// === Chart Options ===
SetChartOptions(0, chartShowArrows | chartShowDates);

// === Parameters ===
RSILen   = Param("RSI Closes Length", 3, 2, 100, 1);
UDLen    = Param("RSI UpClose Length", 2, 2, 100, 1);
RankLen  = Param("PercentRank Length", 100, 10, 200, 1);

// === Connors RSI Calculation ===
upDays   = BarsSince(C <= Ref(C, -1));
downDays = BarsSince(C >= Ref(C, -1));
upDownDays = IIf(upDays > 0, upDays, IIf(downDays > 0, -downDays, 0));

ConnorsRSI = ( PercentRank(ROC(C, 1), RankLen)
             + RSIa(upDownDays, UDLen)
             + RSI(RSILen) ) / 3;

// === Plot Connors RSI in thick yellow ===
Plot(ConnorsRSI, "Connors RSI", colorYellow, styleLine | styleThick);

// === Plot horizontal dashed lines at 70 and 30 ===
Plot(70, "", colorGrey40, styleDashed);
Plot(30, "", colorGrey40, styleDashed);

_SECTION_END();

Connors RSI AFL pullback strategy for backtesting

The indicator above only plots CRSI. To test the classic pullback idea (buy short-term weakness inside a long-term uptrend), add the block below to the same AFL file and run it from the Analysis window. It buys on the next open when CRSI drops below 10 while price is above its 200-day moving average, and sells on the next open when CRSI rises above 70.

// Connors RSI pullback test (add below the Connors RSI code above)
// Long only: buy oversold dips in an uptrend, exit on the bounce

Buy  = ConnorsRSI < 10 AND C > MA(C, 200);
Sell = ConnorsRSI > 70;
Short = 0;
Cover = 0;

Buy  = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

SetTradeDelays(1, 1, 1, 1);      // act on the next bar
BuyPrice  = Open;
SellPrice = Open;
SetPositionSize(10, spsPercentOfEquity);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorGreen, 0, ConnorsRSI, -12);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone), colorRed, 0, ConnorsRSI, -12);

// Exploration columns
Filter = Buy OR Sell;
AddColumn(C, "Close", 1.2);
AddColumn(ConnorsRSI, "CRSI", 1.2);

This is a starting template, not a tested edge. Run it across a basket such as the Nifty 50 stocks, include brokerage, STT and slippage, and compare the results with and without the 200-day filter. If you are new to the report, the guide to AmiBroker backtesting metrics explains each number.

How to use it?

  • Apply this indicator on your preferred time frame (it’s often used on daily charts for stocks or hourly charts for futures).
  • Look for CRSI values above 70 for potential short setups and below 30 for long opportunities. These levels can be fine-tuned based on your instrument’s volatility.
  • Always confirm signals with price action or other filters like trend direction.

Common mistakes with Connors RSI

  • Using it against the trend. CRSI can stay below 10 for days in a falling market. A trend filter such as the 200-day moving average avoids most of those traps.
  • Keeping the 70/30 levels on daily stocks. CRSI crosses 30 and 70 very often. More extreme levels produce fewer, better signals.
  • Not enough history. The PercentRank part needs 100 bars, so the first 100 bars of a chart give unreliable values.

Frequently Asked Questions

What are the best settings for Connors RSI?

The default 3, 2, 100 settings recommended by Connors Research work well for daily charts. Start there and only change them after backtesting on your own market.

Is Connors RSI better than RSI?

For short-term mean reversion it usually reacts faster and with fewer false extremes than a 14-period RSI. For trend and divergence work, the standard RSI is still the better fit.

What is the Connors RSI 2 strategy?

RSI(2) is Larry Connors’ earlier method: a 2-period RSI of closes with 90/10 levels, usually traded only in the direction of the 200-day moving average. Connors RSI was developed later to reduce its false signals.

Does the Connors RSI AFL work on intraday charts?

Yes, it can be applied to hourly or 15-minute charts, but intraday noise is higher. Use more extreme levels and test with realistic costs.

Final thoughts

The Connors RSI is a handy tool for traders who want a bit more depth than the classic RSI. By blending three perspectives on price action, it often provides earlier and more nuanced overbought/oversold signals. Test it thoroughly on historical data to understand its behavior before applying it live.

More oscillator ideas in AFL: RSI divergence indicator and Internal Bar Strength mean reversion.

Marketcalls Elite Traders Club

MEMBERSHIP

Marketcalls Elite Traders Club

Every Marketcalls course and live mentorship in one membership: 127 courses and 2,500+ hours of learning.

  • Market Profile, Orderflow, AFL, Pine Script and Python
  • Live mentorship and TradEdge trading room
  • Premium tools and the Elite Slack community

Learn by watching: free videos every week

Market Profile, order flow, Python, AI and OpenAlgo tutorials on YouTube.

Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, 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. Now the recent curiosity on building Trading AI Agents.

18 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