Pine Script v4 · Strategy
All in One Strategy
A Pine Script v4 strategy built on RSI (close, 14), EMA (RSI, 14) and Highest (high, 5). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.18% commission. 42 settings; defaults include Trade Types Long/Short, Stop Loss % 10.0 and Target Profit % 20.0.
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 All in One Strategy repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did All in One Strategy 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 All in One Strategy 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 All in One Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 269, 272.
- Does All in One Strategy run in Zeal Terminal?
- Yes
- It compiles in 52 ms and runs 1,000 bars in 277 ms, in the browser.
BTCUSDT · 1D · default settings
- Oversold
- Overbought
- K
- D
- RSI
- Winning trade
- Losing trade
- Equity
- Buy and hold
- 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, $1,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
6 settings do nothing
“Long/Short for Mixed Market, Long for Bull, Short for Bear”, “These are the RSI Strategy Inputs, RSI Length applies to MACD, set OB and OS to 45 for using Stoch and EMA strategies.”, “These are the MACD strategy variables”, “Price Change Percentage Cross Check Inputs for all Strategies, added logic to avoid early sell. This is different from setting of max loss in risk management.”, “Stochastic Strategy Inputs”, “Show RSI Buy Sell Zones” are declared but never read.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
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 rsi → ta.rsi, round → math.round, tostring → str.tostring, ema → ta.ema, crossunder → ta.crossunder, crossover → ta.crossover, highest → ta.highest, lowest → ta.lowest, stoch → ta.stoch, wma → ta.wma, sma → ta.sma, change → ta.change, vwma → ta.vwma, macd → ta.macd.
v4 → v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 2: //@version=4 → //@version=5
- Line 22: input(type = input.time) → input.time()
- Line 23: input(type = input.time) → input.time()
- Line 34: input(type = input.integer) → input.int()
- Line 36: input(type = input.integer) → input.int()
- Line 57: input(type = input.source) → input.source()
37 more edits
- Line 58: rsi → ta.rsi
- Line 105: round → math.round
- Line 115: round → math.round
- Line 117: tostring → str.tostring
- Line 117: tostring → str.tostring
- Line 124: ema → ta.ema
- Line 125: ema → ta.ema
- Line 126: ema → ta.ema
- Line 127: ema → ta.ema
- Line 128: ema → ta.ema
- Line 130: ema → ta.ema
- Line 135: crossunder → ta.crossunder
- Line 135: crossunder → ta.crossunder
- Line 136: crossover → ta.crossover
- Line 136: crossover → ta.crossover
- Line 137: crossover → ta.crossover
- Line 137: crossover → ta.crossover
- Line 138: crossunder → ta.crossunder
- Line 176: highest → ta.highest
- Line 177: lowest → ta.lowest
- Line 178: stoch → ta.stoch
- Line 180: ema → ta.ema
- Line 181: wma → ta.wma
- Line 182: sma → ta.sma
- Line 183: sma → ta.sma
- Line 184: change → ta.change
- Line 185: change → ta.change
- Line 197: crossover → ta.crossover
- Line 198: crossunder → ta.crossunder
- Line 201: vwma → ta.vwma
- Line 202: vwma → ta.vwma
- Line 223: sma → ta.sma
- Line 224: sma → ta.sma
- Line 225: sma → ta.sma
- Line 234: macd → ta.macd
- Line 245: crossunder → ta.crossunder
- Line 247: crossover → ta.crossover
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-//@version=4+//@version=5// ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗██████╗ ██████╗ ██╗ ██╗ ⋯//Backtest dates with auto finish date of today-start = input(defval = timestamp("22 June 2021 00:00 -0500"), title = "Start Time", type = input.time)+start = input.time(defval = timestamp("22 June 2021 00:00 -0500"), title = "Start Time")-finish = input(defval = timestamp("31 December 2021 00:00 -0600"), title = "End Time", type = input.time)+finish = input.time(defval = timestamp("31 December 2021 00:00 -0600"), title = "End Time")window() => time >= start and time <= finish ? true : false // create function "within window of time"⋯TargetProfit = tp/100-ld = input(2, "Stop Trading After This Many Losing Days", type=input.integer, minval=0, maxval=100, step=1)+ld = input.int(2, "Stop Trading After This Many Losing Days", minval=0, maxval=100, step=1)strategy.risk.max_cons_loss_days(count=ld)-ml = input(10, "Maximum % of Equity Lost to Halt Trading", type=input.integer, minval=1, maxval=100, step=1)+ml = input.int(10, "Maximum % of Equity Lost to Halt Trading", minval=1, maxval=100, step=1)strategy.risk.max_drawdown(value=ml, type=strategy.percent_of_equity)⋯os_lb = input(35, "Oversold Lookback Bars", minval=0, maxval=100)-source = input(title="Source", type=input.source, defval=close)+source = input.source(title="Source", defval=close)-RSI = rsi(source, length)+RSI = ta.rsi(source, length)// Price Movement Inputs⋯ total := total + src[i]- round(total / count)+ math.round(total / count) ⋯ total := total + src[i]- round(total / count)+ math.round(total / count)RSI_low = AvgLow(RSI, os_lb, os_min)-f_print("Recommended RSI Settings:" + "\nOverbought = " + tostring(RSI_high) + "\nOversold = " + tostring(RSI_low))+f_print("Recommended RSI Settings:" + "\nOverbought = " + str.tostring(RSI_high) + "\nOversold = " + str.tostring(RSI_low))// Plot Oversold and Overbought Lines⋯// ------------------ Background Colors based on EMA Indicators ------------------------------------rsi_ema = ema(RSI, length)+rsi_ema = ta.ema(RSI, length)-emaA = ema(rsi_ema, fastLength) +emaA = ta.ema(rsi_ema, fastLength) -emaFast = 2 * emaA - ema(emaA, fastLength)+emaFast = 2 * emaA - ta.ema(emaA, fastLength)-emaB = ema(rsi_ema, slowLength) +emaB = ta.ema(rsi_ema, slowLength) -emaSlow = 2 * emaB - ema(emaB, slowLength) +emaSlow = 2 * emaB - ta.ema(emaB, slowLength) // New Bullish and Bearish Signal Rule logic check-out = ema(RSI, length)+out = ta.ema(RSI, length)// bullish signal rule: ⋯bearishRule =emaFast < emaSlow and out <= out[1]-EMAShortSell = crossunder(rsi_ema, emaFast) and crossunder(rsi_ema, emaSlow) and bearishRule and window()+EMAShortSell = ta.crossunder(rsi_ema, emaFast) and ta.crossunder(rsi_ema, emaSlow) and bearishRule and window()-EMAShortBuy = crossover(rsi_ema, emaFast) and crossover(rsi_ema, emaSlow) and bullishRule and window()+EMAShortBuy = ta.crossover(rsi_ema, emaFast) and ta.crossover(rsi_ema, emaSlow) and bullishRule and window()-EMALongBuy = crossover(rsi_ema, emaSlow) and crossover(rsi_ema, emaFast) and bullishRule and window()+EMALongBuy = ta.crossover(rsi_ema, emaSlow) and ta.crossover(rsi_ema, emaFast) and bullishRule and window()-EMALongSell = crossunder(emaFast, emaSlow) and bearishRule and window()+EMALongSell = ta.crossunder(emaFast, emaSlow) and bearishRule and window()// current trading State⋯// Use highest highs and lowest lows-h_high = highest(high_source ,lkbk)+h_high = ta.highest(high_source ,lkbk)-l_low = lowest(low_source ,lkbk)+l_low = ta.lowest(low_source ,lkbk)-stoch = stoch(close, high_source, low_source, periodK)+stoch = ta.stoch(close, high_source, low_source, periodK)k =- k_mode=="EMA" ? ema(stoch, smoothK) :+ k_mode=="EMA" ? ta.ema(stoch, smoothK) :- k_mode=="WMA" ? wma(stoch, smoothK) :+ k_mode=="WMA" ? ta.wma(stoch, smoothK) :- sma(stoch, smoothK)+ ta.sma(stoch, smoothK)-d = sma(k, periodD)+d = ta.sma(k, periodD)-k_c = change(k)+k_c = ta.change(k)-d_c = change(d)+d_c = ta.change(d)kd = k - d⋯//plot(signalDown ? (kd+100) : na , "Signal Down", color=dcolor, transp=90, style=plot.style_columns, histbase=100)-StochBuy = crossover(k, d) and k_c>0 and d_c>0 and k<RSI and d<RSI and window()+StochBuy = ta.crossover(k, d) and k_c>0 and d_c>0 and k<RSI and d<RSI and window()-StochSell = crossunder(k, d) and k_c<0 and d_c<0 and k<RSI and d<RSI and window()+StochSell = ta.crossunder(k, d) and k_c<0 and d_c<0 and k<RSI and d<RSI and window()// -------------- Add Price Movement to Strategy for better visualization -------------------------// Calculations-h1 = vwma(high, length)+h1 = ta.vwma(high, length)-l1 = vwma(low, length)+l1 = ta.vwma(low, length)hp = h_high[1]⋯connor_os = oversold-ma1 = sma(close,cl1)+ma1 = ta.sma(close,cl1)-ma2 = sma(close, cl2)+ma2 = ta.sma(close, cl2)-ma3 = sma(close, cl3)+ma3 = ta.sma(close, cl3)// Buy Sell Zones using tweaked Connors RSI (RSI values of 80 and 20 for Crypto as well as ma3, ma20, and ma50 are the tweaks)⋯//------------------- MACD Strategy --------------------------------------------------[macdLine, signalLine, _] = macd(close, fastLength, slowLength, length)+[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, length)bartrendcolor = macdLine > signalLine and k > 50 and RSI > 50 ? color.teal : macdLine < signalLine and k < 50 and RSI < 50 ? color.maroon : macdLine < signalLine ? color.yellow : color.gray⋯// Entry Logic-XRSI_OB = crossunder(RSI, overbought) and overall<0 and window()+XRSI_OB = ta.crossunder(RSI, overbought) and overall<0 and window()RSI_OB = RSI>overbought and true_peak and window()-XRSI_OS = crossover(RSI, oversold) and overall>0 and window()+XRSI_OS = ta.crossover(RSI, oversold) and overall>0 and window()RSI_OS = RSI<oversold and true_dip and window()⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 26: input() → input.bool()
- Line 27: input() → input.string()
- Line 30: input() → input.float()
- Line 32: input() → input.float()
- Line 38: input() → input.bool()
- Line 39: input() → input.bool()
31 more edits
- Line 40: input() → input.bool()
- Line 41: input() → input.int()
- Line 42: input() → input.int()
- Line 43: input() → input.int()
- Line 44: input() → input.int()
- Line 45: input() → input.int()
- Line 46: input() → input.int()
- Line 48: input() → input.bool()
- Line 49: input() → input.bool()
- Line 50: input() → input.bool()
- Line 51: input() → input.int()
- Line 52: input() → input.int()
- Line 53: input() → input.int()
- Line 54: input() → input.int()
- Line 55: input() → input.int()
- Line 56: input() → input.int()
- Line 60: input() → input.bool()
- Line 61: input() → input.int()
- Line 63: input() → input.bool()
- Line 64: input() → input.bool()
- Line 65: input() → input.int()
- Line 66: input() → input.int()
- Line 67: input() → input.int()
- Line 68: input() → input.string()
- Line 69: input() → input.source()
- Line 70: input() → input.source()
- Line 72: input() → input.bool()
- Line 73: input() → input.bool()
- Line 74: input() → input.bool()
- Line 75: input() → input.bool()
- Line 76: input() → input.bool()
⋯// Strategy Selection - Long, Short, or Both-stratinfo = input(true, "Long/Short for Mixed Market, Long for Bull, Short for Bear")+stratinfo = input.bool(true, "Long/Short for Mixed Market, Long for Bull, Short for Bear")-strat = input(title="Trade Types", defval="Long/Short", options=["Long Only", "Long/Short", "Short Only"])+strat = input.string(title="Trade Types", defval="Long/Short", options=["Long Only", "Long/Short", "Short Only"])strat_val = strat == "Long Only" ? 1 : strat == "Long/Short" ? 0 : -1// Risk Management Inputs-sl= input(10.0, "Stop Loss %", minval = 0, maxval = 100, step = 0.01)+sl= input.float(10.0, "Stop Loss %", minval = 0, maxval = 100, step = 0.01)stoploss = sl/100-tp = input(20.0, "Target Profit %", minval = 0, maxval = 100, step = 0.01)+tp = input.float(20.0, "Target Profit %", minval = 0, maxval = 100, step = 0.01)TargetProfit = tp/100⋯strategy.risk.max_drawdown(value=ml, type=strategy.percent_of_equity)-useXRSI = input(false, "Use RSI crossing back, select only one strategy")+useXRSI = input.bool(false, "Use RSI crossing back, select only one strategy")-useCRSI = input(false, "Use Tweaked Connors RSI, select only one")+useCRSI = input.bool(false, "Use Tweaked Connors RSI, select only one")-RSIInfo = input(true, "These are the RSI Strategy Inputs, RSI Length applies to MACD, set OB and OS to 45 for using Stoch and EMA strategies.")+RSIInfo = input.bool(true, "These are the RSI Strategy Inputs, RSI Length applies to MACD, set OB and OS to 45 for using Stoch and EMA strategies.")-length = input(14, "RSI Length", minval=1)+length = input.int(14, "RSI Length", minval=1)-overbought= input(62, "Overbought")+overbought= input.int(62, "Overbought")-oversold= input(35, "Oversold")+oversold= input.int(35, "Oversold")-cl1 = input(3, "Connor's MA Length 1", minval=1, step=1)+cl1 = input.int(3, "Connor's MA Length 1", minval=1, step=1)-cl2 = input(20, "Connor's MA Lenght 2", minval=1, step=1)+cl2 = input.int(20, "Connor's MA Lenght 2", minval=1, step=1)-cl3 = input(50, "Connor's MA Lenght 3", minval=1, step=1)+cl3 = input.int(50, "Connor's MA Lenght 3", minval=1, step=1)// MACD and EMA Inputs-useMACD = input(false, "Use MACD Only, select only one strategy")+useMACD = input.bool(false, "Use MACD Only, select only one strategy")-useEMA = input(false, "Use EMA Only, select only one strategy (EMA uses Stochastic inputs too)")+useEMA = input.bool(false, "Use EMA Only, select only one strategy (EMA uses Stochastic inputs too)")-MACDInfo=input(true, "These are the MACD strategy variables")+MACDInfo=input.bool(true, "These are the MACD strategy variables")-fastLength = input(5, minval=1, title="EMA Fast Length")+fastLength = input.int(5, minval=1, title="EMA Fast Length")-slowLength = input(10, minval=1, title="EMA Slow Length")+slowLength = input.int(10, minval=1, title="EMA Slow Length")-ob_min = input(52, "Overbought Lookback Minimum Value", minval=0, maxval=200)+ob_min = input.int(52, "Overbought Lookback Minimum Value", minval=0, maxval=200)-ob_lb = input(25, "Overbought Lookback Bars", minval=0, maxval=100)+ob_lb = input.int(25, "Overbought Lookback Bars", minval=0, maxval=100)-os_min = input(50, "Oversold Lookback Minimum Value", minval=0, maxval=200)+os_min = input.int(50, "Oversold Lookback Minimum Value", minval=0, maxval=200)-os_lb = input(35, "Oversold Lookback Bars", minval=0, maxval=100)+os_lb = input.int(35, "Oversold Lookback Bars", minval=0, maxval=100)source = input.source(title="Source", defval=close)⋯// Price Movement Inputs-PriceInfo = input(true, "Price Change Percentage Cross Check Inputs for all Strategies, added logic to avoid early sell. This is different from setting of max loss in risk management.")+PriceInfo = input.bool(true, "Price Change Percentage Cross Check Inputs for all Strategies, added logic to avoid early sell. This is different from setting of max loss in risk management.")-lkbk = input(5,"Max Lookback Period")+lkbk = input.int(5,"Max Lookback Period")// EMA and SMA Background Inputs-useStoch = input(false, "Use Stochastic Strategy, choose only one")+useStoch = input.bool(false, "Use Stochastic Strategy, choose only one")-StochInfo = input(true, "Stochastic Strategy Inputs")+StochInfo = input.bool(true, "Stochastic Strategy Inputs")-smoothK = input(3, "K", minval=1)+smoothK = input.int(3, "K", minval=1)-periodK = input(14, "K Period", minval=1)+periodK = input.int(14, "K Period", minval=1)-periodD = input(3, "D Period", minval=1)+periodD = input.int(3, "D Period", minval=1)-k_mode = input("SMA", "K Mode", options=["SMA", "EMA", "WMA"])+k_mode = input.string("SMA", "K Mode", options=["SMA", "EMA", "WMA"])-high_source = input(high,"High Source")+high_source = input.source(high,"High Source")-low_source= input(low,"Low Source")+low_source= input.source(low,"Low Source")// Selections to show or hide the overlays-showZones = input(true, title="Show Bullish/Bearish Zones")+showZones = input.bool(true, title="Show Bullish/Bearish Zones")-showStoch = input(true, title="Show Stochastic Overlays")+showStoch = input.bool(true, title="Show Stochastic Overlays")-showRSIBS = input(true, title="Show RSI Buy Sell Zones")+showRSIBS = input.bool(true, title="Show RSI Buy Sell Zones")-showMACD = input(true, title="Show MACD")+showMACD = input.bool(true, title="Show MACD")-color_bars=input(true, "Color Bars")+color_bars=input.bool(true, "Color Bars")// ----------------------- Dynamic RSI --------------------------------------⋯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.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-//@version=5+//@version=6// ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗██████╗ ██████╗ ██╗ ██╗ ⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Start Time | timestamp("22 June 2021 00:00 -0500") | time | line 24 |
| End Time | timestamp("31 December 2021 00:00 -0600") | time | line 24 |
| Long/Short for Mixed Market, Long for Bull, Short for Bear | true | bool | unused |
| Trade Types | Long/Short | string · options ["Long Only", "Long/Short", "Short Only"] | strat_val |
| Stop Loss % | 10.0 | float · min 0 · max 100 · step 0.01 | stoploss |
| Target Profit % | 20.0 | float · min 0 · max 100 · step 0.01 | TargetProfit |
| Stop Trading After This Many Losing Days | 2 | int (written input.integer) · min 0 · max 100 · step 1 | line 35 |
| Maximum % of Equity Lost to Halt Trading | 10 | int (written input.integer) · min 1 · max 100 · step 1 | line 37 |
| Use RSI crossing back, select only one strategy | false | bool | GoLong GoShort CloseShort CloseLong |
| Use Tweaked Connors RSI, select only one | false | bool | col GoLong GoShort CloseShort CloseLong |
| These are the RSI Strategy Inputs, RSI Length applies to MACD, set OB and OS to 45 for using Stoch and EMA strategies. | true | bool | unused |
| RSI Length | 14 | int · min 1 | RSI rsi_ema out h1 l1 macdLine signalLine |
| Overbought | 62 | int | Overbought signalColor connor_ob XRSI_OB RSI_OB |
| Oversold | 35 | int | Oversold signalColor connor_os XRSI_OS RSI_OS |
| Connor's MA Length 1 | 3 | int · min 1 · step 1 | ma1 |
| Connor's MA Lenght 2 | 20 | int · min 1 · step 1 | ma2 |
| Connor's MA Lenght 3 | 50 | int · min 1 · step 1 | ma3 |
| Use MACD Only, select only one strategy | false | bool | GoLong GoShort CloseShort CloseLong |
| Use EMA Only, select only one strategy (EMA uses Stochastic inputs too) | false | bool | GoLong GoShort CloseShort CloseLong |
| These are the MACD strategy variables | true | bool | unused |
| EMA Fast Length | 5 | int · min 1 | emaA emaFast macdLine signalLine |
| EMA Slow Length | 10 | int · min 1 | emaB emaSlow macdLine signalLine |
| Overbought Lookback Minimum Value | 52 | int · min 0 · max 200 | RSI_high |
| Overbought Lookback Bars | 25 | int · min 0 · max 100 | RSI_high |
| Oversold Lookback Minimum Value | 50 | int · min 0 · max 200 | RSI_low |
| Oversold Lookback Bars | 35 | int · min 0 · max 100 | RSI_low |
| Source | close | source | RSI |
| Price Change Percentage Cross Check Inputs for all Strategies, added logic to avoid early sell. This is different from setting of max loss in risk management. | true | bool | unused |
| Max Lookback Period | 5 | int | i overall_change highest_high lowest_low start_to_high start_to_low overall to_high to_low last_high last_low last_bar h_high l_low |
| Use Stochastic Strategy, choose only one | false | bool | GoLong GoShort CloseShort CloseLong |
| Stochastic Strategy Inputs | true | bool | unused |
| K | 3 | int · min 1 | k |
| K Period | 14 | int · min 1 | stoch |
| D Period | 3 | int · min 1 | d |
| K Mode | SMA | string · options ["SMA", "EMA", "WMA"] | k |
| High Source | high | source | h_high stoch |
| Low Source | low | source | l_low stoch |
| Show Bullish/Bearish Zones | true | bool | Bullish/Bearish Zones |
| Show Stochastic Overlays | true | bool | K D signalUp signalDown |
| Show RSI Buy Sell Zones | true | bool | unused |
| Show MACD | true | bool | MACD Signals |
| Color Bars | true | bool | barcolor |
What it calculates
- RSI (
rsi,ta.rsiin v5)Source (close), RSI Length (14)RSI · line 58 - EMA (
ema,ta.emain v5)RSI, RSI Length (14)rsi_ema · line 124 - EMA (
ema,ta.emain v5)rsi_ema, EMA Fast Length (5)emaA · line 125 - EMA (
ema,ta.emain v5)emaA, EMA Fast Length (5)emaFast · line 126 - EMA (
ema,ta.emain v5)rsi_ema, EMA Slow Length (10)emaB · line 127 - EMA (
ema,ta.emain v5)emaB, EMA Slow Length (10)emaSlow · line 128 - EMA (
ema,ta.emain v5)RSI, RSI Length (14)out · line 130 - Highest (
highest,ta.highestin v5)High Source (high), Max Lookback Period (5)h_high · line 176 - Lowest (
lowest,ta.lowestin v5)Low Source (low), Max Lookback Period (5)l_low · line 177 - Stoch (
stoch,ta.stochin v5)close, High Source (high), Low Source (low), K Period (14)stoch · line 178 - EMA / WMA / SMA (
ema,ta.emain v5)stoch, K (3) · chosen by K Modek · line 179 - SMA (
sma,ta.smain v5)k, D Period (3)d · line 183 - Change (
change,ta.changein v5)kk_c · line 184 - Change (
change,ta.changein v5)dd_c · line 185 - VWMA (
vwma,ta.vwmain v5)high, RSI Length (14)h1 · line 201 - VWMA (
vwma,ta.vwmain v5)low, RSI Length (14)l1 · line 202 - SMA (
sma,ta.smain v5)close, Connor's MA Length 1 (3)ma1 · line 223 - SMA (
sma,ta.smain v5)close, Connor's MA Lenght 2 (20)ma2 · line 224 - SMA (
sma,ta.smain v5)close, Connor's MA Lenght 3 (50)ma3 · line 225 - MACD (
macd,ta.macdin v5)close, EMA Fast Length (5), EMA Slow Length (10), RSI Length (14)macdLine · line 234 - MACD (
macd,ta.macdin v5)close, EMA Fast Length (5), EMA Slow Length (10), RSI Length (14)signalLine · line 234
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 111 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open LONG long | (GoLong) | On | 254 |
| Open SHORT short | (GoShort) | On | 259 |
| Exit Exit Long stop and limit | (strategy.position_size > 0) | On | 269 |
| Exit Exit Short stop and limit | (strategy.position_size < 0) | On | 272 |
| Close LONG | (CloseLong) | On | 280 |
| Close SHORT | (CloseShort) | On | 283 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- CheckIntrabar recalculationcalc_on_every_tick = true. Live values can differ from history.
- ClearOrder timingprocess_orders_on_close = true: orders fill at the signal bar's close.
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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| All in One Strategy this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| All in One Strategy no RSI Label - For higher dollar crypto by Solutions1978 | rsi ema highest lowest stoch sma vwma macd | v4 strategy | No trades on this market | ||
| Bear & Bull Zone Signal Strategy by Solutions1978 | rsi ema highest lowest stoch sma vwma | v4 strategy | No trades on this market | ||
| sma RSI & sudden buy and sell Strategy v1 by samwillington | ema rsi highest lowest sma | v5 strategy | +7.6% | 15 | 3.7% |
| Swing Multi Moving Averages Crypto and Stocks Strategy by exlux99 | ema wma highest lowest sma | v5 strategy | +60.2% | 22 | 13.1% |
| VCP pivot buy by perrycc007 | sma ema vwma wma lowest highest | v4 strategy | does not run in Zeal Terminal | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 52 ms | Yes 1,000 bars in 277 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
“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///@version=4// ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗██████╗ ██████╗ ██╗ ██╗ //██╔════╝██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝██╔══██╗ ██╔══██╗╚██╗ ██╔╝ //██║ ██████╔╝█████╗ ███████║ ██║ █████╗ ██║ ██║ ██████╔╝ ╚████╔╝ //██║ ██╔══██╗██╔══╝ ██╔══██║ ██║ ██╔══╝ ██║ ██║ ██╔══██╗ ╚██╔╝ //╚██████╗██║ ██║███████╗██║ ██║ ██║ ███████╗██████╔╝ ██████╔╝ ██║ // ╚═════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═════╝ ╚═════╝ ╚═╝ //███████╗ ██████╗ ██╗ ██╗ ██╗████████╗██╗ ██████╗ ███╗ ██╗███████╗ ██╗ █████╗ ███████╗ █████╗ //██╔════╝██╔═══██╗██║ ██║ ██║╚══██╔══╝██║██╔═══██╗████╗ ██║██╔════╝███║██╔══██╗╚════██║██╔══██╗//███████╗██║ ██║██║ ██║ ██║ ██║ ██║██║ ██║██╔██╗ ██║███████╗╚██║╚██████║ ██╔╝╚█████╔╝//╚════██║██║ ██║██║ ██║ ██║ ██║ ██║██║ ██║██║╚██╗██║╚════██║ ██║ ╚═══██║ ██╔╝ ██╔══██╗//███████║╚██████╔╝███████╗╚██████╔╝ ██║ ██║╚██████╔╝██║ ╚████║███████║ ██║ █████╔╝ ██║ ╚█████╔╝//╚══════╝ ╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚════╝ ╚═╝ ╚════╝ strategy(shorttitle='Ain1v4',title='All in One Strategy', overlay=true, scale=scale.left, initial_capital = 1000, process_orders_on_close=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent, commission_value=0.18, calc_on_every_tick=true)kcolor = color.new(#0094FF, 60)dcolor = color.new(#FF6A00, 60)// ----------------- Strategy Inputs -------------------------------------------------------------//Backtest dates with auto finish date of todaystart = input(defval = timestamp("22 June 2021 00:00 -0500"), title = "Start Time", type = input.time)finish = input(defval = timestamp("31 December 2021 00:00 -0600"), title = "End Time", type = input.time)window() => time >= start and time <= finish ? true : false // create function "within window of time"// Strategy Selection - Long, Short, or Bothstratinfo = input(true, "Long/Short for Mixed Market, Long for Bull, Short for Bear")strat = input(title="Trade Types", defval="Long/Short", options=["Long Only", "Long/Short", "Short Only"])strat_val = strat == "Long Only" ? 1 : strat == "Long/Short" ? 0 : -1// Risk Management Inputssl= input(10.0, "Stop Loss %", minval = 0, maxval = 100, step = 0.01)stoploss = sl/100tp = input(20.0, "Target Profit %", minval = 0, maxval = 100, step = 0.01)TargetProfit = tp/100ld = input(2, "Stop Trading After This Many Losing Days", type=input.integer, minval=0, maxval=100, step=1)strategy.risk.max_cons_loss_days(count=ld)ml = input(10, "Maximum % of Equity Lost to Halt Trading", type=input.integer, minval=1, maxval=100, step=1)strategy.risk.max_drawdown(value=ml, type=strategy.percent_of_equity)useXRSI = input(false, "Use RSI crossing back, select only one strategy")useCRSI = input(false, "Use Tweaked Connors RSI, select only one")RSIInfo = input(true, "These are the RSI Strategy Inputs, RSI Length applies to MACD, set OB and OS to 45 for using Stoch and EMA strategies.")length = input(14, "RSI Length", minval=1)overbought= input(62, "Overbought")oversold= input(35, "Oversold")cl1 = input(3, "Connor's MA Length 1", minval=1, step=1)cl2 = input(20, "Connor's MA Lenght 2", minval=1, step=1)cl3 = input(50, "Connor's MA Lenght 3", minval=1, step=1)// MACD and EMA InputsuseMACD = input(false, "Use MACD Only, select only one strategy")useEMA = input(false, "Use EMA Only, select only one strategy (EMA uses Stochastic inputs too)")MACDInfo=input(true, "These are the MACD strategy variables")fastLength = input(5, minval=1, title="EMA Fast Length")slowLength = input(10, minval=1, title="EMA Slow Length")ob_min = input(52, "Overbought Lookback Minimum Value", minval=0, maxval=200)ob_lb = input(25, "Overbought Lookback Bars", minval=0, maxval=100)os_min = input(50, "Oversold Lookback Minimum Value", minval=0, maxval=200)os_lb = input(35, "Oversold Lookback Bars", minval=0, maxval=100)source = input(title="Source", type=input.source, defval=close)RSI = rsi(source, length)// Price Movement InputsPriceInfo = input(true, "Price Change Percentage Cross Check Inputs for all Strategies, added logic to avoid early sell. This is different from setting of max loss in risk management.")lkbk = input(5,"Max Lookback Period")// EMA and SMA Background InputsuseStoch = input(false, "Use Stochastic Strategy, choose only one")StochInfo = input(true, "Stochastic Strategy Inputs")smoothK = input(3, "K", minval=1)periodK = input(14, "K Period", minval=1)periodD = input(3, "D Period", minval=1)k_mode = input("SMA", "K Mode", options=["SMA", "EMA", "WMA"])high_source = input(high,"High Source")low_source= input(low,"Low Source")// Selections to show or hide the overlaysshowZones = input(true, title="Show Bullish/Bearish Zones")showStoch = input(true, title="Show Stochastic Overlays")showRSIBS = input(true, title="Show RSI Buy Sell Zones")showMACD = input(true, title="Show MACD")color_bars=input(true, "Color Bars")// ----------------------- Dynamic RSI --------------------------------------// Define f_print function to show key recommendations for RSIf_print(_text) => // Create label on the first bar. var _label = label(na), label.delete(_label), _label := label.new( time + (time-time[1]), ohlc4, _text, xloc.bar_time, yloc.price, color(na), label.style_none, color.gray, size.large, text.align_left ) // Display highest and lowest RSI valuesAvgHigh(src,cnt,val) => total = 0.0 count = 0 for i = 0 to cnt if src[i] > val count := count + 1 total := total + src[i] round(total / count) RSI_high = AvgHigh(RSI, ob_lb, ob_min)AvgLow(src,cnt,val) => total = 0.0 count = 0 for i = 5 to cnt by 5 if src[i] < val count := count + 1 total := total + src[i] round(total / count)RSI_low = AvgLow(RSI, os_lb, os_min)f_print("Recommended RSI Settings:" + "\nOverbought = " + tostring(RSI_high) + "\nOversold = " + tostring(RSI_low))// Plot Oversold and Overbought Linesover = hline(oversold, title="Oversold", color=color.green)under = hline(overbought, title="Overbought", color=color.red)fillcolor = color.new(#9915FF, 90)fill(over, under, fillcolor, title="Band Background")// ------------------ Background Colors based on EMA Indicators -----------------------------------rsi_ema = ema(RSI, length)emaA = ema(rsi_ema, fastLength) emaFast = 2 * emaA - ema(emaA, fastLength)emaB = ema(rsi_ema, slowLength) emaSlow = 2 * emaB - ema(emaB, slowLength) // New Bullish and Bearish Signal Rule logic checkout = ema(RSI, length)// bullish signal rule: bullishRule =emaFast > emaSlow and out >=out[1]// bearish signal rule: bearishRule =emaFast < emaSlow and out <= out[1]EMAShortSell = crossunder(rsi_ema, emaFast) and crossunder(rsi_ema, emaSlow) and bearishRule and window()EMAShortBuy = crossover(rsi_ema, emaFast) and crossover(rsi_ema, emaSlow) and bullishRule and window()EMALongBuy = crossover(rsi_ema, emaSlow) and crossover(rsi_ema, emaFast) and bullishRule and window()EMALongSell = crossunder(emaFast, emaSlow) and bearishRule and window()// current trading StateruleState = 0ruleState := bullishRule ? 1 : bearishRule ? -1 : nz(ruleState[1])ruleColor = ruleState==1 ? color.new(color.blue, 90) : ruleState == -1 ? color.new(color.red, 90) : ruleState == 0 ? color.new(color.gray, 90) : nabgcolor(showZones ? ruleColor : na, title="Bullish/Bearish Zones")// ------------------ Price Percentage Change Calculation ---------------------------------------perc_change(lkbk) => overall_change = ((close[0] - open[lkbk]) / open[lkbk]) * 100 highest_high = 0.0 lowest_low = 0.0 for i = lkbk to 0 highest_high := i == lkbk ? high : high[i] > high[(i + 1)] ? high[i] : highest_high[1] lowest_low := i == lkbk ? low : low[i] < low[(i + 1)] ? low[i] : lowest_low[1] start_to_high = ((highest_high - open[lkbk]) / open[lkbk]) * 100 start_to_low = ((lowest_low - open[lkbk]) / open[lkbk]) * 100 previous_to_high = ((highest_high - open[1])/open[1])*100 previous_to_low = ((lowest_low-open[1])/open[1])*100 previous_bar = ((close[1]-open[1])/open[1])*100 [overall_change, start_to_high, start_to_low, previous_to_high, previous_to_low, previous_bar] // Call the function [overall, to_high, to_low, last_high, last_low, last_bar] = perc_change(lkbk)// Plot the function//plot(overall*50, color=color.white, title='Overall Percentage Change', linewidth=3)//plot(to_high*50, color=color.green,title='Percentage Change from Start to High', linewidth=2)//plot(to_low*50, color=color.red, title='Percentage Change from Start to Low', linewidth=2)//plot(last_high*100, color=color.teal, title="Previous to High", linewidth=2)//plot(last_low*100, color=color.maroon, title="Previous to Close", linewidth=2)//plot(last_bar*100, color=color.orange, title="Previous Bar", linewidth=2)//hline(0, title='Center Line', color=color.orange, linewidth=2)true_dip = overall < 0 and to_high > 0 and to_low < 0 and last_high > 0 and last_low < 0 and last_bar < 0true_peak = overall > 0 and to_high > 0 and to_low > 0 and last_high > 0 and last_low < 0 and last_bar > 0// ------------------ Stochastic Indicator Overlay -----------------------------------------------// Calculation// Use highest highs and lowest lowsh_high = highest(high_source ,lkbk)l_low = lowest(low_source ,lkbk)stoch = stoch(close, high_source, low_source, periodK)k = k_mode=="EMA" ? ema(stoch, smoothK) : k_mode=="WMA" ? wma(stoch, smoothK) : sma(stoch, smoothK)d = sma(k, periodD)k_c = change(k)d_c = change(d)kd = k - d// PlotsignalColor = k>oversold and d<overbought and k>d and k_c>0 and d_c>0 ? kcolor : k<overbought and d>oversold and k<d and k_c<0 and d_c<0 ? dcolor : nakp = plot(showStoch ? k : na, "K", color=kcolor)dp = plot(showStoch ? d : na, "D", color=dcolor)fill(kp, dp, color = signalColor, title="K-D")signalUp = showStoch ? not na(signalColor) and kd>0 : nasignalDown = showStoch ? not na(signalColor) and kd<0 : na//plot(signalUp ? kd : na, "Signal Up", color=kcolor, transp=90, style=plot.style_columns)//plot(signalDown ? (kd+100) : na , "Signal Down", color=dcolor, transp=90, style=plot.style_columns, histbase=100)StochBuy = crossover(k, d) and k_c>0 and d_c>0 and k<RSI and d<RSI and window()StochSell = crossunder(k, d) and k_c<0 and d_c<0 and k<RSI and d<RSI and window()// -------------- Add Price Movement to Strategy for better visualization -------------------------// Calculationsh1 = vwma(high, length)l1 = vwma(low, length)hp = h_high[1]lp = l_low[1]// Plotvar plot_color=#353535var sig = 0if (h1 >hp) sig:=1 plot_color:=color.limeelse if (l1 <lp) sig:=-1 plot_color:=color.maroon//plot(1,title = "Price Movement Bars", style=plot.style_columns,color=plot_color)//plot(sig,title="Signal 1 or -1",display=display.none)// --------------------------------------- RSI Plot ----------------------------------------------// Show RSI and EMA crosses with arrows and RSI Color (tweaked Connors RSI)// Improves strategy setting ease by showing where EMA 5 crosses EMA 10 from above to confirm overbought conditions or trend reversals// This shows where you should enter shorts or exit longs// Tweaked Connors RSI Calculationconnor_ob = overboughtconnor_os = oversoldma1 = sma(close,cl1)ma2 = sma(close, cl2)ma3 = sma(close, cl3)// Buy Sell Zones using tweaked Connors RSI (RSI values of 80 and 20 for Crypto as well as ma3, ma20, and ma50 are the tweaks)RSI_SELL = ma1 > ma2 and open > ma3 and RSI >= connor_ob and true_peak and window()RSI_BUY = ma2 < ma3 and ma3 > close and RSI <= connor_os and true_dip and window()// Color Definitioncol = useCRSI ? (close > ma2 and close < ma3 and RSI <= connor_os ? color.lime : close < ma2 and close > ma3 and RSI <= connor_ob ? color.red : color.yellow ) : color.yellow// Plot colored RSI Lineplot(RSI, title="RSI", linewidth=3, color=col)//------------------- MACD Strategy -------------------------------------------------[macdLine, signalLine, _] = macd(close, fastLength, slowLength, length)bartrendcolor = macdLine > signalLine and k > 50 and RSI > 50 ? color.teal : macdLine < signalLine and k < 50 and RSI < 50 ? color.maroon : macdLine < signalLine ? color.yellow : color.graybarcolor(color = color_bars ? bartrendcolor : na)MACDBuy = macdLine>signalLine and RSI<RSI_low and overall<0 and window()MACDSell = macdLine<signalLine and RSI>RSI_high and overall>0 and window()//plotshape(showMACD ? MACDBuy: na, title = "MACD Buy", style = shape.arrowup, text = "MACD Buy", color=color.green, textcolor=color.green, size=size.small)//plotshape(showMACD ? MACDSell: na, title = "MACD Sell", style = shape.arrowdown, text = "MACD Sell", color=color.red, textcolor=color.red, size=size.small)MACColor = MACDBuy ? color.new(color.teal, 50) : MACDSell ? color.new(color.maroon, 50) : nabgcolor(showMACD ? MACColor : na, title ="MACD Signals")// -------------------------------- Entry and Exit Logic ------------------------------------// Entry LogicXRSI_OB = crossunder(RSI, overbought) and overall<0 and window()RSI_OB = RSI>overbought and true_peak and window()XRSI_OS = crossover(RSI, oversold) and overall>0 and window()RSI_OS = RSI<oversold and true_dip and window()// Strategy Entry and Exit with built in Risk Managementif(strategy.opentrades==0 and strat_val>-1) OtherLong = rsi_ema > RSI and k < d GoLong = useStoch ? StochBuy : useXRSI ? OtherLong and XRSI_OS : useMACD ? OtherLong and MACDBuy : useCRSI ? OtherLong and RSI_BUY : useEMA ? EMALongBuy : RSI_OS if (GoLong) strategy.entry("LONG", strategy.long)if(strategy.opentrades==0 and strat_val<1) OtherShort = rsi_ema < RSI and d < k GoShort = useStoch ? StochSell : useXRSI ? OtherShort and XRSI_OB : useMACD ? OtherShort and MACDSell : useCRSI ? OtherShort and RSI_SELL : useEMA ? EMAShortSell : OtherShort and RSI_OB if (GoShort) strategy.entry("SHORT", strategy.short)longStopPrice = strategy.position_avg_price * (1 - stoploss)longTakePrice = strategy.position_avg_price * (1 + TargetProfit)shortStopPrice = strategy.position_avg_price * (1 + stoploss)shortTakePrice = strategy.position_avg_price * (1 - TargetProfit)//plot(series=(strategy.position_size > 0) ? longTakePrice : na, color=color.green, style=plot.style_circles, linewidth=3, title="Long Take Profit")//plot(series=(strategy.position_size < 0) ? shortTakePrice : na, color=color.green, style=plot.style_circles, linewidth=3, title="Short Take Profit")//plot(series=(strategy.position_size > 0) ? longStopPrice : na, color=color.red, style=plot.style_cross, linewidth=2, title="Long Stop Loss")//plot(series=(strategy.position_size < 0) ? shortStopPrice : na, color=color.red, style=plot.style_cross, linewidth=2, title="Short Stop Loss")if (strategy.position_size > 0) strategy.exit(id="Exit Long", from_entry = "LONG", stop = longStopPrice, limit = longTakePrice) if (strategy.position_size < 0) strategy.exit(id="Exit Short", from_entry = "SHORT", stop = shortStopPrice, limit = shortTakePrice)StochLong2 = strategy.position_size<0 and strat_val > -1OtherLong2 = strategy.position_size<0 and strat_val > -1 and rsi_ema > RSI and k < d CloseShort= useStoch ? StochLong2 and StochBuy : useXRSI ? OtherLong2 and XRSI_OS : useMACD ? OtherLong2 and MACDBuy : useCRSI ? OtherLong2 and RSI_BUY : useEMA ? EMAShortBuy : RSI_OSStochShort2 = strategy.position_size>0 and strat_val < 1 OtherShort2 = strategy.position_size>0 and strat_val < 1 and rsi_ema < RSI and d < kCloseLong = useStoch ? StochShort2 and StochSell : useXRSI ? OtherShort2 and XRSI_OB : useMACD ? OtherShort2 and MACDSell : useCRSI ? OtherShort2 and RSI_SELL : useEMA ? EMALongSell : OtherShort2 and RSI_OBif(CloseLong) strategy.close("LONG") if(CloseShort) strategy.close("SHORT")