Strategy · Pine Script v5 · On the chart

MKUMARAN RRMS Strategy

by shadowmarketai· code credited to mkumaran

A long and short strategy that finds the lowest low and highest high over a swing lookback of 20 bars.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code105
Settings8inputs
LicenceNone statedfile: MPL-2.0
Last update2 months ago27 Aug 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

105 lines of Pine Script v5 from pine_script/rrms_strategy.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

rrms_strategy.pine
// This Pine Script(TM) code is subject to the terms of the Mozilla Public License 2.0
// (c) mkumaran

//@version=5
strategy("MKUMARAN RRMS Strategy v2.0", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=2)

// === INPUTS ===
capital = input.float(100000, "Capital (Rs)", group="RRMS Settings")
risk_pct = input.float(2.0, "Risk %", minval=0.1, maxval=10.0, group="RRMS Settings") / 100
min_rrr = input.float(3.0, "Min RRR", minval=1.0, group="RRMS Settings")
entry_zone_pct = input.float(2.0, "Entry Zone %", minval=0.1, maxval=10.0, group="RRMS Settings") / 100
sl_buffer_pct = input.float(0.5, "SL Buffer %", minval=0.1, maxval=5.0, group="RRMS Settings") / 100
lookback = input.int(20, "Swing Lookback", minval=5, maxval=100, group="Detection")
enable_short = input.bool(true, "Enable SHORT Signals", group="Direction")

// === WEBHOOK ===
use_webhook = input.bool(true, "Send Webhook Alerts", group="Alerts")

// === SWING DETECTION ===
swing_low = ta.lowest(low, lookback)
swing_high = ta.highest(high, lookback)

ltrp = swing_low
pivot_high = swing_high

// === LONG RRMS CALCULATION ===
risk_amt = capital * risk_pct
long_entry_trigger = close <= ltrp * (1 + entry_zone_pct)
long_sl = ltrp * (1 - sl_buffer_pct)
long_risk = close - long_sl
long_reward = pivot_high - close
long_rrr = long_risk > 0 ? long_reward / long_risk : 0
long_qty = long_risk > 0 ? math.floor(risk_amt / long_risk) : 0

// === SHORT RRMS CALCULATION ===
short_entry_trigger = close >= pivot_high * (1 - entry_zone_pct)
short_sl = pivot_high * (1 + sl_buffer_pct)
short_risk = short_sl - close
short_reward = close - ltrp
short_rrr = short_risk > 0 ? short_reward / short_risk : 0
short_qty = short_risk > 0 ? math.floor(risk_amt / short_risk) : 0

// === CONDITIONS ===
long_condition = long_entry_trigger and long_rrr >= min_rrr and long_qty > 0 and close > long_sl
short_condition = enable_short and short_entry_trigger and short_rrr >= min_rrr and short_qty > 0 and close < short_sl

// Prevent duplicate entries
long_signal = long_condition and strategy.position_size == 0
short_signal = short_condition and strategy.position_size == 0

// === EXITS ===
long_target_hit = strategy.position_size > 0 and close >= pivot_high
long_sl_hit = strategy.position_size > 0 and close <= long_sl
short_target_hit = strategy.position_size < 0 and close <= ltrp
short_sl_hit = strategy.position_size < 0 and close >= short_sl

// === STRATEGY EXECUTION ===
if long_signal
    strategy.entry("RRMS Long", strategy.long, qty=long_qty)

if short_signal
    strategy.entry("RRMS Short", strategy.short, qty=short_qty)

if long_target_hit
    strategy.close("RRMS Long", comment="TARGET HIT")

if long_sl_hit
    strategy.close("RRMS Long", comment="STOP LOSS")

if short_target_hit
    strategy.close("RRMS Short", comment="TARGET HIT")

if short_sl_hit
    strategy.close("RRMS Short", comment="STOP LOSS")

// === PLOTS ===
plot(ltrp, "LTRP (Support)", color=color.new(color.blue, 0), linewidth=2, style=plot.style_stepline)
plot(pivot_high, "Pivot High (Resistance)", color=color.new(color.green, 0), linewidth=2, style=plot.style_stepline)
plot(long_sl, "Long SL", color=color.new(color.red, 50), linewidth=1, style=plot.style_stepline)
plot(enable_short ? short_sl : na, "Short SL", color=color.new(color.orange, 50), linewidth=1, style=plot.style_stepline)

// Entry zone highlighting
long_zone_upper = ltrp * (1 + entry_zone_pct)
short_zone_lower = pivot_high * (1 - entry_zone_pct)
bgcolor(close >= ltrp and close <= long_zone_upper ? color.new(color.green, 90) : na, title="Long Entry Zone")
bgcolor(enable_short and close <= pivot_high and close >= short_zone_lower ? color.new(color.red, 90) : na, title="Short Entry Zone")

// === LABELS ===
if long_signal
    label.new(bar_index, low, "BUY\nRRR:" + str.tostring(long_rrr, "#.#") + "\nQty:" + str.tostring(long_qty), style=label.style_label_up, color=color.green, textcolor=color.white, size=size.small)

if short_signal
    label.new(bar_index, high, "SELL\nRRR:" + str.tostring(short_rrr, "#.#") + "\nQty:" + str.tostring(short_qty), style=label.style_label_down, color=color.red, textcolor=color.white, size=size.small)

// === ALERT CONDITIONS ===
alertcondition(long_signal, "RRMS Buy Signal", "RRMS BUY: {{ticker}} @ {{close}}")
alertcondition(short_signal, "RRMS Sell Signal", "RRMS SELL: {{ticker}} @ {{close}}")

// === WEBHOOK ALERTS ===
tf = timeframe.period
if long_signal and use_webhook
    alert('{"ticker": "' + syminfo.ticker + '", "direction": "LONG", "entry": ' + str.tostring(close) + ', "sl": ' + str.tostring(long_sl) + ', "target": ' + str.tostring(pivot_high) + ', "rrr": ' + str.tostring(long_rrr, "#.##") + ', "qty": ' + str.tostring(long_qty) + ', "timeframe": "' + tf + '"}', alert.freq_once_per_bar_close)

if short_signal and use_webhook
    alert('{"ticker": "' + syminfo.ticker + '", "direction": "SHORT", "entry": ' + str.tostring(close) + ', "sl": ' + str.tostring(short_sl) + ', "target": ' + str.tostring(ltrp) + ', "rrr": ' + str.tostring(short_rrr, "#.##") + ', "qty": ' + str.tostring(short_qty) + ', "timeframe": "' + tf + '"}', alert.freq_once_per_bar_close)

Overview

MKUMARAN RRMS Strategy enters long near the low or short near the high when the reward-to-risk ratio meets a minimum, sizing each trade from a capital figure and a risk percentage. Positions close when price reaches the opposite swing level or the buffered stop level, checked on bar close. Webhook alerts and shorting can be toggled. It draws on the price chart.

Details

Published by

shadowmarketai on GitHub

Code credit

mkumaran, as written in the script's header

Draws

On the price chart

Markets

Stocks, Indices

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Capital (Rs)float100000capital
Risk %float2.0risk_pct
Min RRRfloat3.0min_rrr
Entry Zone %float2.0entry_zone_pct
SL Buffer %float0.5sl_buffer_pct
Swing Lookbackint20lookback
Enable SHORT Signalsbooltrueenable_short
Send Webhook Alertsbooltrueuse_webhook
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

330 stars

This strategy divides a fixed price range between an upper and a lower limit into equally spaced grid levels and plots them on the price chart. It marks a buy when price crosses down through a grid and a sell when price crosses up through a grid, using either

Strategy v5 Support & resistanceMean reversion Repaints
Updated 2 months ago · None stated GitHub repository of Grid Bot Simulator [Alorse]

3C QFL Mean Reversal

by hasnocool
106 stars

3C QFL Mean Reversal is a strategy based on the Quickfinger Luc (QFL) trading methodology. It identifies breakdown buying opportunities below established price base levels and enters mean-reversion trades. The strategy includes multi-safety order DCA scaling,

Strategy v5 Mean reversionSupport & resistance Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of 3C QFL Mean Reversal

This strategy builds a spot grid between user-set high and low prices and draws it on the price chart. It splits that range into ten levels and places up to five long limit orders at the lower levels, sizing each from current equity. Orders already below price

Strategy v6 Support & resistanceMean reversion Repaints
Updated 6 weeks ago · None stated GitHub repository of Grid Spot Trading Algorithm [The Quant Science]

FairValueGap E003

by ruckard
13 stars

Calculates the distance between the current price and the opposite end of the latest fair value gap, entering trades on the expectation that price will partially fill the gap. It incorporates risk management with customizable stop loss, take profit based on ri

Strategy v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · None stated GitHub repository of FairValueGap E003

Wyckoff Phase

by muammeryldrm42
7 stars

This strategy identifies Wyckoff consolidation ranges directly on the price chart to trade potential spring and upthrust events. It calculates highest highs and lowest lows over a customizable lookback period, filtering setups by average volume spikes and ATR

Strategy v5 SMC / ICT / price actionSupport & resistance
Updated 3 months ago · MIT GitHub repository of Wyckoff Phase

More Support & resistance scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers