Pine Script v4 · Strategy
PMax on Rsi w-T3 -Strategy-
A Pine Script v4 strategy built on SMA (i, 14), EMA (rsi, 8) and Crossover (MAvg, PMax). It has 2 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 17 settings; defaults include Source hl2, ATR Multiplier 3 and Tillson T3 Length 8.
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 PMax on Rsi w-T3 -Strategy- repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 5 of 5 trades.
- How did PMax on Rsi w-T3 -Strategy- do on BTCUSDT 1D with default settings?
- −10.55%
- From 26 Jan 2024 to 21 Oct 2026, over 12 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can PMax on Rsi w-T3 -Strategy- 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.
- What alerts does PMax on Rsi w-T3 -Strategy- have?
- 6
- Cross Alert; Crossover Alarm; Crossunder Alarm; Price Cross Alert; and more.
- Does PMax on Rsi w-T3 -Strategy- use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
BTCUSDT · 1D · default settings
- RSI
- Upper Band
- Lower Band
- T3
- PMax
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −10.55%
- −$10,552.80
- Buy and hold
- +102.5%
- same period
- Closed trades
- 12
- 6 won · 6 lost
- Profitable
- 50.0%
- of closed trades
- Profit factor
- 0.86
- gross profit ÷ gross loss
- Max drawdown
- 63.65%
- −$85,426.60
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A short position was still open at the last bar. 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
1 setting does nothing
“=Backtest Inputs=” is declared but never read.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 101, 103. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 47
transp = on line 47, 73, 81, 83. v5 folds the transparency into the colour with color.new(c, transp).
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 sma → ta.sma, max → math.max, abs → math.abs, ema → ta.ema, min → math.min, cross → ta.cross, crossover → ta.crossover, crossunder → ta.crossunder.
- 2 strategy calls use the when = argument (line 101, 103). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 12 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 1: //@version=4 → //@version=5
- Line 8: input(type = input.float) → input.float()
- Line 11: input(type = input.integer) → input.int()
- Line 13: input(type = input.bool) → input.bool()
- Line 14: input(type = input.bool) → input.bool()
- Line 15: input(type = input.bool) → input.bool()
27 more edits
- Line 16: input(type = input.bool) → input.bool()
- Line 26: sma → ta.sma
- Line 27: sma → ta.sma
- Line 42: max → math.max
- Line 42: abs → math.abs
- Line 42: abs → math.abs
- Line 43: sma → ta.sma
- Line 47: transp = 90 → color.new(#9915FF, 90)
- Line 48: ema → ta.ema
- Line 49: ema → ta.ema
- Line 50: ema → ta.ema
- Line 51: ema → ta.ema
- Line 52: ema → ta.ema
- Line 53: ema → ta.ema
- Line 63: max → math.max
- Line 66: min → math.min
- Line 73: transp = 0 → color.new(color.red, 0)
- Line 74: cross → ta.cross
- Line 75: crossover → ta.crossover
- Line 76: crossunder → ta.crossunder
- Line 77: cross → ta.cross
- Line 78: crossover → ta.crossover
- Line 79: crossunder → ta.crossunder
- Line 80: crossover → ta.crossover
- Line 81: transp = 0 → color.new(color.green, 0)
- Line 82: crossunder → ta.crossunder
- Line 83: transp = 0 → color.new(color.red, 0)
-//@version=4+//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯src = input(hl2, title="Source")-Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3)+Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3)length =input(8, "Tillson T3 Length", minval=1)T3a1 = input(0.7, "TILLSON T3 Volume Factor", step=0.1)-Periods = input(10,title="ATR Length", type=input.integer)+Periods = input.int(10,title="ATR Length")rsilength = input(14, minval=1, title="RSI Length")-showrsi = input(title="Show RSI?", type=input.bool, defval=true)+showrsi = input.bool(title="Show RSI?", defval=true)-showsupport = input(title="Show Moving Average?", type=input.bool, defval=true)+showsupport = input.bool(title="Show Moving Average?", defval=true)-showsignalsk = input(title="Show Crossing Signals?", type=input.bool, defval=true)+showsignalsk = input.bool(title="Show Crossing Signals?", defval=true)-highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)+highlighting = input.bool(title="Highlighter On/Off ?", defval=true)i = close>=close[1] ? close-close[1] : 0⋯AvDown = Wwma_Func(i2,rsilength)-AvgUp = sma(i,rsilength)+AvgUp = ta.sma(i,rsilength)-AvgDown =sma(i2,rsilength)+AvgDown =ta.sma(i2,rsilength)k1 = high>close[1] ? high-close[1] : 0⋯rsil= rsl==-1 ? 0 : (100-(100/(1+rsl)))-TR=max(rsih-rsil,abs(rsih-rsi[1]),abs(rsil-rsi[1]))+TR=math.max(rsih-rsil,math.abs(rsih-rsi[1]),math.abs(rsil-rsi[1]))-atr=sma(TR,Periods)+atr=ta.sma(TR,Periods)plot(showrsi ? rsi : na, "RSI", color=#8E1599)⋯band0 = hline(30, "Lower Band", color=#C0C0C0)-fill(band1, band0, color=#9915FF, transp=90, title="Background")+fill(band1, band0, color=color.new(#9915FF, 90), title="Background")-T3e1=ema(rsi, length)+T3e1=ta.ema(rsi, length)-T3e2=ema(T3e1,length)+T3e2=ta.ema(T3e1,length)-T3e3=ema(T3e2,length)+T3e3=ta.ema(T3e2,length)-T3e4=ema(T3e3,length)+T3e4=ta.ema(T3e3,length)-T3e5=ema(T3e4,length)+T3e5=ta.ema(T3e4,length)-T3e6=ema(T3e5,length)+T3e6=ta.ema(T3e5,length)T3c1=-T3a1*T3a1*T3a1⋯ longStopPrev = nz(longStop[1], longStop)- longStop := MAvg > longStopPrev ? max(longStop, longStopPrev) : longStop+ longStop := MAvg > longStopPrev ? math.max(longStop, longStopPrev) : longStop shortStop = MAvg + Multiplier*atr shortStopPrev = nz(shortStop[1], shortStop)- shortStop := MAvg < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop+ shortStop := MAvg < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop dir = 1⋯plot(showsupport ? MAvg : na, color=color.black, linewidth=2, title="T3")-pALL=plot(PMax, color=color.red, linewidth=2, title="PMax", transp=0)+pALL=plot(PMax, color=color.new(color.red, 0), linewidth=2, title="PMax")-alertcondition(cross(MAvg, PMax), title="Cross Alert", message="PMax - Moving Avg Crossing!")+alertcondition(ta.cross(MAvg, PMax), title="Cross Alert", message="PMax - Moving Avg Crossing!")-alertcondition(crossover(MAvg, PMax), title="Crossover Alarm", message="Moving Avg BUY SIGNAL!")+alertcondition(ta.crossover(MAvg, PMax), title="Crossover Alarm", message="Moving Avg BUY SIGNAL!")-alertcondition(crossunder(MAvg, PMax), title="Crossunder Alarm", message="Moving Avg SELL SIGNAL!")+alertcondition(ta.crossunder(MAvg, PMax), title="Crossunder Alarm", message="Moving Avg SELL SIGNAL!")-alertcondition(cross(src, PMax), title="Price Cross Alert", message="PMax - Price Crossing!")+alertcondition(ta.cross(src, PMax), title="Price Cross Alert", message="PMax - Price Crossing!")-alertcondition(crossover(src, PMax), title="Price Crossover Alarm", message="PRICE OVER PMax - BUY SIGNAL!")+alertcondition(ta.crossover(src, PMax), title="Price Crossover Alarm", message="PRICE OVER PMax - BUY SIGNAL!")-alertcondition(crossunder(src, PMax), title="Price Crossunder Alarm", message="PRICE UNDER PMax - SELL SIGNAL!")+alertcondition(ta.crossunder(src, PMax), title="Price Crossunder Alarm", message="PRICE UNDER PMax - SELL SIGNAL!")-buySignalk = crossover(MAvg, PMax)+buySignalk = ta.crossover(MAvg, PMax)-plotshape(buySignalk and showsignalsk ? PMax*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)+plotshape(buySignalk and showsignalsk ? PMax*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.white)-sellSignallk = crossunder(MAvg, PMax)+sellSignallk = ta.crossunder(MAvg, PMax)-plotshape(sellSignallk and showsignalsk ? PMax*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)+plotshape(sellSignallk and showsignalsk ? PMax*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)mPlot = plot(rsi, title="", style=plot.style_circles, linewidth=0,display=display.none)⋯Same 12 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 7: input() → input.source()
- Line 9: input() → input.int()
- Line 10: input() → input.float()
- Line 12: input() → input.int()
- Line 89: input() → input.bool()
- Line 90: input() → input.int()
7 more edits
- Line 91: input() → input.int()
- Line 92: input() → input.int()
- Line 93: input() → input.int()
- Line 94: input() → input.int()
- Line 95: input() → input.int()
- Line 101: when = Timerange() → if block
- Line 103: when = Timerange() → if block
⋯strategy("PMax on Rsi w T3 Strategy","PmR3St.", overlay=false, precision=2)-src = input(hl2, title="Source")+src = input.source(hl2, title="Source")Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3)-length =input(8, "Tillson T3 Length", minval=1)+length =input.int(8, "Tillson T3 Length", minval=1)-T3a1 = input(0.7, "TILLSON T3 Volume Factor", step=0.1)+T3a1 = input.float(0.7, "TILLSON T3 Volume Factor", step=0.1)Periods = input.int(10,title="ATR Length")-rsilength = input(14, minval=1, title="RSI Length")+rsilength = input.int(14, minval=1, title="RSI Length")showrsi = input.bool(title="Show RSI?", defval=true)⋯fill(mPlot, pALL, title="DownTrend Highligter", color=shortFillColor)-dummy0 = input(true, title = "=Backtest Inputs=")+dummy0 = input.bool(true, title = "=Backtest 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 = 1, title = "From Month", minval = 1, maxval = 12)+FromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)-FromYear = input(defval = 2005, title = "From Year", minval = 2005)+FromYear = input.int(defval = 2005, title = "From Year", minval = 2005)-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 = 1, title = "To Month", minval = 1, maxval = 12)+ToMonth = input.int(defval = 1, title = "To Month", minval = 1, maxval = 12)-ToYear = input(defval = 9999, title = "To Year", minval = 2006)+ToYear = input.int(defval = 9999, title = "To Year", minval = 2006)Start = timestamp(FromYear, FromMonth, FromDay, 00, 00)⋯if buySignalk- strategy.entry("Long", strategy.long,when=Timerange())+ if Timerange()+ strategy.entry("Long", strategy.long)if sellSignallk- strategy.entry("Short", strategy.short,when=Timerange())+ if Timerange()+ strategy.entry("Short", strategy.short)Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L84:C54: 'linewidth' must be at least 1 in Pine Script v6. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
-//@version=5+//@version=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯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 |
|---|---|---|---|
| Source | hl2 | source | WWMA Price Cross Alert Price Crossover Alarm Price Crossunder Alarm |
| ATR Multiplier | 3 | float · step 0.1 | longStop shortStop |
| Tillson T3 Length | 8 | int · min 1 | T3e1 T3e2 T3e3 T3e4 T3e5 T3e6 PMax |
| TILLSON T3 Volume Factor | 0.7 | float · step 0.1 | T3c1 T3c2 T3c3 T3c4 |
| ATR Length | 10 | int (written input.integer) | atr |
| RSI Length | 14 | int · min 1 | wwalpha WWMA AvUp AvDown AvgUp AvgDown AvgUpH AvgDownH AvgUpL AvgDownL |
| Show RSI? | true | bool | RSI |
| Show Moving Average? | true | bool | T3 |
| Show Crossing Signals? | true | bool | Buy Sell |
| Highlighter On/Off ? | true | bool | longFillColor shortFillColor |
| =Backtest Inputs= | true | bool | unused |
| From Day | 1 | int · min 1 · max 31 | Start |
| From Month | 1 | int · min 1 · max 12 | Start |
| From Year | 2005 | int · min 2005 | Start |
| To Day | 1 | int · min 1 · max 31 | Finish |
| To Month | 1 | int · min 1 · max 12 | Finish |
| To Year | 9999 | int · min 2006 | Finish |
What it calculates
- SMA (
sma,ta.smain v5)i, RSI Length (14)AvgUp · line 26 - SMA (
sma,ta.smain v5)i2, RSI Length (14)AvgDown · line 27 - SMA (
sma,ta.smain v5)TR, ATR Length (10)atr · line 43 - EMA (
ema,ta.emain v5)rsi, Tillson T3 Length (8)T3e1 · line 48 - EMA (
ema,ta.emain v5)T3e1, Tillson T3 Length (8)T3e2 · line 49 - EMA (
ema,ta.emain v5)T3e2, Tillson T3 Length (8)T3e3 · line 50 - EMA (
ema,ta.emain v5)T3e3, Tillson T3 Length (8)T3e4 · line 51 - EMA (
ema,ta.emain v5)T3e4, Tillson T3 Length (8)T3e5 · line 52 - EMA (
ema,ta.emain v5)T3e5, Tillson T3 Length (8)T3e6 · line 53 - Crossover (
crossover,ta.crossoverin v5)MAvg, PMaxbuySignalk · line 80 - Crossunder (
crossunder,ta.crossunderin v5)MAvg, PMaxsellSignallk · line 82
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 75 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 | Timerange() | On | 101 |
| Open Short short | Timerange() | On | 103 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Cross Alert | alertcondition | PMax - Moving Avg Crossing! | 74 |
| Crossover Alarm | alertcondition | Moving Avg BUY SIGNAL! | 75 |
| Crossunder Alarm | alertcondition | Moving Avg SELL SIGNAL! | 76 |
| Price Cross Alert | alertcondition | PMax - Price Crossing! | 77 |
| Price Crossover Alarm | alertcondition | PRICE OVER PMax - BUY SIGNAL! | 78 |
| Price Crossunder Alarm | alertcondition | PRICE UNDER PMax - SELL SIGNAL! | 79 |
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 | −10.6% | +102.5% | 12 | 50% | 0.86 | 63.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +17.0% | +5.5% | 8 | 63% | 4.63 | 4.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +1.9% | +9.8% | 14 | 50% | 1.51 | 1.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.5% | +8.4% | 9 | 33% | 0.37 | 0.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.1% | +16.7% | 8 | 63% | 1.92 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 7 | 57% | 1.11 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.2% | +148.3% | 8 | 38% | 0.70 | 0.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.1% | +17.1% | 9 | 44% | 0.71 | 0.2% | 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 | 3 | 33% | −$22,369.00 |
| Sideways market | 4 | 75% | $16,270.30 |
| Falling market | 5 | 40% | −$4,454.06 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
56.0%
The 95th percentile of the worst drawdown when the same 12 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 29.0% to 56.0%; the tick is what actually happened, 56.2%. Order luck alone moves it this much.
All 12 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 16 Apr 2024 63,420.00 | 26 Jul 2024 65,799.90 | 101 | −$2,379.96 |
| long | 26 Jul 2024 65,799.90 | 24 Dec 2024 94,881.50 | 151 | $29,081.50 |
| short | 24 Dec 2024 94,881.50 | 1 May 2025 94,172.00 | 128 | $709.47 |
| long | 1 May 2025 94,172.00 | 23 Jun 2025 100,964.00 | 53 | $6,791.87 |
| short | 23 Jun 2025 100,964.00 | 10 Oct 2025 121,662.00 | 109 | −$20,698.50 |
| long | 10 Oct 2025 121,662.00 | 18 Nov 2025 92,215.10 | 39 | −$29,447.30 |
| short | 18 Nov 2025 92,215.10 | 7 Jan 2026 93,748.00 | 50 | −$1,532.83 |
| long | 7 Jan 2026 93,748.00 | 7 Feb 2026 70,580.30 | 31 | −$23,167.70 |
| short | 7 Feb 2026 70,580.30 | 15 Mar 2026 71,211.90 | 36 | −$631.69 |
| long | 15 Mar 2026 71,211.90 | 1 Jun 2026 73,674.40 | 78 | $2,462.44 |
| short | 1 Jun 2026 73,674.40 | 17 Jul 2026 63,830.20 | 46 | $9,844.19 |
| long | 17 Jul 2026 63,830.20 | 16 Oct 2026 82,245.90 | 91 | $18,415.70 |
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 |
|---|---|---|---|---|---|
| PMax on Rsi w-T3 -Strategy- this page | — | v4 strategy | −10.6% | 12 | 63.7% |
| MACD Long Strat by TheGrindToday | ema sma | v4 strategy | +24.0% | 79 | 20.1% |
| Stock trending strategy by exlux99 | ema sma | v4 strategy | +35.3% | 21 | 14.7% |
| 4-Hour Stochastic EMA Trend by slymnturkoglu | ema sma | v4 strategy | No trades on this market | ||
| 4X EMA and volume strategy by SoftKill21 | ema sma | v4 strategy | +1.8% | 3 | 25.8% |
| Simple Momentum Strategy Based on SMA, EMA and Volume by slip_stream | sma ema | v4 strategy | +7.4% | 18 | 27.4% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 35 ms | Yes 1,000 bars in 103 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.
//@version=4// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © KivancOzbilgic//developer: @KivancOzbilgic//author: @KivancOzbilgicstrategy("PMax on Rsi w T3 Strategy","PmR3St.", overlay=false, precision=2)src = input(hl2, title="Source")Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3)length =input(8, "Tillson T3 Length", minval=1)T3a1 = input(0.7, "TILLSON T3 Volume Factor", step=0.1)Periods = input(10,title="ATR Length", type=input.integer)rsilength = input(14, minval=1, title="RSI Length")showrsi = input(title="Show RSI?", type=input.bool, defval=true)showsupport = input(title="Show Moving Average?", type=input.bool, defval=true)showsignalsk = input(title="Show Crossing Signals?", type=input.bool, defval=true)highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)i = close>=close[1] ? close-close[1] : 0i2 = close<close[1] ? close[1]-close : 0Wwma_Func(src,rsilength)=> wwalpha = 1/ rsilength WWMA = 0.0 WWMA := wwalpha*src + (1-wwalpha)*nz(WWMA[1])WWMA=Wwma_Func(src,rsilength)AvUp = Wwma_Func(i,rsilength)AvDown = Wwma_Func(i2,rsilength)AvgUp = sma(i,rsilength)AvgDown =sma(i2,rsilength)k1 = high>close[1] ? high-close[1] : 0k2 = high<close[1] ? close[1]-high : 0k3 = low>close[1] ? low-close[1] : 0k4 = low<close[1] ? close[1]-low : 0AvgUpH=(AvgUp*(rsilength-1)+ k1)/rsilengthAvgDownH=(AvgDown*(rsilength-1)+ k2)/rsilengthAvgUpL=(AvgUp*(rsilength-1)+ k3)/rsilengthAvgDownL=(AvgDown*(rsilength-1)+ k4)/rsilengthrs = AvUp/AvDownrsi= rs==-1 ? 0 : (100-(100/(1+rs)))rsh=AvgUpH/AvgDownHrsih= rsh==-1 ? 0 : (100-(100/(1+rsh)))rsl=AvgUpL/AvgDownLrsil= rsl==-1 ? 0 : (100-(100/(1+rsl)))TR=max(rsih-rsil,abs(rsih-rsi[1]),abs(rsil-rsi[1]))atr=sma(TR,Periods)plot(showrsi ? rsi : na, "RSI", color=#8E1599)band1 = hline(70, "Upper Band", color=#C0C0C0)band0 = hline(30, "Lower Band", color=#C0C0C0)fill(band1, band0, color=#9915FF, transp=90, title="Background")T3e1=ema(rsi, length)T3e2=ema(T3e1,length)T3e3=ema(T3e2,length)T3e4=ema(T3e3,length)T3e5=ema(T3e4,length)T3e6=ema(T3e5,length)T3c1=-T3a1*T3a1*T3a1T3c2=3*T3a1*T3a1+3*T3a1*T3a1*T3a1T3c3=-6*T3a1*T3a1-3*T3a1-3*T3a1*T3a1*T3a1T3c4=1+3*T3a1+T3a1*T3a1*T3a1+3*T3a1*T3a1T3=T3c1*T3e6+T3c2*T3e5+T3c3*T3e4+T3c4*T3e3MAvg=T3Pmax_Func(rsi,length)=> longStop = MAvg - Multiplier*atr longStopPrev = nz(longStop[1], longStop) longStop := MAvg > longStopPrev ? max(longStop, longStopPrev) : longStop shortStop = MAvg + Multiplier*atr shortStopPrev = nz(shortStop[1], shortStop) shortStop := MAvg < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop dir = 1 dir := nz(dir[1], dir) dir := dir == -1 and MAvg > shortStopPrev ? 1 : dir == 1 and MAvg < longStopPrev ? -1 : dir PMax = dir==1 ? longStop: shortStopPMax=Pmax_Func(rsi,length)plot(showsupport ? MAvg : na, color=color.black, linewidth=2, title="T3")pALL=plot(PMax, color=color.red, linewidth=2, title="PMax", transp=0)alertcondition(cross(MAvg, PMax), title="Cross Alert", message="PMax - Moving Avg Crossing!")alertcondition(crossover(MAvg, PMax), title="Crossover Alarm", message="Moving Avg BUY SIGNAL!")alertcondition(crossunder(MAvg, PMax), title="Crossunder Alarm", message="Moving Avg SELL SIGNAL!")alertcondition(cross(src, PMax), title="Price Cross Alert", message="PMax - Price Crossing!")alertcondition(crossover(src, PMax), title="Price Crossover Alarm", message="PRICE OVER PMax - BUY SIGNAL!")alertcondition(crossunder(src, PMax), title="Price Crossunder Alarm", message="PRICE UNDER PMax - SELL SIGNAL!")buySignalk = crossover(MAvg, PMax)plotshape(buySignalk and showsignalsk ? PMax*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)sellSignallk = crossunder(MAvg, PMax)plotshape(sellSignallk and showsignalsk ? PMax*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)mPlot = plot(rsi, title="", style=plot.style_circles, linewidth=0,display=display.none)longFillColor = highlighting ? (MAvg>PMax ? color.green : na) : nashortFillColor = highlighting ? (MAvg<PMax ? color.red : na) : nafill(mPlot, pALL, title="UpTrend Highligter", color=longFillColor)fill(mPlot, pALL, title="DownTrend Highligter", color=shortFillColor)dummy0 = input(true, title = "=Backtest Inputs=")FromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)FromYear = input(defval = 2005, title = "From Year", minval = 2005)ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)ToMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)ToYear = input(defval = 9999, title = "To Year", minval = 2006)Start = timestamp(FromYear, FromMonth, FromDay, 00, 00)Finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)Timerange() => time >= Start and time <= Finish ? true : falseif buySignalk strategy.entry("Long", strategy.long,when=Timerange())if sellSignallk strategy.entry("Short", strategy.short,when=Timerange())