Pine Script v4 · Strategy
R19 STRATEGY
A Pine Script v4 strategy built on ATR (14), Change (symHigh) and RMA (tr, len). It has 4 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. 21 settings; defaults include Symbol BINANCE:BTCUSDT, Strategy Decision Time Frame 60 and ADX Smoothing 14.
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 R19 STRATEGY repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did R19 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 entry conditions never all held on this data. It closed no trades on the other markets either. A backtest, not investment advice.
- Can R19 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 R19 STRATEGY use a stop loss?
- Yes
- strategy.exit sets a stop on line 132, 135.
- Does R19 STRATEGY run in Zeal Terminal?
- Yes
- It compiles in 36 ms and runs 1,000 bars in 95 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs BINANCE:BTCUSDT 60 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Values that depend on it are empty on this chart.
- 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.
-
Likely bug
sma(simRSI, 50) ignores the settings line 68
Line 68 hard-codes 50 where line 68 uses “SMA Look Back Candles”. Changing those settings moves one band but not this one.
sma (simRSI , 50)sma(simRSI, smaLookback) -
Likely bug
sma(simRSI, 50) ignores the settings line 69
Line 69 hard-codes 50 where line 68 uses “SMA Look Back Candles”. Changing those settings moves one band but not this one.
sma (simRSI , 50)sma(simRSI, smaLookback) -
Likely bug
sma(simRSI, 50) ignores the settings line 85
Line 85 hard-codes 50 where line 68 uses “SMA Look Back Candles”. Changing those settings moves one band but not this one.
sma (simRSI , 50)sma(simRSI, smaLookback) -
Likely bug
sma(simRSI, 50) ignores the settings line 87
Line 87 hard-codes 50 where line 68 uses “SMA Look Back Candles”. Changing those settings moves one band but not this one.
sma (simRSI , 50)sma(simRSI, smaLookback) -
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.
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 security → request.security, atr → ta.atr, change → ta.change, rma → ta.rma, abs → math.abs, ema → ta.ema, highest → ta.highest, lowest → ta.lowest, rsi → ta.rsi, crossover → ta.crossover, sma → ta.sma, crossunder → ta.crossunder, max → math.max, min → math.min.
v4 → v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 3: //@version=4 → //@version=5
- Line 5: input(type = input.symbol) → input.symbol()
- Line 6: input(type = input.resolution) → input.timeframe()
- Line 36: security → request.security
- Line 37: security → request.security
- Line 38: security → request.security
36 more edits
- Line 39: atr → ta.atr
- Line 42: change → ta.change
- Line 43: change → ta.change
- Line 46: rma → ta.rma
- Line 46: tr → ta.tr
- Line 47: rma → ta.rma
- Line 48: rma → ta.rma
- Line 53: rma → ta.rma
- Line 53: abs → math.abs
- Line 55: ema → ta.ema
- Line 57: ema → ta.ema
- Line 57: ema → ta.ema
- Line 58: ema → ta.ema
- Line 59: highest → ta.highest
- Line 60: lowest → ta.lowest
- Line 61: rsi → ta.rsi
- Line 62: lowest → ta.lowest
- Line 62: highest → ta.highest
- Line 62: lowest → ta.lowest
- Line 63: lowest → ta.lowest
- Line 63: highest → ta.highest
- Line 63: lowest → ta.lowest
- Line 68: crossover → ta.crossover
- Line 68: sma → ta.sma
- Line 68: sma → ta.sma
- Line 69: crossunder → ta.crossunder
- Line 69: sma → ta.sma
- Line 69: sma → ta.sma
- Line 71: crossover → ta.crossover
- Line 73: crossunder → ta.crossunder
- Line 78: sma → ta.sma
- Line 80: sma → ta.sma
- Line 85: sma → ta.sma
- Line 87: sma → ta.sma
- Line 123: max → math.max
- Line 128: min → math.min
⋯// © onurenginogutcu-//@version=4+//@version=5strategy("R19 STRATEGY", overlay=true, calc_on_every_tick=true , margin_long=100, margin_short=100 , process_orders_on_close=true )-sym = input(title="Symbol", type=input.symbol, defval="BINANCE:BTCUSDT" , group = "SYMBOL") +sym = input.symbol(title="Symbol", defval="BINANCE:BTCUSDT" , group = "SYMBOL") -timeFrame = input(title="Strategy Decision Time Frame", type = input.resolution , defval="60")+timeFrame = input.timeframe(title="Strategy Decision Time Frame" , defval="60")adxlen = input(14, title="ADX Smoothing" , group = "ADX")⋯ -symClose = security(sym, timeFrame, close)+symClose = request.security(sym, timeFrame, close)-symHigh = security(sym, timeFrame, high)+symHigh = request.security(sym, timeFrame, high)-symLow = security(sym, timeFrame, low)+symLow = request.security(sym, timeFrame, low)-atr = atr (14) +atr = ta.atr (14) /////////adx codedirmov(len) =>- up = change(symHigh)+ up = ta.change(symHigh)- down = -change(symLow)+ down = -ta.change(symLow) plusDM = na(up) ? na : (up > down and up > 0 ? up : 0) minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)- truerange = rma(tr, len)+ truerange = ta.rma(ta.tr, len)- plus = fixnan(100 * rma(plusDM, len) / truerange)+ plus = fixnan(100 * ta.rma(plusDM, len) / truerange)- minus = fixnan(100 * rma(minusDM, len) / truerange)+ minus = fixnan(100 * ta.rma(minusDM, len) / truerange) [plus, minus]⋯ sum = plus + minus- adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)+ adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)sig = adx(dilen, adxlen)-emasig = ema (sig , adxemalenght )+emasig = ta.ema (sig , adxemalenght )////////adx code over-i = ema (symClose , MACDFast) - ema (symClose , MACDSlow) +i = ta.ema (symClose , MACDFast) - ta.ema (symClose , MACDSlow) -r = ema (i , MACDSmooth)+r = ta.ema (i , MACDSmooth)-sapust = highest (i , MACDLookback) * 0.729 +sapust = ta.highest (i , MACDLookback) * 0.729 -sapalt = lowest (i , MACDLookback) * 0.729 +sapalt = ta.lowest (i , MACDLookback) * 0.729 -simRSI = rsi (symClose , 50 ) +simRSI = ta.rsi (symClose , 50 ) -fibtop = lowest (symLow , fibvar) + ((highest (symHigh , fibvar) - lowest (symLow , fibvar)) * 0.50)+fibtop = ta.lowest (symLow , fibvar) + ((ta.highest (symHigh , fibvar) - ta.lowest (symLow , fibvar)) * 0.50)-fibbottom = lowest (symLow , fibvar) + ((highest (symHigh , fibvar) - lowest (symLow , fibvar)) * 0.50)+fibbottom = ta.lowest (symLow , fibvar) + ((ta.highest (symHigh , fibvar) - ta.lowest (symLow , fibvar)) * 0.50)cond1 = 0⋯cond4 = 0-longCondition = crossover(i, r) and i < sapalt and sig > adxconstant and symClose < sma (symClose , smaLookback) and simRSI < sma (simRSI , 50) and symClose < fibbottom +longCondition = ta.crossover(i, r) and i < sapalt and sig > adxconstant and symClose < ta.sma (symClose , smaLookback) and simRSI < ta.sma (simRSI , 50) and symClose < fibbottom -shortCondition = crossunder(i, r) and i > sapust and sig > adxconstant and symClose > sma (symClose , smaLookback) and simRSI > sma (simRSI , 50) and symClose > fibtop +shortCondition = ta.crossunder(i, r) and i > sapust and sig > adxconstant and symClose > ta.sma (symClose , smaLookback) and simRSI > ta.sma (simRSI , 50) and symClose > fibtop //////////////////////probability long/short-if (crossover(i, r) and i < sapalt)+if (ta.crossover(i, r) and i < sapalt) cond1 := 35-else if (crossunder(i, r) and i > sapust)+else if (ta.crossunder(i, r) and i > sapust) cond1 := -35⋯ -if (symClose < sma (symClose , smaLookback))+if (symClose < ta.sma (symClose , smaLookback)) cond2 := 30-else if (symClose > sma (symClose , smaLookback))+else if (symClose > ta.sma (symClose , smaLookback)) cond2 := -30⋯ -if (simRSI < sma (simRSI , 50))+if (simRSI < ta.sma (simRSI , 50)) cond3 := 25-else if (simRSI > sma (simRSI , 50))+else if (simRSI > ta.sma (simRSI , 50)) cond3 := -25⋯ stopMeasure = close * (1 - trailingStopLong)- max (stopMeasure , trailingLongPrice [1])+ math.max (stopMeasure , trailingLongPrice [1])else if strategy.position_size > 0 and startTrail == 0⋯ stopMeasure = close * (1 + trailingStopShort)- min (stopMeasure , trailingShortPrice [1])+ math.min (stopMeasure , trailingShortPrice [1])else if strategy.position_size < 0 and startTrail == 0⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 7: input() → input.int()
- Line 8: input() → input.int()
- Line 9: input() → input.int()
- Line 10: input() → input.int()
- Line 11: input() → input.int()
- Line 12: input() → input.int()
13 more edits
- Line 13: input() → input.int()
- Line 14: input() → input.int()
- Line 15: input() → input.int()
- Line 16: input() → input.int()
- Line 17: input() → input.float()
- Line 18: input() → input.float()
- Line 19: input() → input.float()
- Line 20: input() → input.float()
- Line 21: input() → input.float()
- Line 24: input() → input.float()
- Line 27: input() → input.int()
- Line 30: input() → input.int()
- Line 33: input() → input.int()
⋯timeFrame = input.timeframe(title="Strategy Decision Time Frame" , defval="60")-adxlen = input(14, title="ADX Smoothing" , group = "ADX")+adxlen = input.int(14, title="ADX Smoothing" , group = "ADX")-dilen = input(14, title="ADX DI Length", group = "ADX")+dilen = input.int(14, title="ADX DI Length", group = "ADX")-adxemalenght = input(30, title="ADX EMA", group = "ADX")+adxemalenght = input.int(30, title="ADX EMA", group = "ADX")-adxconstant = input(19, title="ADX CONSTANT", group = "ADX")+adxconstant = input.int(19, title="ADX CONSTANT", group = "ADX")-fibvar = input (title = "Fibo Look Back Canles" , defval = 50 , minval = 0 , group = "FIBO MACD SMA")+fibvar = input.int (title = "Fibo Look Back Canles" , defval = 50 , minval = 0 , group = "FIBO MACD SMA")-smaLookback = input (title = "SMA Look Back Candles" , defval = 30 , minval = 0 , group = "FIBO MACD SMA")+smaLookback = input.int (title = "SMA Look Back Candles" , defval = 30 , minval = 0 , group = "FIBO MACD SMA")-MACDFast = input (title = "MACD Fast Lenght" , defval = 15 , minval = 0 , group = "FIBO MACD SMA")+MACDFast = input.int (title = "MACD Fast Lenght" , defval = 15 , minval = 0 , group = "FIBO MACD SMA")-MACDSlow = input (title = "MACD Slow Lenght" , defval = 30 , minval = 0 , group = "FIBO MACD SMA")+MACDSlow = input.int (title = "MACD Slow Lenght" , defval = 30 , minval = 0 , group = "FIBO MACD SMA")-MACDSmooth = input (title = "MACD Signal Smoothing" , defval = 9 , minval = 0 , group = "FIBO MACD SMA")+MACDSmooth = input.int (title = "MACD Signal Smoothing" , defval = 9 , minval = 0 , group = "FIBO MACD SMA")-MACDLookback = input (title = "MACD Look Back Candles" , defval = 100 , minval = 0 , group = "FIBO MACD SMA")+MACDLookback = input.int (title = "MACD Look Back Candles" , defval = 100 , minval = 0 , group = "FIBO MACD SMA")-trailingStopLong = input (title = "Trailing Long Stop %" , defval = 2.0 , step = 0.1, group = "TP & SL") * 0.01+trailingStopLong = input.float (title = "Trailing Long Stop %" , defval = 2.0 , step = 0.1, group = "TP & SL") * 0.01-trailingStopShort = input (title = "Trailing Short Stop %" , defval = 2.0 , step = 0.1 , group = "TP & SL") * 0.01+trailingStopShort = input.float (title = "Trailing Short Stop %" , defval = 2.0 , step = 0.1 , group = "TP & SL") * 0.01-LongTrailingProfitStart = input (title = "Long Profit Start %" , defval = 2.0 , step = 0.1 , group = "TP & SL") * 0.01+LongTrailingProfitStart = input.float (title = "Long Profit Start %" , defval = 2.0 , step = 0.1 , group = "TP & SL") * 0.01-ShortTrailingProfitStart = input (title = "Short Profit Start %" , defval = 2.0 , step = 0.1, group = "TP & SL") * 0.01+ShortTrailingProfitStart = input.float (title = "Short Profit Start %" , defval = 2.0 , step = 0.1, group = "TP & SL") * 0.01-lsl = input(title="Max Long Stop Loss (%)",+lsl = input.float(title="Max Long Stop Loss (%)", minval=0.0, step=0.1, defval=3.0, group = "TP & SL") * 0.01 -ssl = input(title="Max Short Stop Loss (%)",+ssl = input.float(title="Max Short Stop Loss (%)", minval=0.0, step=0.1, defval=2.5, group = "TP & SL") * 0.01 -longtp = input(title="Long Take Profit (%)",+longtp = input.int(title="Long Take Profit (%)", minval=0.0, step=0.1, defval=100, group = "TP & SL") * 0.01 -shorttp = input(title="Short Take Profit (%)",+shorttp = input.int(title="Short Take Profit (%)", minval=0.0, step=0.1, defval=100, group = "TP & SL") * 0.01 -capperc = input(title="Capital Percentage to Invest (%)",+capperc = input.int(title="Capital Percentage to Invest (%)", minval=0.0, maxval=100, step=0.1, defval=95, group = "CAPITAL TO INVEST") * 0.01⋯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.
⋯// © onurenginogutcu-//@version=5+//@version=6strategy("R19 STRATEGY", overlay=true, calc_on_every_tick=true , margin_long=100, margin_short=100 , process_orders_on_close=true )⋯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 |
|---|---|---|---|
| SYMBOL | |||
| Symbol | BINANCE:BTCUSDT | symbol | symClose symHigh symLow |
| Strategy Decision Time Frame | 60 | timeframe (written input.resolution) | symClose symHigh symLow |
| ADX | |||
| ADX Smoothing | 14 | int | adx sig |
| ADX DI Length | 14 | int | plus minus sig |
| ADX EMA | 30 | int | emasig |
| ADX CONSTANT | 19 | int | longCondition shortCondition |
| FIBO MACD SMA | |||
| Fibo Look Back Canles | 50 | int · min 0 | fibtop fibbottom |
| SMA Look Back Candles | 30 | int · min 0 | longCondition shortCondition line 78 line 80 |
| MACD Fast Lenght | 15 | int · min 0 | i |
| MACD Slow Lenght | 30 | int · min 0 | i |
| MACD Signal Smoothing | 9 | int · min 0 | r |
| MACD Look Back Candles | 100 | int · min 0 | sapust sapalt |
| TP & SL | |||
| Trailing Long Stop % | 2.0 | float · step 0.1 | trailingLongPrice stopMeasure |
| Trailing Short Stop % | 2.0 | float · step 0.1 | trailingShortPrice stopMeasure |
| Long Profit Start % | 2.0 | float · step 0.1 | line 116 |
| Short Profit Start % | 2.0 | float · step 0.1 | line 118 |
| Max Long Stop Loss (%) | 3.0 | float · min 0.0 · step 0.1 | trailingLongPrice |
| Max Short Stop Loss (%) | 2.5 | float · min 0.0 · step 0.1 | trailingShortPrice |
| Long Take Profit (%) | 100 | int · min 0.0 · step 0.1 | exit Exit Long |
| Short Take Profit (%) | 100 | int · min 0.0 · step 0.1 | exit Exit Short |
| CAPITAL TO INVEST | |||
| Capital Percentage to Invest (%) | 95 | int · min 0.0 · max 100 · step 0.1 | entry Long entry Short |
What it calculates
- ATR (
atr,ta.atrin v5)14atr · line 39 - Change (
change,ta.changein v5)symHighup · line 42 - Change (
change,ta.changein v5)symLowdown · line 43 - RMA (
rma,ta.rmain v5)tr, lentruerange · line 46 - RMA (
rma,ta.rmain v5)abs(plus - minus) / (sum == 0 ? 1 : sum), ADX Smoothing (14)adx · line 53 - EMA (
ema,ta.emain v5)sig, ADX EMA (30)emasig · line 55 - EMA (
ema,ta.emain v5)symClose, MACD Fast Lenght (15)i · line 57 - EMA (
ema,ta.emain v5)i, MACD Signal Smoothing (9)r · line 58 - Highest (
highest,ta.highestin v5)i, MACD Look Back Candles (100)sapust · line 59 - Lowest (
lowest,ta.lowestin v5)i, MACD Look Back Candles (100)sapalt · line 60 - RSI (
rsi,ta.rsiin v5)symClose, 50simRSI · line 61 - Lowest / Highest (
lowest,ta.lowestin v5)symLow, Fibo Look Back Canles (50)fibtop · line 62 - Lowest / Highest (
lowest,ta.lowestin v5)symLow, Fibo Look Back Canles (50)fibbottom · line 63
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | (longCondition and strategy.position_size == 0) | On | 106 |
| Open Short short | (shortCondition and strategy.position_size == 0) | On | 108 |
| Exit Exit Long stop and limit | (strategy.position_size > 0) | On | 132 |
| Exit Exit Short stop and limit | (strategy.position_size < 0) | On | 135 |
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 data3 security call(s), none with lookahead on.
- 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
Not run on other markets: the script requests BINANCE:BTCUSDT 60, and that data is not available here (a lower timeframe than the chart; the engine does not evaluate intrabar data). Its results would rest on empty values.
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 |
|---|---|---|---|---|---|
| R19 STRATEGY this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| M0PB (Momentum Pullback) by Marcns_ | rsi ema highest lowest atr | v5 strategy | +51.3% | 3 | 17.5% |
| Jigga - Survival Level by jigneshjc | rma highest lowest ema atr | v5 strategy | No trades on this market | ||
| Strategy Myth-Busting #8 - TrendSurfers+TrendOsc - [MYN] by myncrypto | highest lowest atr ema rma | v5 strategy | No trades on this market | ||
| Richard's Strategy by Deepak8369 | highest lowest atr ema | v4 strategy | +34.6% | 70 | 26.3% |
| STRATEGY R18-F-BTC by SenatorVonShaft | ema highest lowest rsi | v4 strategy | −8.6% | 11 | 14.4% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 36 ms | Yes 1,000 bars in 95 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/// © onurenginogutcu//@version=4strategy("R19 STRATEGY", overlay=true, calc_on_every_tick=true , margin_long=100, margin_short=100 , process_orders_on_close=true )sym = input(title="Symbol", type=input.symbol, defval="BINANCE:BTCUSDT" , group = "SYMBOL") timeFrame = input(title="Strategy Decision Time Frame", type = input.resolution , defval="60")adxlen = input(14, title="ADX Smoothing" , group = "ADX")dilen = input(14, title="ADX DI Length", group = "ADX")adxemalenght = input(30, title="ADX EMA", group = "ADX")adxconstant = input(19, title="ADX CONSTANT", group = "ADX")fibvar = input (title = "Fibo Look Back Canles" , defval = 50 , minval = 0 , group = "FIBO MACD SMA")smaLookback = input (title = "SMA Look Back Candles" , defval = 30 , minval = 0 , group = "FIBO MACD SMA")MACDFast = input (title = "MACD Fast Lenght" , defval = 15 , minval = 0 , group = "FIBO MACD SMA")MACDSlow = input (title = "MACD Slow Lenght" , defval = 30 , minval = 0 , group = "FIBO MACD SMA")MACDSmooth = input (title = "MACD Signal Smoothing" , defval = 9 , minval = 0 , group = "FIBO MACD SMA")MACDLookback = input (title = "MACD Look Back Candles" , defval = 100 , minval = 0 , group = "FIBO MACD SMA")trailingStopLong = input (title = "Trailing Long Stop %" , defval = 2.0 , step = 0.1, group = "TP & SL") * 0.01trailingStopShort = input (title = "Trailing Short Stop %" , defval = 2.0 , step = 0.1 , group = "TP & SL") * 0.01LongTrailingProfitStart = input (title = "Long Profit Start %" , defval = 2.0 , step = 0.1 , group = "TP & SL") * 0.01ShortTrailingProfitStart = input (title = "Short Profit Start %" , defval = 2.0 , step = 0.1, group = "TP & SL") * 0.01lsl = input(title="Max Long Stop Loss (%)", minval=0.0, step=0.1, defval=3.0, group = "TP & SL") * 0.01 ssl = input(title="Max Short Stop Loss (%)", minval=0.0, step=0.1, defval=2.5, group = "TP & SL") * 0.01 longtp = input(title="Long Take Profit (%)", minval=0.0, step=0.1, defval=100, group = "TP & SL") * 0.01 shorttp = input(title="Short Take Profit (%)", minval=0.0, step=0.1, defval=100, group = "TP & SL") * 0.01 capperc = input(title="Capital Percentage to Invest (%)", minval=0.0, maxval=100, step=0.1, defval=95, group = "CAPITAL TO INVEST") * 0.01 symClose = security(sym, timeFrame, close)symHigh = security(sym, timeFrame, high)symLow = security(sym, timeFrame, low)atr = atr (14) /////////adx codedirmov(len) => up = change(symHigh) down = -change(symLow) plusDM = na(up) ? na : (up > down and up > 0 ? up : 0) minusDM = na(down) ? na : (down > up and down > 0 ? down : 0) truerange = rma(tr, len) plus = fixnan(100 * rma(plusDM, len) / truerange) minus = fixnan(100 * rma(minusDM, len) / truerange) [plus, minus]adx(dilen, adxlen) => [plus, minus] = dirmov(dilen) sum = plus + minus adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)sig = adx(dilen, adxlen)emasig = ema (sig , adxemalenght )////////adx code overi = ema (symClose , MACDFast) - ema (symClose , MACDSlow) r = ema (i , MACDSmooth)sapust = highest (i , MACDLookback) * 0.729 sapalt = lowest (i , MACDLookback) * 0.729 simRSI = rsi (symClose , 50 ) fibtop = lowest (symLow , fibvar) + ((highest (symHigh , fibvar) - lowest (symLow , fibvar)) * 0.50)fibbottom = lowest (symLow , fibvar) + ((highest (symHigh , fibvar) - lowest (symLow , fibvar)) * 0.50)cond1 = 0cond2 = 0cond3 = 0cond4 = 0longCondition = crossover(i, r) and i < sapalt and sig > adxconstant and symClose < sma (symClose , smaLookback) and simRSI < sma (simRSI , 50) and symClose < fibbottom shortCondition = crossunder(i, r) and i > sapust and sig > adxconstant and symClose > sma (symClose , smaLookback) and simRSI > sma (simRSI , 50) and symClose > fibtop //////////////////////probability long/shortif (crossover(i, r) and i < sapalt) cond1 := 35else if (crossunder(i, r) and i > sapust) cond1 := -35else cond1 := 0 if (symClose < sma (symClose , smaLookback)) cond2 := 30else if (symClose > sma (symClose , smaLookback)) cond2 := -30else cond2 := 0 if (simRSI < sma (simRSI , 50)) cond3 := 25else if (simRSI > sma (simRSI , 50)) cond3 := -25else cond3 := 0 if (symClose < fibbottom) cond4 := 10else if (symClose > fibbottom) cond4 := -10else cond4 := 0 probab = cond1 + cond2 + cond3 + cond4///////////////////////////////////////////////////////////////////////////////////////////////////////////STRATEGY ENTRIES AND STOP LOSSES /////var startTrail = 0var trailingLongPrice = 0.0var trailingShortPrice = 0.0if (longCondition and strategy.position_size == 0) strategy.entry("Long", strategy.long , qty = capperc * strategy.equity / close )if (shortCondition and strategy.position_size == 0) strategy.entry("Short" , strategy.short , qty = capperc * strategy.equity / close ) if (strategy.position_size == 0) trailingShortPrice := 0.0 trailingLongPrice := 0.0 startTrail := 0/////////////////////////////////strategy exitif (strategy.position_size > 0 and close >= strategy.position_avg_price * (1 + LongTrailingProfitStart)) startTrail := 1if (strategy.position_size < 0 and close <= strategy.position_avg_price * (1 - ShortTrailingProfitStart)) startTrail := -1 trailingLongPrice := if strategy.position_size > 0 and startTrail == 1 stopMeasure = close * (1 - trailingStopLong) max (stopMeasure , trailingLongPrice [1])else if strategy.position_size > 0 and startTrail == 0 strategy.position_avg_price * (1 - lsl)trailingShortPrice := if strategy.position_size < 0 and startTrail == -1 stopMeasure = close * (1 + trailingStopShort) min (stopMeasure , trailingShortPrice [1])else if strategy.position_size < 0 and startTrail == 0 strategy.position_avg_price * (1 + ssl)if (strategy.position_size > 0) strategy.exit("Exit Long", "Long", stop = trailingLongPrice , limit=strategy.position_avg_price*(1 + longtp)) if (strategy.position_size < 0) strategy.exit("Exit Short", "Short", stop = trailingShortPrice , limit=strategy.position_avg_price*(1 - shorttp))////////////////////////vertical colouring signalsbgcolor(color=longCondition ? color.new (color.green , 70) : na)bgcolor(color=shortCondition ? color.new (color.red , 70) : na)plot (trailingLongPrice , color = color.green) ///long price trailing stopplot (trailingShortPrice , color = color.red) /// short price trailing stopplot (startTrail , color = color.yellow)plot (probab , color = color.white) ////probability