Pine Script v4 · Strategy
Full strategy AllinOne with risk management MACD RSI PSAR ATR MA
A Pine Script v4 strategy built on RSI (price, 5), Crossover (vrsi, 23) and Crossunder (vrsi, 72). It has 7 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 is one contract and pays no commission. 34 settings; defaults include From Day 1, From Month 6 and From Year 2020.
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 Full strategy AllinOne with risk management MACD RSI PSAR ATR MA repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
- Can Full strategy AllinOne with risk management MACD RSI PSAR ATR MA be converted to Pine Script v5?
- Yes
- The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- Does Full strategy AllinOne with risk management MACD RSI PSAR ATR MA use a stop loss?
- Yes
- strategy.exit sets a stop on line 206, 208.
- Does Full strategy AllinOne with risk management MACD RSI PSAR ATR MA run in Zeal Terminal?
- Yes
- It compiles in 44 ms and runs 1,000 bars in 97 ms, in the browser.
BTCUSDT · 1D · default settings
- Crossover
- Crossunder
- SMA
- SMA
- SMA
- SMA
- Stdev
- EMA
- ATR
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +2,985,110.00%
- $29,851,100.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 3
- 2 won · 1 lost
- Profitable
- 66.7%
- of closed trades
- Profit factor
- 3.91
- gross profit ÷ gross loss
- Max drawdown
- 2,350,820.00%
- −$23,508,200.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
2 settings do nothing
“Offset”, “Offset” are declared but never read.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
7 settings have no label
In the settings dialog length (line 37), overSold (line 38), overBought (line 39), start (line 66), increment (line 67), maximum (line 68), length_bb (line 139) show an empty name. The labels on this page come from the variable names.
-
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 203, 204, 207, 209. The upgraded version below moves each call inside an if block.
-
Note
Uses iff(), which v5 removed line 20
iff() on line 20, 22, 24, 26. v5 writes it as the ternary c ? a : b.
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, crossover → ta.crossover, crossunder → ta.crossunder, sma → ta.sma, ema → ta.ema, max → math.max, min → math.min, stdev → ta.stdev, atr → ta.atr, abs → math.abs.
- 4 strategy calls use the when = argument (line 203, 204, 207, 209). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 3 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 20: iff(c, a, b) → (c ? a : b)
- Line 22: iff(c, a, b) → (c ? a : b)
- Line 24: iff(c, a, b) → (c ? a : b)
- Line 26: iff(c, a, b) → (c ? a : b)
- Line 41: rsi → ta.rsi
43 more edits
- Line 42: crossover → ta.crossover
- Line 43: crossunder → ta.crossunder
- Line 45: input(type = input.integer) → input.int()
- Line 46: input(type = input.integer) → input.int()
- Line 47: input(type = input.source) → input.source()
- Line 48: input(type = input.integer) → input.int()
- Line 49: input(type = input.bool) → input.bool()
- Line 50: input(type = input.bool) → input.bool()
- Line 59: sma → ta.sma
- Line 59: ema → ta.ema
- Line 60: sma → ta.sma
- Line 60: ema → ta.ema
- Line 62: sma → ta.sma
- Line 62: ema → ta.ema
- Line 103: max → math.max
- Line 110: min → math.min
- Line 118: min → math.min
- Line 122: min → math.min
- Line 125: min → math.min
- Line 127: min → math.min
- Line 129: max → math.max
- Line 131: max → math.max
- Line 142: sma → ta.sma
- Line 143: stdev → ta.stdev
- Line 146: input(type = input.integer) → input.int()
- Line 154: input(type = input.integer) → input.int()
- Line 155: ema → ta.ema
- Line 162: crossunder → ta.crossunder
- Line 162: ema → ta.ema
- Line 162: sma → ta.sma
- Line 163: crossover → ta.crossover
- Line 163: ema → ta.ema
- Line 163: sma → ta.sma
- Line 169: atr → ta.atr
- Line 173: input(type = input.float) → input.float()
- Line 175: input(type = input.float) → input.float()
- Line 176: input(type = input.float) → input.float()
- Line 177: input(type = input.float) → input.float()
- Line 178: input(type = input.float) → input.float()
- Line 185: abs → math.abs
- Line 189: abs → math.abs
- Line 203: strategy.entry(…, true) → strategy.entry(…, strategy.long)
- Line 204: strategy.entry(…, false) → strategy.entry(…, strategy.short)
⋯// © SoftKill21-//@version=4+//@version=5strategy("EURUSD 1min strat RISK %% ", overlay=false, initial_capital = 1000)⋯//--- Europe-London = iff(DST==0,"0000-0900","0100-1000")+London = (DST==0 ? "0000-0900" : "0100-1000")//--- America-NewYork = iff(DST==0,"0400-1500","0500-1600")+NewYork = (DST==0 ? "0400-1500" : "0500-1600")//--- Pacific-Sydney = iff(DST==0,"1300-2200","1400-2300")+Sydney = (DST==0 ? "1300-2200" : "1400-2300")//--- Asia-Tokyo = iff(DST==0,"1500-2400","1600-0100")+Tokyo = (DST==0 ? "1500-2400" : "1600-0100")//-- Time In Range⋯price = close-vrsi = rsi(price, length)+vrsi = ta.rsi(price, length)-co = crossover(vrsi, overSold)+co = ta.crossover(vrsi, overSold)-cu = crossunder(vrsi, overBought)+cu = ta.crossunder(vrsi, overBought)// macd-fast_length_macd = input(title="Fast Length", type=input.integer, defval=12)+fast_length_macd = input.int(title="Fast Length", defval=12)-slow_length_macd = input(title="Slow Length", type=input.integer, defval=26)+slow_length_macd = input.int(title="Slow Length", defval=26)-src_macd = input(title="Source", type=input.source, defval=close)+src_macd = input.source(title="Source", defval=close)-signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)+signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9)-sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=true)+sma_source = input.bool(title="Simple MA(Oscillator)", defval=true)-sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=true)+sma_signal = input.bool(title="Simple MA(Signal Line)", defval=true)// Plot colors⋯// Calculating-fast_ma = sma_source ? sma(src_macd, fast_length_macd) : ema(src_macd, fast_length_macd)+fast_ma = sma_source ? ta.sma(src_macd, fast_length_macd) : ta.ema(src_macd, fast_length_macd)-slow_ma = sma_source ? sma(src_macd, slow_length_macd) : ema(src_macd, slow_length_macd)+slow_ma = sma_source ? ta.sma(src_macd, slow_length_macd) : ta.ema(src_macd, slow_length_macd)macd = fast_ma - slow_ma-signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)+signal = sma_signal ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)hist = macd - signal⋯ uptrend := false- SAR := max(EP, high)+ SAR := math.max(EP, high) EP := low⋯ uptrend := true- SAR := min(EP, low)+ SAR := math.min(EP, low) EP := high⋯ EP := high- AF := min(AF + increment, maximum)+ AF := math.min(AF + increment, maximum) else⋯ EP := low- AF := min(AF + increment, maximum)+ AF := math.min(AF + increment, maximum) if uptrend- SAR := min(SAR, low[1])+ SAR := math.min(SAR, low[1]) if bar_index > 1- SAR := min(SAR, low[2])+ SAR := math.min(SAR, low[2]) else- SAR := max(SAR, high[1])+ SAR := math.max(SAR, high[1]) if bar_index > 1- SAR := max(SAR, high[2])+ SAR := math.max(SAR, high[2]) ⋯mult_bb = input(2.0, minval=0.001, maxval=50, title="StdDev")-basis_bb = sma(src_bb, length_bb)+basis_bb = ta.sma(src_bb, length_bb)-dev_bb = mult_bb * stdev(src_bb, length_bb)+dev_bb = mult_bb * ta.stdev(src_bb, length_bb)upper_bb = basis_bb + dev_bblower_bb = basis_bb - dev_bb-offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)+offset = input.int(0, "Offset", minval = -500, maxval = 500)//plot(basis_bb, "Basis", color=#872323, offset = offset)⋯src_ema = input(close, title="Source")-offset_ema = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)+offset_ema = input.int(title="Offset", defval=0, minval=-500, maxval=500)-out_ema = ema(src_ema, len_ema)+out_ema = ta.ema(src_ema, len_ema)//plot(out_ema, title="EMA", color=color.blue, offset=offset_ema) ⋯// confirmarea-shortCondition = (uptrend==false and crossunder(ema(src_ema, len_ema),sma(src_bb, length_bb)) and hist < 0 and vrsi < overSold) //and time_cond+shortCondition = (uptrend==false and ta.crossunder(ta.ema(src_ema, len_ema),ta.sma(src_bb, length_bb)) and hist < 0 and vrsi < overSold) //and time_cond-longCondition = (uptrend==true and crossover(ema(src_ema, len_ema),sma(src_bb, length_bb)) and hist > 0 and vrsi > overBought ) //and time_cond+longCondition = (uptrend==true and ta.crossover(ta.ema(src_ema, len_ema),ta.sma(src_bb, length_bb)) and hist > 0 and vrsi > overBought ) //and time_cond//tp=input(0.0025,type=input.float, title="tp")⋯atr_period = input(14, "Average True Range Period")-atr = atr(atr_period)+atr = ta.atr(atr_period)//MONEY MANAGEMENT--------------------------------------------------------------⋯floating = strategy.openprofit //floating profit/loss-risk = input(2,type=input.float,title="Risk %")/100 //risk % per trade+risk = input.float(2,title="Risk %")/100 //risk % per tradeisTwoDigit = input(false,"Is this a 2 digit pair? (JPY, XAU, XPD...")-equity_protector = input(1 ,type=input.float, title="Equity Protection %")/100 //equity protection %+equity_protector = input.float(1 , title="Equity Protection %")/100 //equity protection %-equity_protectorTP = input(2 ,type=input.float, title="Equity TP %")/100 //equity protection %+equity_protectorTP = input.float(2 , title="Equity TP %")/100 //equity protection %-multtp = input(5,type=input.float, title="multi atr tp")+multtp = input.float(5, title="multi atr tp")-multsl = input(5,type=input.float, title="multi atr sl")+multsl = input.float(5, title="multi atr sl")stop = atr*100000*input(1,"SL X")* multsl //Stop level⋯equity_stopout = false-if(floating<0 and abs(floating/balance)>equity_protector)+if(floating<0 and math.abs(floating/balance)>equity_protector) equity_stopout := true⋯equity_stopout2 = false-if(floating>0 and abs(floating/balance)>equity_protectorTP)+if(floating>0 and math.abs(floating/balance)>equity_protectorTP) equity_stopout2 := true⋯is_open = strategy.opentrades > 0-strategy.entry("long",true,size,oca_name="a",oca_type=strategy.oca.cancel,when=longCondition and not is_open) //Long entry+strategy.entry("long",strategy.long,size,oca_name="a",oca_type=strategy.oca.cancel,when=longCondition and not is_open) //Long entry-strategy.entry("short",false,size,oca_name="a",oca_type=strategy.oca.cancel,when=shortCondition and not is_open) //Short entry+strategy.entry("short",strategy.short,size,oca_name="a",oca_type=strategy.oca.cancel,when=shortCondition and not is_open) //Short entry ⋯Same 3 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 8: input() → input.int()
- Line 9: input() → input.int()
- Line 10: input() → input.int()
- Line 13: input() → input.int()
- Line 14: input() → input.int()
- Line 15: input() → input.int()
19 more edits
- Line 37: input() → input.int()
- Line 38: input() → input.int()
- Line 39: input() → input.int()
- Line 66: input() → input.float()
- Line 67: input() → input.float()
- Line 68: input() → input.float()
- Line 139: input() → input.int()
- Line 140: input() → input.source()
- Line 141: input() → input.float()
- Line 152: input() → input.int()
- Line 153: input() → input.source()
- Line 168: input() → input.int()
- Line 174: input() → input.bool()
- Line 179: input() → input.int()
- Line 182: input() → input.int()
- Line 203: when = longCondition and not is_open → if block
- Line 204: when = shortCondition and not is_open → if block
- Line 207: when = shortCondition → if block
- Line 209: when = longCondition → if block
⋯// From Date Inputs-fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)+fromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)-fromMonth = input(defval = 6, title = "From Month", minval = 1, maxval = 12)+fromMonth = input.int(defval = 6, title = "From Month", minval = 1, maxval = 12)-fromYear = input(defval = 2020, title = "From Year", minval = 1970)+fromYear = input.int(defval = 2020, title = "From Year", minval = 1970) // To Date Inputs-toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)+toDay = input.int(defval = 1, title = "To Day", minval = 1, maxval = 31)-toMonth = input(defval = 12, title = "To Month", minval = 1, maxval = 12)+toMonth = input.int(defval = 12, title = "To Month", minval = 1, maxval = 12)-toYear = input(defval = 2020, title = "To Year", minval = 1970)+toYear = input.int(defval = 2020, title = "To Year", minval = 1970) ⋯// rsi-length = input( 5 )+length = input.int( 5 )-overSold = input( 23 )+overSold = input.int( 23 )-overBought = input( 72 )+overBought = input.int( 72 )price = close⋯// sar-start = input(0.02)+start = input.float(0.02)-increment = input(0.02)+increment = input.float(0.02)-maximum = input(0.2)+maximum = input.float(0.2)var bool uptrend = na⋯//bb-length_bb = input(17, minval=1)+length_bb = input.int(17, minval=1)-src_bb = input(close, title="Source")+src_bb = input.source(close, title="Source")-mult_bb = input(2.0, minval=0.001, maxval=50, title="StdDev")+mult_bb = input.float(2.0, minval=0.001, maxval=50, title="StdDev")basis_bb = ta.sma(src_bb, length_bb)⋯//ema-len_ema = input(10, minval=1, title="Length")+len_ema = input.int(10, minval=1, title="Length")-src_ema = input(close, title="Source")+src_ema = input.source(close, title="Source")offset_ema = input.int(title="Offset", defval=0, minval=-500, maxval=500)⋯ //Average True Range (1. RISK)-atr_period = input(14, "Average True Range Period")+atr_period = input.int(14, "Average True Range Period")atr = ta.atr(atr_period)⋯risk = input.float(2,title="Risk %")/100 //risk % per trade-isTwoDigit = input(false,"Is this a 2 digit pair? (JPY, XAU, XPD...")+isTwoDigit = input.bool(false,"Is this a 2 digit pair? (JPY, XAU, XPD...")equity_protector = input.float(1 , title="Equity Protection %")/100 //equity protection %⋯multsl = input.float(5, title="multi atr sl")-stop = atr*100000*input(1,"SL X")* multsl //Stop level+stop = atr*100000*input.int(1,"SL X")* multsl //Stop levelif(isTwoDigit) stop := stop/100-target = atr*100000*input(1,"TP X")*multtp //Stop level+target = atr*100000*input.int(1,"TP X")*multtp //Stop level //Calculate current DD and determine if stopout is necessary⋯is_open = strategy.opentrades > 0-strategy.entry("long",strategy.long,size,oca_name="a",oca_type=strategy.oca.cancel,when=longCondition and not is_open) //Long entry+if longCondition and not is_open+ strategy.entry("long",strategy.long,size,oca_name="a",oca_type=strategy.oca.cancel) //Long entry-strategy.entry("short",strategy.short,size,oca_name="a",oca_type=strategy.oca.cancel,when=shortCondition and not is_open) //Short entry+if shortCondition and not is_open+ strategy.entry("short",strategy.short,size,oca_name="a",oca_type=strategy.oca.cancel) //Short entry strategy.exit("exit_long","long",loss=stop, profit=target) //Long exit (stop loss)-strategy.close("long",when=shortCondition) //Long exit (exit condition)+if shortCondition+ strategy.close("long") //Long exit (exit condition)strategy.exit("exit_short","short",loss=stop, profit=target) //Short exit (stop loss)-strategy.close("short",when=longCondition) //Short exit (exit condition)+if longCondition+ strategy.close("short") //Short exit (exit condition)//strategy.entry("long", strategy.long,size,when=longCondition , comment="long" , alert_message = "long")⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L69:C0: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © SoftKill21-//@version=5+//@version=6strategy("EURUSD 1min strat RISK %% ", overlay=false, initial_capital = 1000)⋯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 |
|---|---|---|---|
| From Day | 1 | int · min 1 · max 31 | startDate |
| From Month | 6 | int · min 1 · max 12 | startDate |
| From Year | 2020 | int · min 1970 | startDate |
| To Day | 1 | int · min 1 · max 31 | finishDate |
| To Month | 12 | int · min 1 · max 12 | finishDate |
| To Year | 2020 | int · min 1970 | finishDate |
| Length (no label in the script) | 5 | int | vrsi |
| Over Sold (no label in the script) | 23 | int | co shortCondition |
| Over Bought (no label in the script) | 72 | int | cu longCondition |
| Fast Length | 12 | int (written input.integer) | fast_ma |
| Slow Length | 26 | int (written input.integer) | slow_ma |
| Source | close | source | fast_ma slow_ma |
| Signal Smoothing | 9 | int (written input.integer) · min 1 · max 50 | signal |
| Simple MA(Oscillator) | true | bool | fast_ma slow_ma |
| Simple MA(Signal Line) | true | bool | signal |
| Start (no label in the script) | 0.02 | float | SAR AF |
| Increment (no label in the script) | 0.02 | float | AF |
| Maximum (no label in the script) | 0.2 | float | AF |
| Length bb (no label in the script) | 17 | int · min 1 | basis_bb dev_bb shortCondition longCondition |
| Source | close | source | basis_bb dev_bb shortCondition longCondition |
| StdDev | 2.0 | float · min 0.001 · max 50 | dev_bb |
| Offset | 0 | int (written input.integer) · min -500 · max 500 | unused |
| Length | 10 | int · min 1 | out_ema shortCondition longCondition |
| Source | close | source | out_ema shortCondition longCondition |
| Offset | 0 | int (written input.integer) · min -500 · max 500 | unused |
| Average True Range Period | 14 | int | atr |
| Risk % | 2 | float | temp01 |
| Is this a 2 digit pair? (JPY, XAU, XPD... | false | bool | line 180 |
| Equity Protection % | 1 | float | line 185 |
| Equity TP % | 2 | float | line 189 |
| multi atr tp | 5 | float | target |
| multi atr sl | 5 | float | stop |
| SL X | 1 | int | temp02 exit exit_long exit exit_short |
| TP X | 1 | int | exit exit_long exit exit_short |
What it calculates
- RSI (
rsi,ta.rsiin v5)price, Length (5)vrsi · line 41 - Crossover (
crossover,ta.crossoverin v5)vrsi, Over Sold (23)co · line 42 - Crossunder (
crossunder,ta.crossunderin v5)vrsi, Over Bought (72)cu · line 43 - SMA / EMA (
sma,ta.smain v5)Source (close), Fast Length (12)fast_ma · line 59 - SMA / EMA (
sma,ta.smain v5)Source (close), Slow Length (26)slow_ma · line 60 - SMA / EMA (
sma,ta.smain v5)macd, Signal Smoothing (9)signal · line 62 - SMA (
sma,ta.smain v5)Source (close), Length bb (17)basis_bb · line 142 - Stdev (
stdev,ta.stdevin v5)Source (close), Length bb (17)dev_bb · line 143 - EMA (
ema,ta.emain v5)Source (close), Length (10)out_ema · line 155 - ATR (
atr,ta.atrin v5)Average True Range Period (14)atr · line 169
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 68 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 |
|---|---|---|---|
| Close equity_stopout | every bar | On | 200 |
| Open long long | longCondition and not is_open | On | 203 |
| Open short short | shortCondition and not is_open | On | 204 |
| Exit exit_long stop and limit | every bar | On | 206 |
| Close long | shortCondition(uptrend==false and crossunder(ema(src_ema, len_ema),sma(src_bb, length_bb)) and hist < 0 and vrsi < overSold) | On | 207 |
| Exit exit_short stop and limit | every bar | On | 208 |
| Close short | longCondition(uptrend==true and crossover(ema(src_ema, len_ema),sma(src_bb, length_bb)) and hist > 0 and vrsi > overBought ) | On | 209 |
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, and the live replay matched history.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +2,985,110.0% | +102.5% | 3 | 67% | 3.91 | 2,350,820.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −1,841,210.0% | +5.5% | 6 | 33% | 0.26 | 1,044,850.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −88,020.0% | +9.8% | 2 | 0% | 0.00 | 174,810.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −2,060.0% | +8.4% | 6 | 33% | 0.96 | 19,600.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +6,550.0% | +16.7% | 6 | 33% | 1.49 | 1,270.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −1,990.0% | +21.5% | 7 | 43% | 0.23 | 664.4% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −17,590.0% | +148.3% | 3 | 0% | 0.00 | 19,960.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +770.0% | +17.1% | 7 | 29% | 1.05 | 2,800.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 0 | — | $0.00 |
| Sideways market | 2 | 100% | $40,121,800.00 |
| Falling market | 1 | 0% | −$10,270,700.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
1,351,370.0%
The 95th percentile of the worst drawdown when the same 3 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 320.9% to 1,351,370.0%; the tick is what actually happened, 320.9%. Order luck alone moves it this much.
All 3 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 16 Jul 2024 64,724.10 | 17 Jul 2024 65,044.00 | 1 | $3,199,400.00 |
| short | 21 Jan 2026 88,427.70 | 22 Jan 2026 89,454.70 | 1 | −$10,270,700.00 |
| long | 20 Aug 2026 69,334.80 | 21 Aug 2026 73,027.00 | 1 | $36,922,400.00 |
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 |
|---|---|---|---|---|---|
| Full strategy AllinOne with risk management MACD RSI PSAR ATR MA this page | — | v4 strategy | +2,985,110.0% | 3 | 2,350,820.0% |
| [KL] Bollinger bands + RSI Strategy by DojiEmoji | sma stdev atr ema rsi | v4 strategy | +28.2% | 30 | 14.7% |
| [KL] Bollinger Bands Consolidation Strategy by DojiEmoji | sma stdev atr ema rsi | v4 strategy | +39.1% | 33 | 19.6% |
| 3 x EMA + Stochastic RSI + ATR by tomimarson | ema rsi sma atr | v4 strategy | −42.3% | 18 | 44.8% |
| Take Profit On Trend (by BHD_Trade_Bot) by BHD_Trade_Bot | ema rsi stdev sma | v4 strategy | +54.8% | 9 | 13.1% |
| Atrend by OTS by prim722 | ema rsi sma atr | v4 strategy | +12.1% | 76 | 34.4% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 44 ms | With a workaround 1,000 bars in 97 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 203, 204) so the engine trades the way the script says. 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/// © SoftKill21//@version=4strategy("EURUSD 1min strat RISK %% ", overlay=false, initial_capital = 1000)// BACKTESTING RANGE // From Date InputsfromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)fromMonth = input(defval = 6, title = "From Month", minval = 1, maxval = 12)fromYear = input(defval = 2020, title = "From Year", minval = 1970) // To Date InputstoDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)toMonth = input(defval = 12, title = "To Month", minval = 1, maxval = 12)toYear = input(defval = 2020, title = "To Year", minval = 1970) // Calculate start/end date and time conditionDST = 1 //day light saving for usa//--- EuropeLondon = iff(DST==0,"0000-0900","0100-1000")//--- AmericaNewYork = iff(DST==0,"0400-1500","0500-1600")//--- PacificSydney = iff(DST==0,"1300-2200","1400-2300")//--- AsiaTokyo = iff(DST==0,"1500-2400","1600-0100")//-- Time In Rangetimeinrange(res, sess) => time(res, sess) != 0london = timeinrange(timeframe.period, London)newyork = timeinrange(timeframe.period, NewYork)startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)finishDate = timestamp(toYear, toMonth, toDay, 00, 00)time_cond = time >= startDate and time <= finishDate and (london or newyork)// // // rsilength = input( 5 )overSold = input( 23 )overBought = input( 72 )price = closevrsi = rsi(price, length)co = crossover(vrsi, overSold)cu = crossunder(vrsi, overBought)// macdfast_length_macd = input(title="Fast Length", type=input.integer, defval=12)slow_length_macd = input(title="Slow Length", type=input.integer, defval=26)src_macd = input(title="Source", type=input.source, defval=close)signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=true)sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=true)// Plot colorscol_grow_above = #26A69Acol_grow_below = #FFCDD2col_fall_above = #B2DFDBcol_fall_below = #EF5350col_macd = #0094ffcol_signal = #ff6a00// Calculatingfast_ma = sma_source ? sma(src_macd, fast_length_macd) : ema(src_macd, fast_length_macd)slow_ma = sma_source ? sma(src_macd, slow_length_macd) : ema(src_macd, slow_length_macd)macd = fast_ma - slow_masignal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)hist = macd - signal//plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=0 )// sarstart = input(0.02)increment = input(0.02)maximum = input(0.2)var bool uptrend = navar float EP = navar float SAR = navar float AF = startvar float nextBarSAR = naif bar_index > 0 firstTrendBar = false SAR := nextBarSAR if bar_index == 1 float prevSAR = na float prevEP = na lowPrev = low[1] highPrev = high[1] closeCur = close closePrev = close[1] if closeCur > closePrev uptrend := true EP := high prevSAR := lowPrev prevEP := high else uptrend := false EP := low prevSAR := highPrev prevEP := low firstTrendBar := true SAR := prevSAR + start * (prevEP - prevSAR) if uptrend if SAR > low firstTrendBar := true uptrend := false SAR := max(EP, high) EP := low AF := start else if SAR < high firstTrendBar := true uptrend := true SAR := min(EP, low) EP := high AF := start if not firstTrendBar if uptrend if high > EP EP := high AF := min(AF + increment, maximum) else if low < EP EP := low AF := min(AF + increment, maximum) if uptrend SAR := min(SAR, low[1]) if bar_index > 1 SAR := min(SAR, low[2]) else SAR := max(SAR, high[1]) if bar_index > 1 SAR := max(SAR, high[2]) nextBarSAR := SAR + AF * (EP - SAR) //plot(SAR, style=plot.style_cross, linewidth=3, color=color.orange)//plot(nextBarSAR, style=plot.style_cross, linewidth=3, color=color.aqua)//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)//bblength_bb = input(17, minval=1)src_bb = input(close, title="Source")mult_bb = input(2.0, minval=0.001, maxval=50, title="StdDev")basis_bb = sma(src_bb, length_bb)dev_bb = mult_bb * stdev(src_bb, length_bb)upper_bb = basis_bb + dev_bblower_bb = basis_bb - dev_bboffset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)//plot(basis_bb, "Basis", color=#872323, offset = offset)//p1_bb = plot(upper_bb, "Upper", color=color.teal, offset = offset)//p2_bb = plot(lower_bb, "Lower", color=color.teal, offset = offset)//fill(p1_bb, p2_bb, title = "Background", color=#198787, transp=95)//emalen_ema = input(10, minval=1, title="Length")src_ema = input(close, title="Source")offset_ema = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)out_ema = ema(src_ema, len_ema)//plot(out_ema, title="EMA", color=color.blue, offset=offset_ema) //out_ema e emaul//basis_bb e middle de la bb//hist e histograma// rsi cu band0 cross pt rsi// confirmareashortCondition = (uptrend==false and crossunder(ema(src_ema, len_ema),sma(src_bb, length_bb)) and hist < 0 and vrsi < overSold) //and time_condlongCondition = (uptrend==true and crossover(ema(src_ema, len_ema),sma(src_bb, length_bb)) and hist > 0 and vrsi > overBought ) //and time_cond//tp=input(0.0025,type=input.float, title="tp")//sl=input(0.001,type=input.float, title="sl")//INDICATOR--------------------------------------------------------------------- //Average True Range (1. RISK)atr_period = input(14, "Average True Range Period")atr = atr(atr_period)//MONEY MANAGEMENT--------------------------------------------------------------balance = strategy.netprofit + strategy.initial_capital //current balancefloating = strategy.openprofit //floating profit/lossrisk = input(2,type=input.float,title="Risk %")/100 //risk % per tradeisTwoDigit = input(false,"Is this a 2 digit pair? (JPY, XAU, XPD...")equity_protector = input(1 ,type=input.float, title="Equity Protection %")/100 //equity protection %equity_protectorTP = input(2 ,type=input.float, title="Equity TP %")/100 //equity protection %multtp = input(5,type=input.float, title="multi atr tp")multsl = input(5,type=input.float, title="multi atr sl")stop = atr*100000*input(1,"SL X")* multsl //Stop levelif(isTwoDigit) stop := stop/100target = atr*100000*input(1,"TP X")*multtp //Stop level //Calculate current DD and determine if stopout is necessaryequity_stopout = falseif(floating<0 and abs(floating/balance)>equity_protector) equity_stopout := true equity_stopout2 = falseif(floating>0 and abs(floating/balance)>equity_protectorTP) equity_stopout2 := true //Calculate the size of the next tradetemp01 = balance * risk //Risk in USDtemp02 = temp01/stop //Risk in lotstemp03 = temp02*100000 //Convert to contractssize = temp03 - temp03%1000 //Normalize to 1000s (Trade size)if(size < 10000) size := 10000 //Set min. lot size//TRADE EXECUTION---------------------------------------------------------------strategy.close_all(equity_stopout, comment="equity sl", alert_message = "equity_sl") //Close all trades w/equity protector//strategy.close_all(equity_stopout2, comment="equity tp", alert_message = "equity_tp") //Close all trades w/equity protectoris_open = strategy.opentrades > 0strategy.entry("long",true,size,oca_name="a",oca_type=strategy.oca.cancel,when=longCondition and not is_open) //Long entrystrategy.entry("short",false,size,oca_name="a",oca_type=strategy.oca.cancel,when=shortCondition and not is_open) //Short entry strategy.exit("exit_long","long",loss=stop, profit=target) //Long exit (stop loss)strategy.close("long",when=shortCondition) //Long exit (exit condition)strategy.exit("exit_short","short",loss=stop, profit=target) //Short exit (stop loss)strategy.close("short",when=longCondition) //Short exit (exit condition)//strategy.entry("long", strategy.long,size,when=longCondition , comment="long" , alert_message = "long")//strategy.entry("short", strategy.short, size,when=shortCondition , comment="short" , alert_message = "short") //strategy.exit("closelong", "long" , profit = close * tp / syminfo.mintick, alert_message = "closelong")//strategy.exit("closeshort", "short" , profit = close * tp / syminfo.mintick, alert_message = "closeshort") //strategy.exit("closelong", "long" ,size, profit = close * tp / syminfo.mintick, loss = close * sl / syminfo.mintick, alert_message = "closelong")//strategy.exit("closeshort", "short" , size, profit = close * tp / syminfo.mintick, loss = close * sl / syminfo.mintick, alert_message = "closeshort") //strategy.close("long" , when=not (time_cond), comment="time", alert_message = "closelong" )//strategy.close("short" , when=not (time_cond), comment="time", alert_message = "closeshort")//strategy.close_all(when=not (time_cond), comment ='time')