Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (17)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctRSI$86,997$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
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

Verified

Same 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)⋯

Clean v5

VerifiedDownload the v5 script

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.

SettingDefaultType and rangeFeeds
Sourcehl2sourceWWMA Price Cross Alert Price Crossover Alarm Price Crossunder Alarm
ATR Multiplier3float · step 0.1longStop shortStop
Tillson T3 Length8int · min 1T3e1 T3e2 T3e3 T3e4 T3e5 T3e6 PMax
TILLSON T3 Volume Factor0.7float · step 0.1T3c1 T3c2 T3c3 T3c4
ATR Length10int (written input.integer)atr
RSI Length14int · min 1wwalpha WWMA AvUp AvDown AvgUp AvgDown AvgUpH AvgDownH AvgUpL AvgDownL
Show RSI?trueboolRSI
Show Moving Average?trueboolT3
Show Crossing Signals?trueboolBuy Sell
Highlighter On/Off ?trueboollongFillColor shortFillColor
=Backtest Inputs=trueboolunused
From Day1int · min 1 · max 31Start
From Month1int · min 1 · max 12Start
From Year2005int · min 2005Start
To Day1int · min 1 · max 31Finish
To Month1int · min 1 · max 12Finish
To Year9999int · min 2006Finish

What it calculates

  • SMA (sma, ta.sma in v5)i, RSI Length (14)AvgUp · line 26
  • SMA (sma, ta.sma in v5)i2, RSI Length (14)AvgDown · line 27
  • SMA (sma, ta.sma in v5)TR, ATR Length (10)atr · line 43
  • EMA (ema, ta.ema in v5)rsi, Tillson T3 Length (8)T3e1 · line 48
  • EMA (ema, ta.ema in v5)T3e1, Tillson T3 Length (8)T3e2 · line 49
  • EMA (ema, ta.ema in v5)T3e2, Tillson T3 Length (8)T3e3 · line 50
  • EMA (ema, ta.ema in v5)T3e3, Tillson T3 Length (8)T3e4 · line 51
  • EMA (ema, ta.ema in v5)T3e4, Tillson T3 Length (8)T3e5 · line 52
  • EMA (ema, ta.ema in v5)T3e5, Tillson T3 Length (8)T3e6 · line 53
  • Crossover (crossover, ta.crossover in v5)MAvg, PMaxbuySignalk · line 80
  • Crossunder (crossunder, ta.crossunder in 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

OrderFires whenBy defaultLine
Open Long longTimerange()On101
Open Short shortTimerange()On103

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

Alerts

AlertCallMessageLine
Cross AlertalertconditionPMax - Moving Avg Crossing!74
Crossover AlarmalertconditionMoving Avg BUY SIGNAL!75
Crossunder AlarmalertconditionMoving Avg SELL SIGNAL!76
Price Cross AlertalertconditionPMax - Price Crossing!77
Price Crossover AlarmalertconditionPRICE OVER PMax - BUY SIGNAL!78
Price Crossunder AlarmalertconditionPRICE UNDER PMax - SELL SIGNAL!79

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

5/5trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.

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

Other markets

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

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−10.6%+102.5%1250%0.8663.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+17.0%+5.5%863%4.634.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+1.9%+9.8%1450%1.511.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.5%+8.4%933%0.370.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.1%+16.7%863%1.920.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%757%1.110.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.2%+148.3%838%0.700.5%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.1%+17.1%944%0.710.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 barsTradesWonP&L
Rising market333%−$22,369.00
Sideways market475%$16,270.30
Falling market540%−$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.

0%65%
All 12 trades
SideEntryExitBarsP&L
short16 Apr 2024 63,420.0026 Jul 2024 65,799.90101−$2,379.96
long26 Jul 2024 65,799.9024 Dec 2024 94,881.50151$29,081.50
short24 Dec 2024 94,881.501 May 2025 94,172.00128$709.47
long1 May 2025 94,172.0023 Jun 2025 100,964.0053$6,791.87
short23 Jun 2025 100,964.0010 Oct 2025 121,662.00109−$20,698.50
long10 Oct 2025 121,662.0018 Nov 2025 92,215.1039−$29,447.30
short18 Nov 2025 92,215.107 Jan 2026 93,748.0050−$1,532.83
long7 Jan 2026 93,748.007 Feb 2026 70,580.3031−$23,167.70
short7 Feb 2026 70,580.3015 Mar 2026 71,211.9036−$631.69
long15 Mar 2026 71,211.901 Jun 2026 73,674.4078$2,462.44
short1 Jun 2026 73,674.4017 Jul 2026 63,830.2046$9,844.19
long17 Jul 2026 63,830.2016 Oct 2026 82,245.9091$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.

ScriptSharesTypeNetTradesMax drawdown
PMax on Rsi w-T3 -Strategy- this page—v4 strategy−10.6%1263.7%
MACD Long Strat by TheGrindTodayema smav4 strategy+24.0%7920.1%
Stock trending strategy by exlux99ema smav4 strategy+35.3%2114.7%
4-Hour Stochastic EMA Trend by slymnturkogluema smav4 strategyNo trades on this market
4X EMA and volume strategy by SoftKill21ema smav4 strategy+1.8%325.8%
Simple Momentum Strategy Based on SMA, EMA and Volume by slip_streamsma emav4 strategy+7.4%1827.4%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 35 msYes 1,000 bars in 103 msNot measured
PineTSNo 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())