Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

CCI-RSI MR

A Pine Script v4 strategy built on Highest (high, 5), Lowest (low, 5) and SMA (close, 5). It has 51 order rules and no entry of its own. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 17 settings; defaults include Risk Limit (%) 2.0, Max Drawdown (x ATR) 2.0 and SL Based on Close Price.

Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.

Does CCI-RSI MR repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did CCI-RSI MR do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
Can CCI-RSI MR be converted to Pine Script v5?
Not tested
The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
Does CCI-RSI MR use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does CCI-RSI MR run in Zeal Terminal?
Yes
It compiles in 101 ms and runs 1,000 bars in 140 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • MA
  • Shape
  • Shape
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (17)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$100,000$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
Net profit
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
0.00%
$0.00

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.

Review

What a careful reader of this script would point out, found by checking the source and the backtest.

  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

  • Note

    Uses an argument v6 removed

    when = on line 156, 159. The upgraded version below moves each call inside an if block.

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames highest → ta.highest, lowest → ta.lowest, sma → ta.sma, atr → ta.atr, cci → ta.cci, rsi → ta.rsi, bb → ta.bb, sum → math.sum, crossunder → ta.crossunder, crossover → ta.crossover, abs → math.abs, round → math.round, tostring → str.tostring.
  • 2 strategy calls use the when = argument (line 156, 159). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 3: //@version=4 → //@version=5
  • Line 8: input(type = input.float) → input.float()
  • Line 10: input(type = input.float) → input.float()
  • Line 14: input(type = input.integer) → input.int()
  • Line 15: input(type = input.integer) → input.int()
  • Line 17: input(type = input.float) → input.float()
70 more edits
  • Line 18: input(type = input.float) → input.float()
  • Line 19: input(type = input.float) → input.float()
  • Line 20: input(type = input.float) → input.float()
  • Line 22: input(type = input.bool) → input.bool()
  • Line 23: input(type = input.bool) → input.bool()
  • Line 25: input(type = input.integer) → input.int()
  • Line 26: input(type = input.integer) → input.int()
  • Line 27: input(type = input.integer) → input.int()
  • Line 28: input(type = input.integer) → input.int()
  • Line 29: input(type = input.integer) → input.int()
  • Line 30: input(type = input.integer) → input.int()
  • Line 36: highest → ta.highest
  • Line 37: lowest → ta.lowest
  • Line 38: sma → ta.sma
  • Line 39: atr → ta.atr
  • Line 40: cci → ta.cci
  • Line 41: rsi → ta.rsi
  • Line 42: sma → ta.sma
  • Line 72: bb → ta.bb
  • Line 73: lowest → ta.lowest
  • Line 74: highest → ta.highest
  • Line 76: sum → math.sum
  • Line 76: crossunder → ta.crossunder
  • Line 77: sum → math.sum
  • Line 77: crossunder → ta.crossunder
  • Line 78: sum → math.sum
  • Line 78: crossover → ta.crossover
  • Line 79: sum → math.sum
  • Line 79: crossover → ta.crossover
  • Line 107: abs → math.abs
  • Line 109: abs → math.abs
  • Line 115: abs → math.abs
  • Line 116: abs → math.abs
  • Line 128: round → math.round
  • Line 128: abs → math.abs
  • Line 129: round → math.round
  • Line 140: abs → math.abs
  • Line 156: tostring → str.tostring
  • Line 159: tostring → str.tostring
  • Line 163: abs → math.abs
  • Line 164: abs → math.abs
  • Line 164: tostring → str.tostring
  • Line 176: abs → math.abs
  • Line 177: abs → math.abs
  • Line 177: tostring → str.tostring
  • Line 191: abs → math.abs
  • Line 193: abs → math.abs
  • Line 193: tostring → str.tostring
  • Line 206: abs → math.abs
  • Line 208: abs → math.abs
  • Line 208: tostring → str.tostring
  • Line 223: abs → math.abs
  • Line 224: abs → math.abs
  • Line 224: tostring → str.tostring
  • Line 236: abs → math.abs
  • Line 237: abs → math.abs
  • Line 237: tostring → str.tostring
  • Line 249: abs → math.abs
  • Line 250: tostring → str.tostring
  • Line 254: abs → math.abs
  • Line 254: abs → math.abs
  • Line 255: tostring → str.tostring
  • Line 264: abs → math.abs
  • Line 265: tostring → str.tostring
  • Line 269: abs → math.abs
  • Line 269: abs → math.abs
  • Line 270: tostring → str.tostring
  • Line 283: abs → math.abs
  • Line 294: abs → math.abs
  • Line 311: sma → ta.sma
⋯// © sg1999-//@version=4+//@version=5// >>>>>strategy name⋯// 1. risk per trade as % of initial capital-risk_limit = input(title="Risk Limit (%)", type=input.float, minval=0.1, defval=2.0, step=0.1)+risk_limit = input.float(title="Risk Limit (%)", minval=0.1, defval=2.0, step=0.1)// 2. drawdown-Draw_down = input(title="Max Drawdown (x ATR)", type=input.float, minval=0.5, maxval=10, defval=2.0, step=0.1)+Draw_down = input.float(title="Max Drawdown (x ATR)", minval=0.5, maxval=10, defval=2.0, step=0.1)// 3. type of stop loss to be used⋯// 4. entry signal validity for bollinger strategies-dist_from_signal= input(title="Entry distance from signal", type=input.integer, minval=1, maxval=20, defval=3, step=1)+dist_from_signal= input.int(title="Entry distance from signal", minval=1, maxval=20, defval=3, step=1)-cross_val = input(title="Cross(over/under) validity", type=input.integer, minval=1, maxval=5, defval=3, step=1) // cross(under/over) of either RSI or CCI is valid for 'n' no.of days+cross_val = input.int(title="Cross(over/under) validity", minval=1, maxval=5, defval=3, step=1) // cross(under/over) of either RSI or CCI is valid for 'n' no.of days// 5. multiple exit points-exit_1_pft_pct          = input(title="1st exit when reward is", type=input.float, minval=0.5, maxval=100, defval=1.0, step=0.1)+exit_1_pft_pct          = input.float(title="1st exit when reward is", minval=0.5, maxval=100, defval=1.0, step=0.1)-exit_1_qty_pct          = input(title="1st exit quantity %", type=input.float, minval=1, maxval=100, defval=100, step=5)+exit_1_qty_pct          = input.float(title="1st exit quantity %", minval=1, maxval=100, defval=100, step=5)-exit_2_pft_pct          = input(title="2nd exit when reward is", type=input.float, minval=0.5, maxval=100, defval=1.5, step=0.1)+exit_2_pft_pct          = input.float(title="2nd exit when reward is", minval=0.5, maxval=100, defval=1.5, step=0.1)-sl_trail_pct            = input(title="Trailing SL compared to original SL", type=input.float, minval=0.5, maxval=100, defval=0.5, step=0.5)+sl_trail_pct            = input.float(title="Trailing SL compared to original SL", minval=0.5, maxval=100, defval=0.5, step=0.5)//show signal bool-plotBB = input(title="Show BB", type=input.bool, defval=true)+plotBB = input.bool(title="Show BB", defval=true)-plotSignals  = input(title="Show Signals", type=input.bool, defval=true)+plotSignals  = input.bool(title="Show Signals", defval=true)// 6. date range to be used for backtesting-fromMonth = input(defval = 1,    title = "From Month",      type = input.integer, minval = 1, maxval = 12)+fromMonth = input.int(defval = 1,    title = "From Month", minval = 1, maxval = 12)-fromDay   = input(defval = 1,    title = "From Day",        type = input.integer, minval = 1, maxval = 31)+fromDay   = input.int(defval = 1,    title = "From Day", minval = 1, maxval = 31)-fromYear  = input(defval = 1990, title = "From Year",       type = input.integer, minval = 1970)+fromYear  = input.int(defval = 1990, title = "From Year", minval = 1970)-thruMonth = input(defval = 1,    title = "Thru Month",      type = input.integer, minval = 1, maxval = 12)+thruMonth = input.int(defval = 1,    title = "Thru Month", minval = 1, maxval = 12)-thruDay   = input(defval = 1,    title = "Thru Day",        type = input.integer, minval = 1, maxval = 31)+thruDay   = input.int(defval = 1,    title = "Thru Day", minval = 1, maxval = 31)-thruYear  = input(defval = 2022, title = "Thru Year",       type = input.integer, minval = 1970)+thruYear  = input.int(defval = 2022, title = "Thru Year", minval = 1970)start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start window⋯//input variables -current_high = highest(high, 5)     // swing high (5 period)+current_high = ta.highest(high, 5)     // swing high (5 period)-current_low = lowest(low, 5)        // swing low (5 period)+current_low = ta.lowest(low, 5)        // swing low (5 period)-current_ma = sma(close, 5)          // Simple Moving average (5 period)+current_ma = ta.sma(close, 5)          // Simple Moving average (5 period)-atr_length = atr(20)                // ATR (20 period)  +atr_length = ta.atr(20)                // ATR (20 period)  -CCI = cci(close,20)                 // CCI (20 period)+CCI = ta.cci(close,20)                 // CCI (20 period)-RSI = rsi(close,14)                 // RSI (14 period)+RSI = ta.rsi(close,14)                 // RSI (14 period)-RSI_5 = sma (RSI, 5)                // Simple moving average of RSI (5 period)+RSI_5 = ta.sma (RSI, 5)                // Simple moving average of RSI (5 period)// 1. for current candle⋯// Bollinger bands (2 std)-[mBB0,uBB0,lBB0] = bb(close,20,2)+[mBB0,uBB0,lBB0] = ta.bb(close,20,2)-uBB0_low= lowest(uBB0,3) // lowest among upper BB of past 3 periods+uBB0_low= ta.lowest(uBB0,3) // lowest among upper BB of past 3 periods-lBB0_high= highest(lBB0,3) //highest among upper BB of past 3 periods+lBB0_high= ta.highest(lBB0,3) //highest among upper BB of past 3 periods//RSI and CCI may not necessarily crossunder on the same candle.-t_sell_RSI = sum( crossunder(RSI,RSI_5)? 1 : 0, cross_val) == 1 // checks if crossunder has happened in the last 3 candles (including the current candle)+t_sell_RSI = math.sum( ta.crossunder(RSI,RSI_5)? 1 : 0, cross_val) == 1 // checks if crossunder has happened in the last 3 candles (including the current candle)-t_sell_CCI = sum( crossunder(CCI,100)? 1 : 0, cross_val) == 1 +t_sell_CCI = math.sum( ta.crossunder(CCI,100)? 1 : 0, cross_val) == 1 -t_buy_RSI  = sum( crossover(RSI,RSI_5)? 1 : 0, cross_val) == 1  //checks if crossover has happened in the last 3 candles (including the current candle)+t_buy_RSI  = math.sum( ta.crossover(RSI,RSI_5)? 1 : 0, cross_val) == 1  //checks if crossover has happened in the last 3 candles (including the current candle)-t_buy_CCI  = sum( crossover(CCI,-100) ? 1 : 0, cross_val) == 1+t_buy_CCI  = math.sum( ta.crossover(CCI,-100) ? 1 : 0, cross_val) == 1// CONDITIONS FOR A SELL signal⋯    sl_price            := current_high + syminfo.mintick // (swing high + one tick) is the stop loss-    sl_size             := abs(entry_price - sl_price)+    sl_size             := math.abs(entry_price - sl_price)    candles_on_trade    := 0-    tsl_size            := abs(entry_price - sl_price)*sl_trail_pct // Here sl_trail_pct is the multiple of R which is used to calculate TSL size+    tsl_size            := math.abs(entry_price - sl_price)*sl_trail_pct // Here sl_trail_pct is the multiple of R which is used to calculate TSL sizeif strategy.position_size == 0 and RSI_long ⋯    candles_on_trade    := 0-    sl_size             := abs(entry_price - sl_price)+    sl_size             := math.abs(entry_price - sl_price)-    tsl_size            := abs(entry_price - sl_price)*sl_trail_pct // Here sl_trail_pct is the multiple of R which is used to calculate TSL size+    tsl_size            := math.abs(entry_price - sl_price)*sl_trail_pct // Here sl_trail_pct is the multiple of R which is used to calculate TSL size    ⋯if (long_entry or short_entry) and strategy.position_size == 0 // Based on our risk (R), no.of lots is calculated by considering a risk per trade limit formula-    qty                 := round((strategy.equity) * (risk_limit/100)/(abs(entry_price - sl_price)*syminfo.pointvalue))+    qty                 := math.round((strategy.equity) * (risk_limit/100)/(math.abs(entry_price - sl_price)*syminfo.pointvalue))-    exit_1_qty          := round(qty * (exit_1_qty_pct/100))+    exit_1_qty          := math.round(qty * (exit_1_qty_pct/100))    exit_2_qty          := qty - (exit_1_qty)⋯// trail SL after 1st target is hit-if abs(strategy.position_size) == 0+if math.abs(strategy.position_size) == 0    hold_high   := 0⋯    strategy.cancel("BUY", window())   // add another window condition which considers day time (working hours)-    strategy.order("BUY", strategy.long, qty, comment="BUY @ "+ tostring(entry_price),when=window())+    strategy.order("BUY", strategy.long, qty, comment="BUY @ "+ str.tostring(entry_price),when=window())if short_entry and strategy.position_size == 0    strategy.cancel("SELL", window()) // add another window condition which considers day time (working hours)-    strategy.order("SELL", strategy.short, qty, comment="SELL @ "+ tostring(entry_price),when=window())+    strategy.order("SELL", strategy.short, qty, comment="SELL @ "+ str.tostring(entry_price),when=window())//>>>> exit conditons⋯//exit at tsl-if strategy.position_size > 0 and close < tsl_price  and abs(strategy.position_size)!=qty +if strategy.position_size > 0 and close < tsl_price  and math.abs(strategy.position_size)!=qty -    strategy.order("EXIT at TSL", strategy.short, abs(strategy.position_size),  comment="EXIT TSL @ "+ tostring(close))+    strategy.order("EXIT at TSL", strategy.short, math.abs(strategy.position_size),  comment="EXIT TSL @ "+ str.tostring(close))    RSI_short                := false   ⋯    strategy.cancel("EXIT at SL",true)-if strategy.position_size < 0 and close > tsl_price  and abs(strategy.position_size)!=qty +if strategy.position_size < 0 and close > tsl_price  and math.abs(strategy.position_size)!=qty -    strategy.order("EXIT at TSL", strategy.long, abs(strategy.position_size), comment="EXIT TSL @ "+ tostring(close))+    strategy.order("EXIT at TSL", strategy.long, math.abs(strategy.position_size), comment="EXIT TSL @ "+ str.tostring(close))    RSI_short                := false   ⋯    -if strategy.position_size > 0 and original_sl_type == "Close Price" and close < sl_price and abs(strategy.position_size)==qty+if strategy.position_size > 0 and original_sl_type == "Close Price" and close < sl_price and math.abs(strategy.position_size)==qty    strategy.cancel("EXIT at SL", true)-    strategy.order("EXIT at SL", strategy.short, abs(strategy.position_size),stop= sl_price,  comment="EXIT SL @ "+ tostring(close))+    strategy.order("EXIT at SL", strategy.short, math.abs(strategy.position_size),stop= sl_price,  comment="EXIT SL @ "+ str.tostring(close))    RSI_short                := false   ⋯    -if strategy.position_size < 0 and original_sl_type == "Close Price" and close > sl_price and abs(strategy.position_size)==qty+if strategy.position_size < 0 and original_sl_type == "Close Price" and close > sl_price and math.abs(strategy.position_size)==qty    strategy.cancel("EXIT at SL", true)-    strategy.order("EXIT at SL", strategy.long, abs(strategy.position_size), stop = sl_price, comment="EXIT SL @ "+ tostring(close))+    strategy.order("EXIT at SL", strategy.long, math.abs(strategy.position_size), stop = sl_price, comment="EXIT SL @ "+ str.tostring(close))    RSI_short               := false   ⋯//>>>>>for ltp sl setting-if strategy.position_size > 0 and original_sl_type == "Last Traded Price" and abs(strategy.position_size) ==qty+if strategy.position_size > 0 and original_sl_type == "Last Traded Price" and math.abs(strategy.position_size) ==qty-    strategy.order("EXIT at SL", strategy.short, abs(strategy.position_size),stop= sl_price,  comment="EXIT SL @ "+ tostring(close))+    strategy.order("EXIT at SL", strategy.short, math.abs(strategy.position_size),stop= sl_price,  comment="EXIT SL @ "+ str.tostring(close))    RSI_short              := false   ⋯    -if strategy.position_size < 0 and original_sl_type == "Last Traded Price" and abs(strategy.position_size) ==qty+if strategy.position_size < 0 and original_sl_type == "Last Traded Price" and math.abs(strategy.position_size) ==qty-    strategy.order("EXIT at SL", strategy.long, abs(strategy.position_size), stop = sl_price, comment="EXIT SL @ "+ tostring(close))+    strategy.order("EXIT at SL", strategy.long, math.abs(strategy.position_size), stop = sl_price, comment="EXIT SL @ "+ str.tostring(close))    RSI_short              := false   ⋯//>>>>>exit at target-if strategy.position_size > 0 and abs(strategy.position_size) == qty and not tsl_hit_flag+if strategy.position_size > 0 and math.abs(strategy.position_size) == qty and not tsl_hit_flag-    strategy.order("EXIT 1", strategy.short, exit_1_qty, limit=exit_1_price, comment="EXIT TG1 @ "+ tostring(exit_1_price))+    strategy.order("EXIT 1", strategy.short, exit_1_qty, limit=exit_1_price, comment="EXIT TG1 @ "+ str.tostring(exit_1_price))    strategy.cancel("Exit Drawd",true)⋯    cci_buy := false-if strategy.position_size > 0 and abs(strategy.position_size) < qty and abs(strategy.position_size) != qty and not tsl_hit_flag+if strategy.position_size > 0 and math.abs(strategy.position_size) < qty and math.abs(strategy.position_size) != qty and not tsl_hit_flag-    strategy.order("EXIT 2", strategy.short, exit_2_qty, limit=exit_2_price, comment="EXIT TG2 @ "+ tostring(exit_2_price))+    strategy.order("EXIT 2", strategy.short, exit_2_qty, limit=exit_2_price, comment="EXIT TG2 @ "+ str.tostring(exit_2_price))    RSI_short := false   ⋯    strategy.cancel("EXIT at SL", true)-if strategy.position_size < 0 and abs(strategy.position_size) == qty and not tsl_hit_flag+if strategy.position_size < 0 and math.abs(strategy.position_size) == qty and not tsl_hit_flag-    strategy.order("EXIT 1", strategy.long, exit_1_qty, limit=exit_1_price, comment="EXIT TG1 @ "+ tostring(exit_1_price))+    strategy.order("EXIT 1", strategy.long, exit_1_qty, limit=exit_1_price, comment="EXIT TG1 @ "+ str.tostring(exit_1_price))    strategy.cancel("Exit Drawd",true)⋯    cci_sell := false-if strategy.position_size < 0 and abs(strategy.position_size) < qty and abs(strategy.position_size) != qty +if strategy.position_size < 0 and math.abs(strategy.position_size) < qty and math.abs(strategy.position_size) != qty -    strategy.order("EXIT 2", strategy.long, exit_2_qty, limit=exit_2_price, comment="EXIT TG2 @ "+ tostring(exit_2_price))+    strategy.order("EXIT 2", strategy.long, exit_2_qty, limit=exit_2_price, comment="EXIT TG2 @ "+ str.tostring(exit_2_price))    RSI_short := false   ⋯    strategy.cancel("Exit Drawd",true)-    strategy.order("Exit Drawd", strategy.long, abs(strategy.position_size), stop= (entry_price + Draw_down*atr_length)  ,comment="Drawdown exit S")+    strategy.order("Exit Drawd", strategy.long, math.abs(strategy.position_size), stop= (entry_price + Draw_down*atr_length)  ,comment="Drawdown exit S")    RSI_short            := false   ⋯    strategy.cancel("Exit Drawd",true)-    strategy.order("Exit Drawd", strategy.short, abs(strategy.position_size), stop= (entry_price - Draw_down*atr_length)  ,comment="Drawdown exit B")+    strategy.order("Exit Drawd", strategy.short, math.abs(strategy.position_size), stop= (entry_price - Draw_down*atr_length)  ,comment="Drawdown exit B")    RSI_short           := false   ⋯p_lBB = plot(plotBB ? lBB0 : na, color=color.teal, style=plot.style_stepline)-plot(sma(close,5), color=color.blue, title="MA")+plot(ta.sma(close,5), color=color.blue, title="MA")//>>>>plot signals⋯

Clean v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 12: input() → input.string()
  • Line 156: when = window() → if block
  • Line 159: when = window() → if block
⋯// 3. type of stop loss to be used-original_sl_type  = input(title="SL Based on", defval="Close Price", options=["Close Price","Last Traded Price"])+original_sl_type  = input.string(title="SL Based on", defval="Close Price", options=["Close Price","Last Traded Price"])// 4. entry signal validity for bollinger strategies⋯    strategy.cancel("BUY", window())   // add another window condition which considers day time (working hours)-    strategy.order("BUY", strategy.long, qty, comment="BUY @ "+ str.tostring(entry_price),when=window())+    if window()+        strategy.order("BUY", strategy.long, qty, comment="BUY @ "+ str.tostring(entry_price))if short_entry and strategy.position_size == 0    strategy.cancel("SELL", window()) // add another window condition which considers day time (working hours)-    strategy.order("SELL", strategy.short, qty, comment="SELL @ "+ str.tostring(entry_price),when=window())+    if window()+        strategy.order("SELL", strategy.short, qty, comment="SELL @ "+ str.tostring(entry_price))//>>>> exit conditons⋯

Does it run in Pine Script v6?

Not tested

Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © sg1999-//@version=5+//@version=6// >>>>>strategy name⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Risk Limit (%)2.0float · min 0.1 · step 0.1qty
Max Drawdown (x ATR)2.0float · min 0.5 · max 10 · step 0.1order Exit Drawd
SL Based onClose Pricestring · options ["Close Price","Last Traded Price"]cancel EXIT at SL order EXIT at SL cancel EXIT 1 cancel EXIT 2 cancel Exit Drawd cancel EXIT at TSL cancel EXIT at SL order EXIT at SL cancel EXIT 1 cancel EXIT 2 cancel Exit Drawd cancel EXIT at TSL order EXIT at SL cancel EXIT 1 cancel EXIT 2 cancel Exit Drawd cancel EXIT at TSL order EXIT at SL cancel EXIT 1 cancel EXIT 2 cancel Exit Drawd cancel EXIT at TSL cancel Exit Drawd order Exit Drawd cancel Exit Drawd order Exit Drawd line 191 line 206 line 223 line 236 line 281 line 292
Entry distance from signal3int (written input.integer) · min 1 · max 20 · step 1line 88 line 97
Cross(over/under) validity3int (written input.integer) · min 1 · max 5 · step 1t_sell_RSI t_sell_CCI t_buy_RSI t_buy_CCI
1st exit when reward is1.0float · min 0.5 · max 100 · step 0.1exit_1_price
1st exit quantity %100float · min 1 · max 100 · step 5exit_1_qty
2nd exit when reward is1.5float · min 0.5 · max 100 · step 0.1exit_2_price
Trailing SL compared to original SL0.5float · min 0.5 · max 100 · step 0.5tsl_size
Show BBtrueboolp_mBB p_uBB p_lBB plot
Show Signalstrueboolplotshape
From Month1int (written input.integer) · min 1 · max 12start
From Day1int (written input.integer) · min 1 · max 31start
From Year1990int (written input.integer) · min 1970start
Thru Month1int (written input.integer) · min 1 · max 12finish
Thru Day1int (written input.integer) · min 1 · max 31finish
Thru Year2022int (written input.integer) · min 1970finish

What it calculates

  • Highest (highest, ta.highest in v5)high, 5current_high · line 36
  • Lowest (lowest, ta.lowest in v5)low, 5current_low · line 37
  • SMA (sma, ta.sma in v5)close, 5current_ma · line 38
  • ATR (atr, ta.atr in v5)20atr_length · line 39
  • CCI (cci, ta.cci in v5)close, 20CCI · line 40
  • RSI (rsi, ta.rsi in v5)close, 14RSI · line 41
  • SMA (sma, ta.sma in v5)RSI, 5RSI_5 · line 42
  • BB (bb, ta.bb in v5)close, 20, 2mBB0 · line 72
  • BB (bb, ta.bb in v5)close, 20, 2uBB0 · line 72
  • BB (bb, ta.bb in v5)close, 20, 2lBB0 · line 72
  • Lowest (lowest, ta.lowest in v5)uBB0, 3uBB0_low · line 73
  • Highest (highest, ta.highest in v5)lBB0, 3lBB0_high · line 74
  • Crossunder (crossunder, ta.crossunder in v5)RSI, RSI_5t_sell_RSI · line 76
  • Crossunder (crossunder, ta.crossunder in v5)CCI, 100t_sell_CCI · line 77
  • Crossover (crossover, ta.crossover in v5)RSI, RSI_5t_buy_RSI · line 78
  • Crossover (crossover, ta.crossover in v5)CCI, -100t_buy_CCI · line 79

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

The script has 72 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
cancel BUYlong_entry and strategy.position_size == 0On155
order BUY longwindow()On156
cancel SELLshort_entry and strategy.position_size == 0On158
order SELL shortwindow()On159
order EXIT at TSL shortstrategy.position_size > 0 and close < tsl_price and abs(strategy.position_size)!=qtyOn164
cancel EXIT 1strategy.position_size > 0 and close < tsl_price and abs(strategy.position_size)!=qtyOn172
cancel EXIT 2strategy.position_size > 0 and close < tsl_price and abs(strategy.position_size)!=qtyOn173
cancel Exit Drawdstrategy.position_size > 0 and close < tsl_price and abs(strategy.position_size)!=qtyOn174
cancel EXIT at SLstrategy.position_size > 0 and close < tsl_price and abs(strategy.position_size)!=qtyOn175
order EXIT at TSL longstrategy.position_size < 0 and close > tsl_price and abs(strategy.position_size)!=qtyOn177
cancel EXIT 1strategy.position_size < 0 and close > tsl_price and abs(strategy.position_size)!=qtyOn185
cancel EXIT 2strategy.position_size < 0 and close > tsl_price and abs(strategy.position_size)!=qtyOn186
cancel Exit Drawdstrategy.position_size < 0 and close > tsl_price and abs(strategy.position_size)!=qtyOn187
cancel EXIT at SLstrategy.position_size < 0 and close > tsl_price and abs(strategy.position_size)!=qtyOn188
cancel EXIT at SLstrategy.position_size > 0 and original_sl_type == "Close Price" and close < sl_price and abs(strategy.position_size)==qtyOn192
order EXIT at SL shortstrategy.position_size > 0 and original_sl_type == "Close Price" and close < sl_price and abs(strategy.position_size)==qtyOn193
cancel EXIT 1strategy.position_size > 0 and original_sl_type == "Close Price" and close < sl_price and abs(strategy.position_size)==qtyOn201
cancel EXIT 2strategy.position_size > 0 and original_sl_type == "Close Price" and close < sl_price and abs(strategy.position_size)==qtyOn202
cancel Exit Drawdstrategy.position_size > 0 and original_sl_type == "Close Price" and close < sl_price and abs(strategy.position_size)==qtyOn203
cancel EXIT at TSLstrategy.position_size > 0 and original_sl_type == "Close Price" and close < sl_price and abs(strategy.position_size)==qtyOn204
cancel EXIT at SLstrategy.position_size < 0 and original_sl_type == "Close Price" and close > sl_price and abs(strategy.position_size)==qtyOn207
order EXIT at SL longstrategy.position_size < 0 and original_sl_type == "Close Price" and close > sl_price and abs(strategy.position_size)==qtyOn208
cancel EXIT 1strategy.position_size < 0 and original_sl_type == "Close Price" and close > sl_price and abs(strategy.position_size)==qtyOn216
cancel EXIT 2strategy.position_size < 0 and original_sl_type == "Close Price" and close > sl_price and abs(strategy.position_size)==qtyOn217
cancel Exit Drawdstrategy.position_size < 0 and original_sl_type == "Close Price" and close > sl_price and abs(strategy.position_size)==qtyOn218
cancel EXIT at TSLstrategy.position_size < 0 and original_sl_type == "Close Price" and close > sl_price and abs(strategy.position_size)==qtyOn219
order EXIT at SL shortstrategy.position_size > 0 and original_sl_type == "Last Traded Price" and abs(strategy.position_size) ==qtyOn224
cancel EXIT 1strategy.position_size > 0 and original_sl_type == "Last Traded Price" and abs(strategy.position_size) ==qtyOn231
cancel EXIT 2strategy.position_size > 0 and original_sl_type == "Last Traded Price" and abs(strategy.position_size) ==qtyOn232
cancel Exit Drawdstrategy.position_size > 0 and original_sl_type == "Last Traded Price" and abs(strategy.position_size) ==qtyOn233
cancel EXIT at TSLstrategy.position_size > 0 and original_sl_type == "Last Traded Price" and abs(strategy.position_size) ==qtyOn234
order EXIT at SL longstrategy.position_size < 0 and original_sl_type == "Last Traded Price" and abs(strategy.position_size) ==qtyOn237
cancel EXIT 1strategy.position_size < 0 and original_sl_type == "Last Traded Price" and abs(strategy.position_size) ==qtyOn244
cancel EXIT 2strategy.position_size < 0 and original_sl_type == "Last Traded Price" and abs(strategy.position_size) ==qtyOn245
cancel Exit Drawdstrategy.position_size < 0 and original_sl_type == "Last Traded Price" and abs(strategy.position_size) ==qtyOn246
cancel EXIT at TSLstrategy.position_size < 0 and original_sl_type == "Last Traded Price" and abs(strategy.position_size) ==qtyOn247
order EXIT 1 shortstrategy.position_size > 0 and abs(strategy.position_size) == qty and not tsl_hit_flagOn250
cancel Exit Drawdstrategy.position_size > 0 and abs(strategy.position_size) == qty and not tsl_hit_flagOn251
order EXIT 2 shortstrategy.position_size > 0 and abs(strategy.position_size) < qty and abs(strategy.position_size) != qty and not tsl_hit_flagOn255
cancel Exit Drawdstrategy.position_size > 0 and abs(strategy.position_size) < qty and abs(strategy.position_size) != qty and not tsl_hit_flagOn262
cancel EXIT at SLstrategy.position_size > 0 and abs(strategy.position_size) < qty and abs(strategy.position_size) != qty and not tsl_hit_flagOn263
order EXIT 1 longstrategy.position_size < 0 and abs(strategy.position_size) == qty and not tsl_hit_flagOn265
cancel Exit Drawdstrategy.position_size < 0 and abs(strategy.position_size) == qty and not tsl_hit_flagOn266
order EXIT 2 longstrategy.position_size < 0 and abs(strategy.position_size) < qty and abs(strategy.position_size) != qtyOn270
cancel Exit Drawdstrategy.position_size < 0 and abs(strategy.position_size) < qty and abs(strategy.position_size) != qtyOn277
cancel EXIT at SLstrategy.position_size < 0 and abs(strategy.position_size) < qty and abs(strategy.position_size) != qtyOn278
cancel Exit Drawdstrategy.position_size < 0 and original_sl_type == "Close Price" and not tsl_hit_flagOn282
order Exit Drawd longstrategy.position_size < 0 and original_sl_type == "Close Price" and not tsl_hit_flagOn283
cancel Exit Drawdstrategy.position_size > 0 and original_sl_type == "Close Price" and not tsl_hit_flag and not sl_hit_flagOn293
order Exit Drawd shortstrategy.position_size > 0 and original_sl_type == "Close Price" and not tsl_hit_flag and not sl_hit_flagOn294
cancel_all strategy.position_size == 0 and not (long_entry or short_entry)every barOn306

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

No

No repainting patterns in the source.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Other markets

The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—0.0%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
CCI-RSI MR this page—v4 strategy0.0%00.0%
Double Bollinger Strategy by tweakerIDlowest highest atr rsi bbv4 strategy−29.6%6150.1%
MA Bollinger Bands + RSI by LucasViviensma rsi atr lowest highestv5 strategy−73.9%477.3%
DC Breakout Strategy - This is simplicity at its finest. by Robrecht99sma highest lowest atrv5 strategy+10.8%578.3%
BuyTheDip by Trendoscopesma atr highest bbv4 strategy+4.6%28.3%
Trend Following with Donchian Channels and MACD by Robrecht99highest lowest sma atrv5 strategy−1.0%122.7%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 101 msWith a workaround 1,000 bars in 140 msNot measured
PineTSNo v5 and v6 only—Not measured

The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © sg1999//@version=4// >>>>>strategy namestrategy(title = "CCI-RSI MR", shorttitle = "CCI-RSI MR", overlay = true)// >>>>input variables// 1. risk per trade as % of initial capitalrisk_limit = input(title="Risk Limit (%)", type=input.float, minval=0.1, defval=2.0, step=0.1)// 2. drawdownDraw_down = input(title="Max Drawdown (x ATR)", type=input.float, minval=0.5, maxval=10, defval=2.0, step=0.1)// 3. type of stop loss to be usedoriginal_sl_type  = input(title="SL Based on", defval="Close Price", options=["Close Price","Last Traded Price"])// 4. entry signal validity for bollinger strategiesdist_from_signal= input(title="Entry distance from signal", type=input.integer, minval=1, maxval=20, defval=3, step=1)cross_val = input(title="Cross(over/under) validity", type=input.integer, minval=1, maxval=5, defval=3, step=1) // cross(under/over) of either RSI or CCI is valid for 'n' no.of days// 5. multiple exit pointsexit_1_pft_pct          = input(title="1st exit when reward is", type=input.float, minval=0.5, maxval=100, defval=1.0, step=0.1)exit_1_qty_pct          = input(title="1st exit quantity %", type=input.float, minval=1, maxval=100, defval=100, step=5)exit_2_pft_pct          = input(title="2nd exit when reward is", type=input.float, minval=0.5, maxval=100, defval=1.5, step=0.1)sl_trail_pct            = input(title="Trailing SL compared to original SL", type=input.float, minval=0.5, maxval=100, defval=0.5, step=0.5)//show signal boolplotBB = input(title="Show BB", type=input.bool, defval=true)plotSignals  = input(title="Show Signals", type=input.bool, defval=true)// 6. date range to be used for backtestingfromMonth = input(defval = 1,    title = "From Month",      type = input.integer, minval = 1, maxval = 12)fromDay   = input(defval = 1,    title = "From Day",        type = input.integer, minval = 1, maxval = 31)fromYear  = input(defval = 1990, title = "From Year",       type = input.integer, minval = 1970)thruMonth = input(defval = 1,    title = "Thru Month",      type = input.integer, minval = 1, maxval = 12)thruDay   = input(defval = 1,    title = "Thru Day",        type = input.integer, minval = 1, maxval = 31)thruYear  = input(defval = 2022, title = "Thru Year",       type = input.integer, minval = 1970)start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start windowfinish    = timestamp(thruYear, thruMonth, thruDay, 23, 59)        // backtest finish windowwindow()  => time >= start and time <= finish ? true : false// >>>>>strategy variables//input variables current_high = highest(high, 5)     // swing high (5 period)current_low = lowest(low, 5)        // swing low (5 period)current_ma = sma(close, 5)          // Simple Moving average (5 period)atr_length = atr(20)                // ATR (20 period)  CCI = cci(close,20)                 // CCI (20 period)RSI = rsi(close,14)                 // RSI (14 period)RSI_5 = sma (RSI, 5)                // Simple moving average of RSI (5 period)// 1. for current candlelong_entry              = false short_entry             = falserisk_reward_ok          = falsesl_hit_flag             = falsetsl_hit_flag            = falsesl_cross                = false// 2. across candlesvar RSI_short           = false     //short signal booleanvar RSI_long            = false     //long signal booleanvar cci_sell            = false     //sellsignal crossunder booleanvar cci_buy             = false     //buy signal crossover booleanvar bar_count_long      = 0         // Number of bars after a long signal var bar_count_short     = 0         // Number of bars after a short signalvar candles_on_trade    = 0         var entry_price         = 0.00var sl_price            = 0.00var qty                 = 0var exit_1_qty          = 0var exit_2_qty          = 0var exit_1_price        = 0.0var exit_2_price        = 0.0var hold_high           = 0.0       // variable used to calculate Trailing slvar hold_low            = 0.0       // variable used to calculate Trailing slvar tsl_size            = 0.0       // Trailing Stop loss size(xR)var sl_size             = 0.0       // Stop loss size (R)var tsl_price           = 0.0       //Trailing stoploss price// >>>>>strategy conditions.// Bollinger bands (2 std)[mBB0,uBB0,lBB0] = bb(close,20,2)uBB0_low= lowest(uBB0,3) // lowest among upper BB of past 3 periodslBB0_high= highest(lBB0,3) //highest among upper BB of past 3 periods//RSI and CCI may not necessarily crossunder on the same candle.t_sell_RSI = sum( crossunder(RSI,RSI_5)? 1 : 0, cross_val) == 1 // checks if crossunder has happened in the last 3 candles (including the current candle)t_sell_CCI = sum( crossunder(CCI,100)? 1 : 0, cross_val) == 1 t_buy_RSI  = sum( crossover(RSI,RSI_5)? 1 : 0, cross_val) == 1  //checks if crossover has happened in the last 3 candles (including the current candle)t_buy_CCI  = sum( crossover(CCI,-100) ? 1 : 0, cross_val) == 1// CONDITIONS FOR A SELL signalif t_sell_RSI and t_sell_CCI and (current_high >= uBB0_low)     cci_sell := true    bar_count_short := 0 if  cci_sell and strategy.position_size ==0     bar_count_short := bar_count_short + 1    if  cci_sell and bar_count_short<= dist_from_signal and close <= current_ma  and strategy.position_size ==0    RSI_short := true//conditions for a BUY signalif t_buy_RSI and t_buy_CCI and (current_low <= lBB0_high) // or current_low_close <= lBB01_high)    cci_buy := true    bar_count_long := 0if  cci_buy and strategy.position_size ==0     bar_count_long := bar_count_long + 1    if  cci_buy and  bar_count_long<= dist_from_signal and close >= current_ma and strategy.position_size ==0    RSI_long := trueif RSI_long and RSI_short    RSI_long := false    RSI_short := false// >>>>>entry and target specificationsif strategy.position_size == 0 and RSI_short     short_entry         := true    entry_price         := close    sl_price            := current_high + syminfo.mintick // (swing high + one tick) is the stop loss    sl_size             := abs(entry_price - sl_price)    candles_on_trade    := 0    tsl_size            := abs(entry_price - sl_price)*sl_trail_pct // Here sl_trail_pct is the multiple of R which is used to calculate TSL sizeif strategy.position_size == 0 and RSI_long     long_entry          := true    entry_price         := close    sl_price            := current_low -  syminfo.mintick //(swing low - one tick) is the stop loss    candles_on_trade    := 0    sl_size             := abs(entry_price - sl_price)    tsl_size            := abs(entry_price - sl_price)*sl_trail_pct // Here sl_trail_pct is the multiple of R which is used to calculate TSL size    if long_entry and short_entry    long_entry          := false    short_entry         := false        // >>>>risk evaluation criteria    //>>>>> quantity determination and exit point specifications.    if (long_entry or short_entry) and strategy.position_size == 0 // Based on our risk (R), no.of lots is calculated by considering a risk per trade limit formula    qty                 := round((strategy.equity) * (risk_limit/100)/(abs(entry_price - sl_price)*syminfo.pointvalue))    exit_1_qty          := round(qty * (exit_1_qty_pct/100))    exit_2_qty          := qty - (exit_1_qty)    if long_entry        exit_1_price    := entry_price + (sl_size * exit_1_pft_pct)         exit_2_price    := entry_price + (sl_size * exit_2_pft_pct)    if short_entry        exit_1_price    := entry_price - (sl_size * exit_1_pft_pct)         exit_2_price    := entry_price - (sl_size * exit_2_pft_pct)                // trail SL after 1st target is hitif abs(strategy.position_size) == 0    hold_high   := 0    hold_low    := 0if strategy.position_size > 0 and high > exit_1_price    if high > hold_high or hold_high == 0        hold_high    := high    tsl_price        := hold_high - tsl_size    if strategy.position_size < 0 and low < exit_1_price    if low  < hold_low or hold_low == 0        hold_low     := low    tsl_price        := hold_low + tsl_size    //>>>> entry conditonsif long_entry and strategy.position_size == 0    strategy.cancel("BUY", window())   // add another window condition which considers day time (working hours)    strategy.order("BUY", strategy.long, qty, comment="BUY @ "+ tostring(entry_price),when=window())if short_entry and strategy.position_size == 0    strategy.cancel("SELL", window()) // add another window condition which considers day time (working hours)    strategy.order("SELL", strategy.short, qty, comment="SELL @ "+ tostring(entry_price),when=window())//>>>> exit conditonstsl_hit_flag     := false//exit at tslif strategy.position_size > 0 and close < tsl_price  and abs(strategy.position_size)!=qty     strategy.order("EXIT at TSL", strategy.short, abs(strategy.position_size),  comment="EXIT TSL @ "+ tostring(close))    RSI_short                := false       RSI_long                 := false    bar_count_long            := 0    bar_count_short           := 0    tsl_hit_flag              := true    cci_sell := false    cci_buy := false    strategy.cancel("EXIT 1", true)    strategy.cancel("EXIT 2", true)    strategy.cancel("Exit Drawd",true)    strategy.cancel("EXIT at SL",true)if strategy.position_size < 0 and close > tsl_price  and abs(strategy.position_size)!=qty     strategy.order("EXIT at TSL", strategy.long, abs(strategy.position_size), comment="EXIT TSL @ "+ tostring(close))    RSI_short                := false       RSI_long                 := false    bar_count_long            := 0    bar_count_short           := 0       tsl_hit_flag              := true    cci_sell := false    cci_buy := false    strategy.cancel("EXIT 1", true)    strategy.cancel("EXIT 2", true)    strategy.cancel("Exit Drawd",true)    strategy.cancel("EXIT at SL",true)//>>>>exit at sl    if strategy.position_size > 0 and original_sl_type == "Close Price" and close < sl_price and abs(strategy.position_size)==qty    strategy.cancel("EXIT at SL", true)    strategy.order("EXIT at SL", strategy.short, abs(strategy.position_size),stop= sl_price,  comment="EXIT SL @ "+ tostring(close))    RSI_short                := false       RSI_long                 := false    bar_count_long            := 0    bar_count_short           := 0    cci_buy := false    cci_sell := false    sl_hit_flag               := true    strategy.cancel("EXIT 1", true)    strategy.cancel("EXIT 2", true)    strategy.cancel("Exit Drawd",true)    strategy.cancel("EXIT at TSL",true)    if strategy.position_size < 0 and original_sl_type == "Close Price" and close > sl_price and abs(strategy.position_size)==qty    strategy.cancel("EXIT at SL", true)    strategy.order("EXIT at SL", strategy.long, abs(strategy.position_size), stop = sl_price, comment="EXIT SL @ "+ tostring(close))    RSI_short               := false       RSI_long                := false    bar_count_long           := 0    bar_count_short          := 0       cci_buy := false    cci_sell := false    sl_hit_flag              := true    strategy.cancel("EXIT 1", true)    strategy.cancel("EXIT 2", true)    strategy.cancel("Exit Drawd",true)    strategy.cancel("EXIT at TSL",true)        //>>>>>for ltp sl settingif strategy.position_size > 0 and original_sl_type == "Last Traded Price" and abs(strategy.position_size) ==qty    strategy.order("EXIT at SL", strategy.short, abs(strategy.position_size),stop= sl_price,  comment="EXIT SL @ "+ tostring(close))    RSI_short              := false       RSI_long               := false    bar_count_long          := 0    bar_count_short         := 0    cci_buy := false    cci_sell := false    strategy.cancel("EXIT 1", true)    strategy.cancel("EXIT 2", true)    strategy.cancel("Exit Drawd",true)    strategy.cancel("EXIT at TSL",true)    if strategy.position_size < 0 and original_sl_type == "Last Traded Price" and abs(strategy.position_size) ==qty    strategy.order("EXIT at SL", strategy.long, abs(strategy.position_size), stop = sl_price, comment="EXIT SL @ "+ tostring(close))    RSI_short              := false       RSI_long               := false    bar_count_long          := 0    bar_count_short         := 0       cci_buy := false    cci_sell := false    strategy.cancel("EXIT 1", true)    strategy.cancel("EXIT 2", true)    strategy.cancel("Exit Drawd",true)    strategy.cancel("EXIT at TSL",true)//>>>>>exit at targetif strategy.position_size > 0 and abs(strategy.position_size) == qty and not tsl_hit_flag    strategy.order("EXIT 1", strategy.short, exit_1_qty, limit=exit_1_price, comment="EXIT TG1 @ "+ tostring(exit_1_price))    strategy.cancel("Exit Drawd",true)    cci_sell := false    cci_buy := falseif strategy.position_size > 0 and abs(strategy.position_size) < qty and abs(strategy.position_size) != qty and not tsl_hit_flag    strategy.order("EXIT 2", strategy.short, exit_2_qty, limit=exit_2_price, comment="EXIT TG2 @ "+ tostring(exit_2_price))    RSI_short := false       RSI_long  := false    bar_count_long := 0    bar_count_short := 0    cci_buy := false    cci_sell := false    strategy.cancel("Exit Drawd",true)    strategy.cancel("EXIT at SL", true)if strategy.position_size < 0 and abs(strategy.position_size) == qty and not tsl_hit_flag    strategy.order("EXIT 1", strategy.long, exit_1_qty, limit=exit_1_price, comment="EXIT TG1 @ "+ tostring(exit_1_price))    strategy.cancel("Exit Drawd",true)    cci_buy := false    cci_sell := falseif strategy.position_size < 0 and abs(strategy.position_size) < qty and abs(strategy.position_size) != qty     strategy.order("EXIT 2", strategy.long, exit_2_qty, limit=exit_2_price, comment="EXIT TG2 @ "+ tostring(exit_2_price))    RSI_short := false       RSI_long  := false    bar_count_long := 0    bar_count_short := 0      cci_buy := false    cci_sell := false    strategy.cancel("Exit Drawd",true)    strategy.cancel("EXIT at SL", true)    //>>>>>>drawdown executionif strategy.position_size < 0 and original_sl_type == "Close Price" and not tsl_hit_flag      strategy.cancel("Exit Drawd",true)    strategy.order("Exit Drawd", strategy.long, abs(strategy.position_size), stop= (entry_price + Draw_down*atr_length)  ,comment="Drawdown exit S")    RSI_short            := false       RSI_long             := false    bar_count_long        := 0    bar_count_short       := 0    cci_buy := false    cci_sell := false       if strategy.position_size > 0 and original_sl_type == "Close Price" and not tsl_hit_flag and not sl_hit_flag     strategy.cancel("Exit Drawd",true)    strategy.order("Exit Drawd", strategy.short, abs(strategy.position_size), stop= (entry_price - Draw_down*atr_length)  ,comment="Drawdown exit B")    RSI_short           := false       RSI_long            := false    bar_count_long       := 0    bar_count_short      := 0    cci_buy := false    cci_sell := false    //>>>>to add sl hit sign  if strategy.position_size != 0 and sl_hit_flag //For symbols on chart    sl_cross := true//>>>>>cancel all pending orders if the trade is bookedstrategy.cancel_all(strategy.position_size == 0 and not (long_entry or short_entry))//>>>>plot indicatorsp_mBB = plot(plotBB ? mBB0 : na, color=color.teal)p_uBB = plot(plotBB ? uBB0 : na, color=color.teal, style=plot.style_stepline)p_lBB = plot(plotBB ? lBB0 : na, color=color.teal, style=plot.style_stepline)plot(sma(close,5), color=color.blue, title="MA")//>>>>plot signalsplotshape(plotSignals and RSI_short, style=shape.triangledown, location=location.abovebar, color=color.red)plotshape(plotSignals and RSI_long, style=shape.triangleup, location=location.belowbar, color=color.green)plotshape(sl_cross, text= "Stoploss Hit",size= size.normal,style=shape.xcross , location=location.belowbar, color=color.red)//>>>>plot signal high lowif strategy.position_size != 0    candles_on_trade := candles_on_trade + 1if strategy.position_size != 0 and candles_on_trade == 1    line.new(x1=bar_index[1], y1=high[1], x2=bar_index[0], y2=high[1], color=color.black, width=2)    line.new(x1=bar_index[1], y1=low[1],  x2=bar_index[0], y2=low[1],  color=color.black, width=2)//>>>>end of program