Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Oscillator Evaluator (Analysis tool)

A Pine Script v4 strategy built on RSI (ohlc4, 1), SMA or Stoch (close, high, low, 1, 2) and Change (_src, _len). It has 12 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits 500 in cash and pays 0.1% commission. 36 settings; defaults include Average Returns Ratio Adjustment 1, Strategy Selector MA Strategy and Oscillator Selector Oscillator 1.

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 Oscillator Evaluator (Analysis tool) repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Oscillator Evaluator (Analysis tool) do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
Can Oscillator Evaluator (Analysis tool) 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 Oscillator Evaluator (Analysis tool) use a stop loss?
Yes
strategy.exit sets a stop on line 542, 543, 544, 545.
Does Oscillator Evaluator (Analysis tool) run in Zeal Terminal?
Yes
It compiles in 142 ms and runs 1,000 bars in 238 ms, in the browser.

BTCUSDT · 1D · default settings

  • MA Strat
  • Plot
  • HLine
  • HLine
  • HLine
  • 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 (36)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctMA Strat$700$1,418Equity from $700
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. Zeal Terminal's engine currently reads an order side written as false, true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 527, 531) 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.
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, $700 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

    1 setting does nothing

    “Oscillator 3 Timeframe Adjustment” is declared but never read.

  • 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 527, 531, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 548

    transp = on line 548, 549, 551. 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 abs → math.abs, rsi → ta.rsi, sma → ta.sma, stoch → ta.stoch, asin → math.asin, sin → math.sin, cos → math.cos, atan → math.atan, change → ta.change, sum → math.sum, pow → math.pow, sqrt → math.sqrt, exp → math.exp, ema → ta.ema, crossunder → ta.crossunder, crossover → ta.crossover, max → math.max, min → math.min.
  • 12 strategy calls use the when = argument (line 527, 531, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 3: //@version=4 → //@version=5
  • Line 7: input(type = input.float) → input.float()
  • Line 11: abs → math.abs
  • Line 19: input(type = input.string) → input.string()
  • Line 20: input(type = input.string) → input.string()
  • Line 21: input(type = input.float) → input.float()
88 more edits
  • Line 22: input(type = input.float) → input.float()
  • Line 23: input(type = input.float) → input.float()
  • Line 24: input(type = input.float) → input.float()
  • Line 25: input(type = input.float) → input.float()
  • Line 26: input(type = input.float) → input.float()
  • Line 70: rsi → ta.rsi
  • Line 71: rsi → ta.rsi
  • Line 72: rsi → ta.rsi
  • Line 73: rsi → ta.rsi
  • Line 74: rsi → ta.rsi
  • Line 75: rsi → ta.rsi
  • Line 76: rsi → ta.rsi
  • Line 78: rsi → ta.rsi
  • Line 79: rsi → ta.rsi
  • Line 80: rsi → ta.rsi
  • Line 81: rsi → ta.rsi
  • Line 82: rsi → ta.rsi
  • Line 83: rsi → ta.rsi
  • Line 84: rsi → ta.rsi
  • Line 88: sma → ta.sma
  • Line 88: stoch → ta.stoch
  • Line 89: sma → ta.sma
  • Line 89: stoch → ta.stoch
  • Line 90: sma → ta.sma
  • Line 90: stoch → ta.stoch
  • Line 91: sma → ta.sma
  • Line 91: stoch → ta.stoch
  • Line 92: sma → ta.sma
  • Line 92: stoch → ta.stoch
  • Line 93: sma → ta.sma
  • Line 93: stoch → ta.stoch
  • Line 94: sma → ta.sma
  • Line 94: stoch → ta.stoch
  • Line 96: sma → ta.sma
  • Line 96: stoch → ta.stoch
  • Line 97: sma → ta.sma
  • Line 97: stoch → ta.stoch
  • Line 98: sma → ta.sma
  • Line 98: stoch → ta.stoch
  • Line 99: sma → ta.sma
  • Line 99: stoch → ta.stoch
  • Line 100: sma → ta.sma
  • Line 100: stoch → ta.stoch
  • Line 101: sma → ta.sma
  • Line 101: stoch → ta.stoch
  • Line 102: sma → ta.sma
  • Line 102: stoch → ta.stoch
  • Line 115: asin → math.asin
  • Line 126: sin → math.sin
  • Line 126: cos → math.cos
  • Line 153: atan → math.atan
  • Line 164: atan → math.atan
  • Line 177: abs → math.abs
  • Line 177: change → ta.change
  • Line 178: sum → math.sum
  • Line 178: abs → math.abs
  • Line 178: change → ta.change
  • Line 182: pow → math.pow
  • Line 189: change → ta.change
  • Line 192: sum → math.sum
  • Line 193: sum → math.sum
  • Line 195: abs → math.abs
  • Line 200: sqrt → math.sqrt
  • Line 201: exp → math.exp
  • Line 202: cos → math.cos
  • Line 203: pow → math.pow
  • Line 210: type is reserved in v5: renamed type_
  • Line 212: ema → ta.ema
  • Line 212: sma → ta.sma
  • Line 215: range is reserved in v5: renamed range_
  • Line 224: abs → math.abs
  • Line 239: abs → math.abs
  • Line 244: abs → math.abs
  • Line 253: abs → math.abs
  • Line 388: crossunder → ta.crossunder
  • Line 397: crossover → ta.crossover
  • Line 409: max → math.max
  • Line 411: min → math.min
  • Line 489: input(type = input.time) → input.time()
  • Line 490: input(type = input.integer) → input.int()
  • Line 495: input(type = input.time) → input.time()
  • Line 496: input(type = input.time) → input.time()
  • Line 498: input(type = input.integer) → input.int()
  • Line 527: strategy.entry(…, false) → strategy.entry(…, strategy.short)
  • Line 531: strategy.entry(…, true) → strategy.entry(…, strategy.long)
  • Line 548: transp = 100 → color.new(color.white, 100)
  • Line 549: transp = 100 → color.new(color.white, 100)
  • Line 551: transp = 0 → color.new(cColor, 0)
⋯// © mks17-//@version=4+//@version=5//Created for tradingview backtester⋯//--------------------Average Returns----------------------------------avgRetR = input(title='Average Returns Ratio Adjustment', type=input.float, defval=1, minval=0.02, step=0.02)   //To change the automatic calculated avgRet parameter +avgRetR = input.float(title='Average Returns Ratio Adjustment', defval=1, minval=0.02, step=0.02)   //To change the automatic calculated avgRet parameter sum = 0.0⋯returns = (close - close[1]) * 100 / close-sum := sum + abs(returns)+sum := sum + math.abs(returns)avgRet = sum / bar_index⋯sEntries = input(false, title="Show Short Entries Only")-stratSel = input(defval="MA Strategy", title="Strategy Selector", options=["MA Strategy", "MA Crossover Strategy", "Cross over 0 Strategy","Buy/Sell on Extremes Strategy", "Mean Reversion Strategy", "Take Profit Strategy"], type=input.string)+stratSel = input.string(defval="MA Strategy", title="Strategy Selector", options=["MA Strategy", "MA Crossover Strategy", "Cross over 0 Strategy","Buy/Sell on Extremes Strategy", "Mean Reversion Strategy", "Take Profit Strategy"])-dataSel = input(defval="Oscillator 1", title="Oscillator Selector", options=["Oscillator 1", "Oscillator 2", "Oscillator 3"], type=input.string)+dataSel = input.string(defval="Oscillator 1", title="Oscillator Selector", options=["Oscillator 1", "Oscillator 2", "Oscillator 3"])-scale1 = input(title="Oscillator 1 Scale Adjustment", type=input.float, defval=1, minval=0, maxval=10, step=0.05)+scale1 = input.float(title="Oscillator 1 Scale Adjustment", defval=1, minval=0, maxval=10, step=0.05)-tfadj1 = input(title="Oscillator 1 Timeframe Adjustment", type=input.float, defval=0.2, minval=0, maxval=10, step=0.05)+tfadj1 = input.float(title="Oscillator 1 Timeframe Adjustment", defval=0.2, minval=0, maxval=10, step=0.05)-scale2 = input(title="Oscillator 2 Scale Adjustment", type=input.float, defval=1, minval=0, maxval=10, step=0.05)+scale2 = input.float(title="Oscillator 2 Scale Adjustment", defval=1, minval=0, maxval=10, step=0.05)-tfadj2 = input(title="Oscillator 2 Timeframe Adjustment", type=input.float, defval=0.2, minval=0, maxval=10, step=0.05)+tfadj2 = input.float(title="Oscillator 2 Timeframe Adjustment", defval=0.2, minval=0, maxval=10, step=0.05)-scale3 = input(title="Oscillator 3 Scale Adjustment", type=input.float, defval=1, minval=0, maxval=10, step=0.05)+scale3 = input.float(title="Oscillator 3 Scale Adjustment", defval=1, minval=0, maxval=10, step=0.05)-tfadj3 = input(title="Oscillator 3 Timeframe Adjustment", type=input.float, defval=0.2, minval=0, maxval=10, step=0.05)+tfadj3 = input.float(title="Oscillator 3 Timeframe Adjustment", defval=0.2, minval=0, maxval=10, step=0.05)bool mastrat = false, macrossstrat = false, crossstrat = false, bsstrat = false, mrstrat = false, tpstrat = false⋯//Mine is RSI-rsi1 = rsi(ohlc4, 1)+rsi1 = ta.rsi(ohlc4, 1)-rsi2 = rsi(ohlc4, 2), rsi2 := nz(rsi2, rsi1)+rsi2 = ta.rsi(ohlc4, 2), rsi2 := nz(rsi2, rsi1)-rsi3 = rsi(ohlc4, 3), rsi3 := nz(rsi3, rsi2)+rsi3 = ta.rsi(ohlc4, 3), rsi3 := nz(rsi3, rsi2)-rsi4 = rsi(ohlc4, 4), rsi4 := nz(rsi4, rsi3)+rsi4 = ta.rsi(ohlc4, 4), rsi4 := nz(rsi4, rsi3)-rsi5 = rsi(ohlc4, 5), rsi5 := nz(rsi5, rsi4)+rsi5 = ta.rsi(ohlc4, 5), rsi5 := nz(rsi5, rsi4)-rsi6 = rsi(ohlc4, 6), rsi6 := nz(rsi6, rsi5)+rsi6 = ta.rsi(ohlc4, 6), rsi6 := nz(rsi6, rsi5)-rsi7 = rsi(ohlc4, 7), rsi7 := nz(rsi7, rsi6)+rsi7 = ta.rsi(ohlc4, 7), rsi7 := nz(rsi7, rsi6)LTFrsi = ((rsi1 + rsi2 + rsi3 + rsi4 + rsi5 + rsi6 + rsi7) / 7) - 50-rsi12 = rsi(ohlc4, 12), rsi12 := nz(rsi12, LTFrsi)+rsi12 = ta.rsi(ohlc4, 12), rsi12 := nz(rsi12, LTFrsi)-rsi24 = rsi(ohlc4, 24), rsi24 := nz(rsi24, rsi12)+rsi24 = ta.rsi(ohlc4, 24), rsi24 := nz(rsi24, rsi12)-rsi36 = rsi(ohlc4, 36), rsi36 := nz(rsi36, rsi24)+rsi36 = ta.rsi(ohlc4, 36), rsi36 := nz(rsi36, rsi24)-rsi48 = rsi(ohlc4, 48), rsi48 := nz(rsi48, rsi36)+rsi48 = ta.rsi(ohlc4, 48), rsi48 := nz(rsi48, rsi36)-rsi60 = rsi(ohlc4, 60), rsi60 := nz(rsi60, rsi48)+rsi60 = ta.rsi(ohlc4, 60), rsi60 := nz(rsi60, rsi48)-rsi72 = rsi(ohlc4, 72), rsi72 := nz(rsi72, rsi60)+rsi72 = ta.rsi(ohlc4, 72), rsi72 := nz(rsi72, rsi60)-rsi84 = rsi(ohlc4, 84), rsi84 := nz(rsi84, rsi72)+rsi84 = ta.rsi(ohlc4, 84), rsi84 := nz(rsi84, rsi72)HTFrsi = ((rsi12 + rsi24 + rsi36 + rsi48 + rsi60 + rsi72 + rsi84) / 7) - 50⋯//And Stochastic-stoch1 = sma(stoch(close, high, low, 1), 2)+stoch1 = ta.sma(ta.stoch(close, high, low, 1), 2)-stoch2 = sma(stoch(close, high, low, 2), 2), stoch2 := nz(stoch2, stoch1)+stoch2 = ta.sma(ta.stoch(close, high, low, 2), 2), stoch2 := nz(stoch2, stoch1)-stoch3 = sma(stoch(close, high, low, 3), 2), stoch3 := nz(stoch3, stoch2)+stoch3 = ta.sma(ta.stoch(close, high, low, 3), 2), stoch3 := nz(stoch3, stoch2)-stoch4 = sma(stoch(close, high, low, 4), 2), stoch4 := nz(stoch4, stoch3)+stoch4 = ta.sma(ta.stoch(close, high, low, 4), 2), stoch4 := nz(stoch4, stoch3)-stoch5 = sma(stoch(close, high, low, 5), 2), stoch5 := nz(stoch5, stoch4)+stoch5 = ta.sma(ta.stoch(close, high, low, 5), 2), stoch5 := nz(stoch5, stoch4)-stoch6 = sma(stoch(close, high, low, 6), 2), stoch6 := nz(stoch6, stoch5)+stoch6 = ta.sma(ta.stoch(close, high, low, 6), 2), stoch6 := nz(stoch6, stoch5)-stoch7 = sma(stoch(close, high, low, 7), 2), stoch7 := nz(stoch7, stoch6)+stoch7 = ta.sma(ta.stoch(close, high, low, 7), 2), stoch7 := nz(stoch7, stoch6)LTFstoch = ((stoch1 + stoch2 + stoch3 + stoch4 + stoch5 + stoch6 + stoch7) / 7) - 50-stoch12 = sma(stoch(close, high, low, 12), 2), stoch12 := nz(stoch12, LTFstoch)+stoch12 = ta.sma(ta.stoch(close, high, low, 12), 2), stoch12 := nz(stoch12, LTFstoch)-stoch24 = sma(stoch(close, high, low, 24), 2), stoch24 := nz(stoch24, stoch12)+stoch24 = ta.sma(ta.stoch(close, high, low, 24), 2), stoch24 := nz(stoch24, stoch12)-stoch36 = sma(stoch(close, high, low, 36), 2), stoch36 := nz(stoch36, stoch24)+stoch36 = ta.sma(ta.stoch(close, high, low, 36), 2), stoch36 := nz(stoch36, stoch24)-stoch48 = sma(stoch(close, high, low, 48), 2), stoch48 := nz(stoch48, stoch36)+stoch48 = ta.sma(ta.stoch(close, high, low, 48), 2), stoch48 := nz(stoch48, stoch36)-stoch60 = sma(stoch(close, high, low, 60), 2), stoch60 := nz(stoch60, stoch48)+stoch60 = ta.sma(ta.stoch(close, high, low, 60), 2), stoch60 := nz(stoch60, stoch48)-stoch72 = sma(stoch(close, high, low, 72), 2), stoch72 := nz(stoch72, stoch60)+stoch72 = ta.sma(ta.stoch(close, high, low, 72), 2), stoch72 := nz(stoch72, stoch60)-stoch84 = sma(stoch(close, high, low, 84), 2), stoch84 := nz(stoch84, stoch72)+stoch84 = ta.sma(ta.stoch(close, high, low, 84), 2), stoch84 := nz(stoch84, stoch72)HTFstoch = ((stoch12 + stoch24 + stoch36 + stoch48 + stoch60 + stoch72 + stoch84) / 7) - 50⋯//--------------------MAs----------------------PI = 2 * asin(1)+PI = 2 * math.asin(1)laguerre(src, alpha) =>⋯    a = 0.707 * 2 * PI / highpassLength-    alpha1 = 1 + (sin(a) - 1) / cos(a)+    alpha1 = 1 + (math.sin(a) - 1) / math.cos(a)    b = 1 - alpha1 / 2⋯    if Re != 0 and Im != 0-        mesaPeriod := 2 * PI / atan(Im / Re)+        mesaPeriod := 2 * PI / math.atan(Im / Re)    if mesaPeriod > 1.5 * nz(mesaPeriod[1])⋯    if I1 != 0-        phase := (180 / PI) * atan(Q1 / I1)+        phase := (180 / PI) * math.atan(Q1 / I1)    deltaPhase = nz(phase[1]) - phase⋯kama(_src, _len) =>-    mom = abs(change(_src, _len))+    mom = math.abs(ta.change(_src, _len))-    volatility = sum(abs(change(_src)), _len)+    volatility = math.sum(math.abs(ta.change(_src)), _len)    er = volatility != 0 ? mom / volatility : 0⋯    slowAlpha = 0.0645-    alpha = pow((er * (fastAlpha - slowAlpha)) + slowAlpha, 2)+    alpha = math.pow((er * (fastAlpha - slowAlpha)) + slowAlpha, 2)    kama = 0.0⋯    alpha = 6 / (_len + 1)-    momm = change(_src)+    momm = ta.change(_src)    m1 = momm >= 0.0 ? momm : 0.0    m2 = momm >= 0.0 ? 0.0 : -momm-    sm1 = sum(m1, _len)+    sm1 = math.sum(m1, _len)-    sm2 = sum(m2, _len)+    sm2 = math.sum(m2, _len)    chandeMO = nz(percent(sm1 - sm2, sm1 + sm2))-    k = abs(chandeMO) / 100 +    k = math.abs(chandeMO) / 100     vidya = 0.0⋯//Ehlers Super Smooth Filter -    arg = sqrt(2) * PI / length+    arg = math.sqrt(2) * PI / length-    a1 = exp(-arg)+    a1 = math.exp(-arg)-    coef2 = 2 * a1 * cos(arg)+    coef2 = 2 * a1 * math.cos(arg)-    coef3 = -pow(a1, 2)+    coef3 = -math.pow(a1, 2)    coef1 = 1 - coef2 - coef3⋯    -filter(type, src, len) =>+filter(type_, src, len) =>// MA type Selector-    type == "Laguerre" ? laguerre(src, 4.0 / (1 + len)) : type == "EMA" ? ema(src, len) : type == "SMA" ?  sma(src, len) : type == "MAMA" ? mama(src, 4.5 / len, 0.45 / len) : type == "KAMA" ? kama(src, len) : type == "VIDYA" ? vidya(src, len) : type == "S Smooth" ? sSmooth(src, len) : src+    type_ == "Laguerre" ? laguerre(src, 4.0 / (1 + len)) : type_ == "EMA" ? ta.ema(src, len) : type_ == "SMA" ?  ta.sma(src, len) : type_ == "MAMA" ? mama(src, 4.5 / len, 0.45 / len) : type_ == "KAMA" ? kama(src, len) : type_ == "VIDYA" ? vidya(src, len) : type_ == "S Smooth" ? sSmooth(src, len) : src//-------------------------Strategies---------------------//-------------MA Strategy-bool bear = false, bool bull = false, bool range = false, var rangeprice = close, ma2 = 0.0+bool bear = false, bool bull = false, bool range_ = false, var rangeprice = close, ma2 = 0.0if mastrat⋯    suma4 := nz(suma4[1])-    abschange = abs(change) +    abschange = math.abs(change)     suma4 := suma4 + abschange * 100⋯            bull := true -        if (abs(ma2a - ma2a[1]) < mcthr and not(bear or bull))+        if (math.abs(ma2a - ma2a[1]) < mcthr and not(bear or bull))-            range := true+            range_ := true    ⋯    if (mcthr < -0.15 * avgChange100) -        if (abs(ma2a - ma2a[1]) < -mcthr - 0.15 * avgChange100)+        if (math.abs(ma2a - ma2a[1]) < -mcthr - 0.15 * avgChange100)-            range := true+            range_ := true-        if (dataa > ma2a and data > ma2a and not(range))+        if (dataa > ma2a and data > ma2a and not(range_))            bull :=  true -        if (dataa < ma2a and data < ma2a and not(range or bull))+        if (dataa < ma2a and data < ma2a and not(range_ or bull))            bear := true⋯    if (mcthr > 0.15 * avgChange100) -        if (abs(ma2a - ma2a[1]) < mcthr - 0.15 * avgChange100 or (ma2a - ma2a[1] >= mcthr - 0.15 * avgChange100 and dataa < ma2a and dataa < ma2a or ma2a[1] - ma2a >= mcthr - 0.15 * avgChange100 and dataa > ma2a and dataa > ma2a))+        if (math.abs(ma2a - ma2a[1]) < mcthr - 0.15 * avgChange100 or (ma2a - ma2a[1] >= mcthr - 0.15 * avgChange100 and dataa < ma2a and dataa < ma2a or ma2a[1] - ma2a >= mcthr - 0.15 * avgChange100 and dataa > ma2a and dataa > ma2a))-            range := true+            range_ := true-        if (ma2a - ma2a[1] >= mcthr - 0.15 * avgChange100 and not(range))+        if (ma2a - ma2a[1] >= mcthr - 0.15 * avgChange100 and not(range_))            bull :=  true -        if (ma2a[1] - ma2a >= mcthr - 0.15* avgChange100 and not(range or bull))+        if (ma2a[1] - ma2a >= mcthr - 0.15* avgChange100 and not(range_ or bull))            bear := true            -    rangeprice := range[1] == false and range ? ma2 : range[1] and range == false ? na : rangeprice[1]+    rangeprice := range_[1] == false and range_ ? ma2 : range_[1] and range_ == false ? na : rangeprice[1]//--------------MA CrossOver Strategy⋯    -        if (shortCounter == 0 and longCounter == 0 and crossunder(data, tpOversold))+        if (shortCounter == 0 and longCounter == 0 and ta.crossunder(data, tpOversold))            longentry := 1⋯        -        if (longCounter == 0 and shortCounter == 0 and crossover(data, tpOverbought))+        if (longCounter == 0 and shortCounter == 0 and ta.crossover(data, tpOverbought))            shortentry := 1⋯if longCounter > 0 -    maxProfit := max(maxProfit[1], close)+    maxProfit := math.max(maxProfit[1], close)else if shortCounter > 0-    maxProfit := min(maxProfit[1], close)+    maxProfit := math.min(maxProfit[1], close)else ⋯useTB1 = input(false, title="Time Break 1")-startTime1 = input(defval = timestamp("01 Jan 2017"), title = "TB Start Time", type = input.time)+startTime1 = input.time(defval = timestamp("01 Jan 2017"), title = "TB Start Time")-days1 = input(title="TB 1 Range (days)", type=input.integer, defval=40, minval=1)+days1 = input.int(title="TB 1 Range (days)", defval=40, minval=1)// useTB2 = input(false, title="Time Break 2")⋯useTR = input(true, title="Time Range")-startTime = input(defval = timestamp("01 Jan 2000"), title = "TR Start Time", type = input.time)+startTime = input.time(defval = timestamp("01 Jan 2000"), title = "TR Start Time")-endTime = input(defval = timestamp("01 Jun 2020"), title = "TR End Time", type = input.time)+endTime = input.time(defval = timestamp("01 Jun 2020"), title = "TR End Time")useWF = input(true, title="Walk-Forward") -weeks = input(title="WF Range (weeks)", type=input.integer, defval=50, minval=0)+weeks = input.int(title="WF Range (weeks)", defval=50, minval=0)//Time Range & Walk Forward Test⋯    if lEntries == false -        strategy.entry("Short", false, oca_name="oca_short", oca_type=strategy.oca.reduce, when=shortentry == 1)+        strategy.entry("Short", strategy.short, oca_name="oca_short", oca_type=strategy.oca.reduce, when=shortentry == 1)        //strategy.entry("2xShort", false, oca_name="oca_short", oca_type=strategy.oca.reduce, when=x2shortentry == 1)⋯    if sEntries == false     -        strategy.entry("Long", true, oca_name="oca_long", oca_type=strategy.oca.reduce, when=longentry == 1)+        strategy.entry("Long", strategy.long, oca_name="oca_long", oca_type=strategy.oca.reduce, when=longentry == 1)        //strategy.entry("2xLong", true, oca_name="oca_long", oca_type=strategy.oca.reduce, when=x2longentry == 1)⋯//-------------------------Plotting-----------------------------plotchar(longCounter - shortCounter, title="Position Counter", char="•", color=color.white, transp=100, location=location.top, size=size.tiny)+plotchar(longCounter - shortCounter, title="Position Counter", char="•", color=color.new(color.white, 100), location=location.top, size=size.tiny)-plotchar(avgRet, title="Average Returns", char="•", color=color.white, transp=100, location=location.top, size=size.tiny)+plotchar(avgRet, title="Average Returns", char="•", color=color.new(color.white, 100), location=location.top, size=size.tiny)-cColor = bull ? color.lime : range ? color.maroon : color.orange+cColor = bull ? color.lime : range_ ? color.maroon : color.orange-plot(mastrat ? ma2 : na, color=cColor, transp=0, title="MA Strat", style=plot.style_linebr)+plot(mastrat ? ma2 : na, color=color.new(cColor, 0), title="MA Strat", style=plot.style_linebr)plot(macrossstrat ? ma1 : na, color=color.blue)⋯

Clean v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 17: input() → input.bool()
  • Line 18: input() → input.bool()
  • Line 41: input() → input.int()
  • Line 42: input() → input.float()
  • Line 44: input() → input.int()
  • Line 45: input() → input.int()
28 more edits
  • Line 47: input() → input.int()
  • Line 49: input() → input.float()
  • Line 50: input() → input.float()
  • Line 52: input() → input.int()
  • Line 53: input() → input.int()
  • Line 57: input() → input.float()
  • Line 58: input() → input.float()
  • Line 60: input() → input.int()
  • Line 61: input() → input.int()
  • Line 62: input() → input.int()
  • Line 63: input() → input.int()
  • Line 65: input() → input.int()
  • Line 66: input() → input.int()
  • Line 488: input() → input.bool()
  • Line 494: input() → input.bool()
  • Line 497: input() → input.bool()
  • Line 527: when = shortentry == 1 → if block
  • Line 531: when = longentry == 1 → if block
  • Line 536: when = shortexit == 1 → if block
  • Line 537: when = longexit == 1 → if block
  • Line 538: when = shortexit == 1 → if block
  • Line 539: when = longexit == 1 → if block
  • Line 540: when = longexit == 4 or shortexit == 4 → if block
  • Line 541: when = longexit == 5 or shortexit == 5 → if block
  • Line 542: when = longexit == 2 → if block
  • Line 543: when = shortexit == 2 → if block
  • Line 544: when = longexit == 3 → if block
  • Line 545: when = shortexit == 3 → if block
⋯//---------------------------Inputs-------------------------------------lEntries = input(false, title="Show Long Entries Only")+lEntries = input.bool(false, title="Show Long Entries Only")-sEntries = input(false, title="Show Short Entries Only")+sEntries = input.bool(false, title="Show Short Entries Only")stratSel = input.string(defval="MA Strategy", title="Strategy Selector", options=["MA Strategy", "MA Crossover Strategy", "Cross over 0 Strategy","Buy/Sell on Extremes Strategy", "Mean Reversion Strategy", "Take Profit Strategy"])⋯//MA Strat-malmt = input(7, "MA Strat Length")+malmt = input.int(7, "MA Strat Length")-mcthr = input(0.07, "MA Strat Range Threshold", step=0.005) //"MC Range Threshold "+mcthr = input.float(0.07, "MA Strat Range Threshold", step=0.005) //"MC Range Threshold "//MA crossOver Strat -mas = input(3, "MA Crossover Strat Short Length") //"MA Short Length"+mas = input.int(3, "MA Crossover Strat Short Length") //"MA Short Length"-mal = input(9, "MA Crossover Strat Long Length") //"MA Long Length"  +mal = input.int(9, "MA Crossover Strat Long Length") //"MA Long Length"  //Cross on 0 Strat-cross = input(0, "Cross Strat Horizon", step=0.1) //"Cross over 0"+cross = input.int(0, "Cross Strat Horizon", step=0.1) //"Cross over 0"//Buy Sell on Extremes Strat-bsOversold = input(-36.2, "Buy/Sell on Extremes Strat Oversold Value", step=0.1) //"Entry Max Signal"+bsOversold = input.float(-36.2, "Buy/Sell on Extremes Strat Oversold Value", step=0.1) //"Entry Max Signal"-bsOverbought = input(47.2, "Buy/Sell on Extremes Strat Overbought Value", step=0.1) //"Entry Max Signal"+bsOverbought = input.float(47.2, "Buy/Sell on Extremes Strat Overbought Value", step=0.1) //"Entry Max Signal"//Mean Reversion Strat-mrOversold = input(-45, "Mean Reversion Strat Oversold Value", step=0.1) //"Entry Max Signal"+mrOversold = input.int(-45, "Mean Reversion Strat Oversold Value", step=0.1) //"Entry Max Signal"-mrOverbought = input(45, "Mean Reversion Strat Overbought Value", step=0.1) //"Entry Max Signal"+mrOverbought = input.int(45, "Mean Reversion Strat Overbought Value", step=0.1) //"Entry Max Signal"// factor0 = input(1, step=0.1)⋯// factor2 = input(1, step=0.1)-mrtp = input(0.5, "Mean Reversion Strat TP (%)", step=0.1) / 100//+mrtp = input.float(0.5, "Mean Reversion Strat TP (%)", step=0.1) / 100//-mrsl = input(0.5, "Mean Reversion Strat SL (%)", step=0.1) / 100//+mrsl = input.float(0.5, "Mean Reversion Strat SL (%)", step=0.1) / 100////Take Profit Strat-tpOversold = input(-45, "Take Profit Strat Oversold Value", step=0.1) //"Entry Max Signal"+tpOversold = input.int(-45, "Take Profit Strat Oversold Value", step=0.1) //"Entry Max Signal"-tpOverbought = input(45, "Take Profit Strat Overbought Value", step=0.1) //"Entry Max Signal"+tpOverbought = input.int(45, "Take Profit Strat Overbought Value", step=0.1) //"Entry Max Signal"-tp = input(10, "Take Profit Strat TP (%)", step=1) / 100//+tp = input.int(10, "Take Profit Strat TP (%)", step=1) / 100//-sl = input(4, "Take Profit Strat TP (%)", step=1) / 100//+sl = input.int(4, "Take Profit Strat TP (%)", step=1) / 100////Max loss and Max Downturn for all strategies-emaxl = input(10, "Max Loss (%)", step=1) / 100 //"Exit Max loss"+emaxl = input.int(10, "Max Loss (%)", step=1) / 100 //"Exit Max loss"-emaxdn =input(20, "Max Downturn (%)", step=1) / 100//"Exit Max Downturn"+emaxdn =input.int(20, "Max Downturn (%)", step=1) / 100//"Exit Max Downturn"//-------------Oscillators-----------------⋯//--------------------------Backtesting & Orders------------------------------useTB1 = input(false, title="Time Break 1")+useTB1 = input.bool(false, title="Time Break 1")startTime1 = input.time(defval = timestamp("01 Jan 2017"), title = "TB Start Time")⋯// days2 = input(title="TB 2 Range (days)", type=input.integer, defval=20, minval=1)-useTR = input(true, title="Time Range")+useTR = input.bool(true, title="Time Range")startTime = input.time(defval = timestamp("01 Jan 2000"), title = "TR Start Time")endTime = input.time(defval = timestamp("01 Jun 2020"), title = "TR End Time")-useWF = input(true, title="Walk-Forward") +useWF = input.bool(true, title="Walk-Forward") weeks = input.int(title="WF Range (weeks)", defval=50, minval=0)⋯    if lEntries == false -        strategy.entry("Short", strategy.short, oca_name="oca_short", oca_type=strategy.oca.reduce, when=shortentry == 1)+        if shortentry == 1+            strategy.entry("Short", strategy.short, oca_name="oca_short", oca_type=strategy.oca.reduce)        //strategy.entry("2xShort", false, oca_name="oca_short", oca_type=strategy.oca.reduce, when=x2shortentry == 1)⋯    if sEntries == false     -        strategy.entry("Long", strategy.long, oca_name="oca_long", oca_type=strategy.oca.reduce, when=longentry == 1)+        if longentry == 1+            strategy.entry("Long", strategy.long, oca_name="oca_long", oca_type=strategy.oca.reduce)        //strategy.entry("2xLong", true, oca_name="oca_long", oca_type=strategy.oca.reduce, when=x2longentry == 1)⋯    if strategy.position_size != 0-        strategy.close("Short", when=shortexit == 1, comment="Exit")     //+        if shortexit == 1+            strategy.close("Short", comment="Exit")     //-        strategy.close("Long", when=longexit == 1, comment="Exit")     //+        if longexit == 1+            strategy.close("Long", comment="Exit")     //-        strategy.close("2xShort", when=shortexit == 1, comment="Exit")     //+        if shortexit == 1+            strategy.close("2xShort", comment="Exit")     //-        strategy.close("2xLong", when=longexit == 1, comment="Exit")     //+        if longexit == 1+            strategy.close("2xLong", comment="Exit")     //-        strategy.close_all(when=longexit == 4 or shortexit == 4, comment="Max Loss")+        if longexit == 4 or shortexit == 4+            strategy.close_all(comment="Max Loss")-        strategy.close_all(when=longexit == 5 or shortexit == 5, comment="Max Downturn")+        if longexit == 5 or shortexit == 5+            strategy.close_all(comment="Max Downturn")-        strategy.exit("TP", qty_percent=100, stop=high, oca_name="oca_long", when=longexit == 2)+        if longexit == 2+            strategy.exit("TP", qty_percent=100, stop=high, oca_name="oca_long")-        strategy.exit("TP",  qty_percent=100, stop=low, oca_name="oca_short", when=shortexit == 2)+        if shortexit == 2+            strategy.exit("TP",  qty_percent=100, stop=low, oca_name="oca_short")-        strategy.exit("SL", qty_percent=100, stop=high, oca_name="oca_long", when=longexit == 3)+        if longexit == 3+            strategy.exit("SL", qty_percent=100, stop=high, oca_name="oca_long")-        strategy.exit("SL",  qty_percent=100, stop=low, oca_name="oca_short", when=shortexit == 3)+        if shortexit == 3+            strategy.exit("SL",  qty_percent=100, stop=low, oca_name="oca_short")    ⋯

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.

⋯// © mks17-//@version=5+//@version=6//Created for tradingview backtester⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Average Returns Ratio Adjustment1float · min 0.02 · step 0.02avgRet
Show Long Entries Onlyfalseboolentry Short line 295 line 315 line 336 line 358 line 380 line 401 line 526
Show Short Entries Onlyfalseboolentry Long line 284 line 306 line 327 line 348 line 370 line 392 line 530
Strategy SelectorMA Strategystring · options ["MA Strategy", "MA Crossover Strategy", "Cross over 0 Strategy","Buy/Sell on Extremes Strategy", "Mean Reversion Strategy", "Take Profit Strategy"]line 28 line 30 line 32 line 34 line 36
Oscillator SelectorOscillator 1string · options ["Oscillator 1", "Oscillator 2", "Oscillator 3"]line 107 line 109
Oscillator 1 Scale Adjustment1float · min 0 · max 10 · step 0.05data
Oscillator 1 Timeframe Adjustment0.2float · min 0 · max 10 · step 0.05rsi
Oscillator 2 Scale Adjustment1float · min 0 · max 10 · step 0.05data
Oscillator 2 Timeframe Adjustment0.2float · min 0 · max 10 · step 0.05stoch
Oscillator 3 Scale Adjustment1float · min 0 · max 10 · step 0.05data
Oscillator 3 Timeframe Adjustment0.2float · min 0 · max 10 · step 0.05unused
MA Strat Length7intma2
MA Strat Range Threshold0.07float · step 0.005line 234 line 235 line 237 line 239 line 243 line 244 line 252 line 253 line 255 line 257
MA Crossover Strat Short Length3intma1
MA Crossover Strat Long Length9intma3
Cross Strat Horizon0int · step 0.1line 323 line 332
Buy/Sell on Extremes Strat Oversold Value-36.2float · step 0.1line 344
Buy/Sell on Extremes Strat Overbought Value47.2float · step 0.1line 354
Mean Reversion Strat Oversold Value-45int · step 0.1line 366
Mean Reversion Strat Overbought Value45int · step 0.1line 376
Mean Reversion Strat TP (%)0.5float · step 0.1line 453 line 461
Mean Reversion Strat SL (%)0.5float · step 0.1line 457 line 465
Take Profit Strat Oversold Value-45int · step 0.1line 388
Take Profit Strat Overbought Value45int · step 0.1line 397
Take Profit Strat TP (%)10int · step 1line 472 line 480
Take Profit Strat TP (%)4int · step 1line 476 line 484
Max Loss (%)10int · step 1maxlossLong maxlossShort
Max Downturn (%)20int · step 1maxdowntLong maxdowntShort
Time Break 1falseboolline 516
TB Start Timetimestamp("01 Jan 2017")timefinish4 line 510
TB 1 Range (days)40int (written input.integer) · min 1finish4
Time Rangetrueboolline 524
TR Start Timetimestamp("01 Jan 2000")timeline 501 line 506
TR End Timetimestamp("01 Jun 2020")timefinish2 line 501 line 504
Walk-Forwardtrueboolline 524
WF Range (weeks)50int (written input.integer) · min 0finish2

What it calculates

  • RSI (rsi, ta.rsi in v5)ohlc4, 1rsi1 · line 70
  • RSI (rsi, ta.rsi in v5)ohlc4, 2rsi2 · line 71
  • RSI (rsi, ta.rsi in v5)ohlc4, 3rsi3 · line 72
  • RSI (rsi, ta.rsi in v5)ohlc4, 4rsi4 · line 73
  • RSI (rsi, ta.rsi in v5)ohlc4, 5rsi5 · line 74
  • RSI (rsi, ta.rsi in v5)ohlc4, 6rsi6 · line 75
  • RSI (rsi, ta.rsi in v5)ohlc4, 7rsi7 · line 76
  • RSI (rsi, ta.rsi in v5)ohlc4, 12rsi12 · line 78
  • RSI (rsi, ta.rsi in v5)ohlc4, 24rsi24 · line 79
  • RSI (rsi, ta.rsi in v5)ohlc4, 36rsi36 · line 80
  • RSI (rsi, ta.rsi in v5)ohlc4, 48rsi48 · line 81
  • RSI (rsi, ta.rsi in v5)ohlc4, 60rsi60 · line 82
  • RSI (rsi, ta.rsi in v5)ohlc4, 72rsi72 · line 83
  • RSI (rsi, ta.rsi in v5)ohlc4, 84rsi84 · line 84
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, 1), 2stoch1 · line 88
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, 2), 2stoch2 · line 89
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, 3), 2stoch3 · line 90
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, 4), 2stoch4 · line 91
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, 5), 2stoch5 · line 92
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, 6), 2stoch6 · line 93
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, 7), 2stoch7 · line 94
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, 12), 2stoch12 · line 96
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, 24), 2stoch24 · line 97
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, 36), 2stoch36 · line 98
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, 48), 2stoch48 · line 99
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, 60), 2stoch60 · line 100
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, 72), 2stoch72 · line 101
  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, 84), 2stoch84 · line 102
  • Change (change, ta.change in v5)_src, _lenmom · line 177
  • Change (change, ta.change in v5)_srcvolatility · line 178
  • Change (change, ta.change in v5)_srcmomm · line 189

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 137 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Short shortshortentry == 1On527
Open Long longlongentry == 1On531
Close Shortshortexit == 1On536
Close Longlongexit == 1On537
Close 2xShortshortexit == 1On538
Close 2xLonglongexit == 1On539
Close longexit == 4 or shortexit == 4On540
Close longexit == 5 or shortexit == 5On541
Exit TP stoplongexit == 2On542
Exit TP stopshortexit == 2On543
Exit SL stoplongexit == 3On544
Exit SL stopshortexit == 3On545

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—0.0%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
Oscillator Evaluator (Analysis tool) this page—v4 strategy0.0%00.0%
CCI Level Zone by Naruephatsma rsi stochv5 strategyNo trades on this market
AVWAP Strategy by asfbherorsi stoch smav5 strategydoes not run in Zeal Terminal
SRJ RSI Outperformer Strategy by Sapt_Jashrsi smav5 strategy+0.6%82.4%
RSI SMA Crossover Strategy by reeesrsi smav5 strategy+39.8%4230.8%
Short In Downtrend Below MA100 (Coinrule) by Coinrulesma rsiv4 strategy−34.5%9945.4%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 142 msWith a workaround 1,000 bars in 238 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as false, true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 527, 531) 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/// © mks17//@version=4//Created for tradingview backtesterstrategy(title='Oscillator Evaluator (Analysis tool)', shorttitle='Oscillator Evaluator', precision=3, initial_capital=700, pyramiding=500, default_qty_value=500, default_qty_type=strategy.cash, commission_type=strategy.commission.percent, commission_value=0.1, calc_on_every_tick=false, calc_on_order_fills=false, max_bars_back=600, overlay=false)//--------------------Average Returns---------------------------------avgRetR = input(title='Average Returns Ratio Adjustment', type=input.float, defval=1, minval=0.02, step=0.02)   //To change the automatic calculated avgRet parameter sum = 0.0sum := nz(sum[1])returns = (close - close[1]) * 100 / closesum := sum + abs(returns)avgRet = sum / bar_indexavgRet := avgRet * avgRetRavgRet100 = avgRet / 100avgRetClose100 = close * avgRet100//---------------------------Inputs------------------------------------lEntries = input(false, title="Show Long Entries Only")sEntries = input(false, title="Show Short Entries Only")stratSel = input(defval="MA Strategy", title="Strategy Selector", options=["MA Strategy", "MA Crossover Strategy", "Cross over 0 Strategy","Buy/Sell on Extremes Strategy", "Mean Reversion Strategy", "Take Profit Strategy"], type=input.string)dataSel = input(defval="Oscillator 1", title="Oscillator Selector", options=["Oscillator 1", "Oscillator 2", "Oscillator 3"], type=input.string)scale1 = input(title="Oscillator 1 Scale Adjustment", type=input.float, defval=1, minval=0, maxval=10, step=0.05)tfadj1 = input(title="Oscillator 1 Timeframe Adjustment", type=input.float, defval=0.2, minval=0, maxval=10, step=0.05)scale2 = input(title="Oscillator 2 Scale Adjustment", type=input.float, defval=1, minval=0, maxval=10, step=0.05)tfadj2 = input(title="Oscillator 2 Timeframe Adjustment", type=input.float, defval=0.2, minval=0, maxval=10, step=0.05)scale3 = input(title="Oscillator 3 Scale Adjustment", type=input.float, defval=1, minval=0, maxval=10, step=0.05)tfadj3 = input(title="Oscillator 3 Timeframe Adjustment", type=input.float, defval=0.2, minval=0, maxval=10, step=0.05)bool mastrat = false, macrossstrat = false, crossstrat = false, bsstrat = false, mrstrat = false, tpstrat = falseif stratSel == "MA Strategy"    mastrat := true    else if stratSel == "MA Crossover Strategy"    macrossstrat := true    else if stratSel == "Cross over 0 Strategy"    crossstrat := true   else if stratSel == "Buy/Sell on Extremes Strategy"    bsstrat := trueelse if stratSel == "Mean Reversion Strategy"    mrstrat := true    else     tpstrat := true//MA Stratmalmt = input(7, "MA Strat Length")mcthr = input(0.07, "MA Strat Range Threshold", step=0.005) //"MC Range Threshold "//MA crossOver Strat mas = input(3, "MA Crossover Strat Short Length") //"MA Short Length"mal = input(9, "MA Crossover Strat Long Length") //"MA Long Length"  //Cross on 0 Stratcross = input(0, "Cross Strat Horizon", step=0.1) //"Cross over 0"//Buy Sell on Extremes StratbsOversold = input(-36.2, "Buy/Sell on Extremes Strat Oversold Value", step=0.1) //"Entry Max Signal"bsOverbought = input(47.2, "Buy/Sell on Extremes Strat Overbought Value", step=0.1) //"Entry Max Signal"//Mean Reversion StratmrOversold = input(-45, "Mean Reversion Strat Oversold Value", step=0.1) //"Entry Max Signal"mrOverbought = input(45, "Mean Reversion Strat Overbought Value", step=0.1) //"Entry Max Signal"// factor0 = input(1, step=0.1)// factor1 = input(1, step=0.1)// factor2 = input(1, step=0.1)mrtp = input(0.5, "Mean Reversion Strat TP (%)", step=0.1) / 100//mrsl = input(0.5, "Mean Reversion Strat SL (%)", step=0.1) / 100////Take Profit StrattpOversold = input(-45, "Take Profit Strat Oversold Value", step=0.1) //"Entry Max Signal"tpOverbought = input(45, "Take Profit Strat Overbought Value", step=0.1) //"Entry Max Signal"tp = input(10, "Take Profit Strat TP (%)", step=1) / 100//sl = input(4, "Take Profit Strat TP (%)", step=1) / 100////Max loss and Max Downturn for all strategiesemaxl = input(10, "Max Loss (%)", step=1) / 100 //"Exit Max loss"emaxdn =input(20, "Max Downturn (%)", step=1) / 100//"Exit Max Downturn"//-------------Oscillators-----------------//Put here your 2 oscillators of choice for comparison//Mine is RSIrsi1 = rsi(ohlc4, 1)rsi2 = rsi(ohlc4, 2), rsi2 := nz(rsi2, rsi1)rsi3 = rsi(ohlc4, 3), rsi3 := nz(rsi3, rsi2)rsi4 = rsi(ohlc4, 4), rsi4 := nz(rsi4, rsi3)rsi5 = rsi(ohlc4, 5), rsi5 := nz(rsi5, rsi4)rsi6 = rsi(ohlc4, 6), rsi6 := nz(rsi6, rsi5)rsi7 = rsi(ohlc4, 7), rsi7 := nz(rsi7, rsi6)LTFrsi = ((rsi1 + rsi2 + rsi3 + rsi4 + rsi5 + rsi6 + rsi7) / 7) - 50rsi12 = rsi(ohlc4, 12), rsi12 := nz(rsi12, LTFrsi)rsi24 = rsi(ohlc4, 24), rsi24 := nz(rsi24, rsi12)rsi36 = rsi(ohlc4, 36), rsi36 := nz(rsi36, rsi24)rsi48 = rsi(ohlc4, 48), rsi48 := nz(rsi48, rsi36)rsi60 = rsi(ohlc4, 60), rsi60 := nz(rsi60, rsi48)rsi72 = rsi(ohlc4, 72), rsi72 := nz(rsi72, rsi60)rsi84 = rsi(ohlc4, 84), rsi84 := nz(rsi84, rsi72)HTFrsi = ((rsi12 + rsi24 + rsi36 + rsi48 + rsi60 + rsi72 + rsi84) / 7) - 50rsi = tfadj1 * LTFrsi + (1 - tfadj1) * HTFrsi//And Stochasticstoch1 = sma(stoch(close, high, low, 1), 2)stoch2 = sma(stoch(close, high, low, 2), 2), stoch2 := nz(stoch2, stoch1)stoch3 = sma(stoch(close, high, low, 3), 2), stoch3 := nz(stoch3, stoch2)stoch4 = sma(stoch(close, high, low, 4), 2), stoch4 := nz(stoch4, stoch3)stoch5 = sma(stoch(close, high, low, 5), 2), stoch5 := nz(stoch5, stoch4)stoch6 = sma(stoch(close, high, low, 6), 2), stoch6 := nz(stoch6, stoch5)stoch7 = sma(stoch(close, high, low, 7), 2), stoch7 := nz(stoch7, stoch6)LTFstoch = ((stoch1 + stoch2 + stoch3 + stoch4 + stoch5 + stoch6 + stoch7) / 7) - 50stoch12 = sma(stoch(close, high, low, 12), 2), stoch12 := nz(stoch12, LTFstoch)stoch24 = sma(stoch(close, high, low, 24), 2), stoch24 := nz(stoch24, stoch12)stoch36 = sma(stoch(close, high, low, 36), 2), stoch36 := nz(stoch36, stoch24)stoch48 = sma(stoch(close, high, low, 48), 2), stoch48 := nz(stoch48, stoch36)stoch60 = sma(stoch(close, high, low, 60), 2), stoch60 := nz(stoch60, stoch48)stoch72 = sma(stoch(close, high, low, 72), 2), stoch72 := nz(stoch72, stoch60)stoch84 = sma(stoch(close, high, low, 84), 2), stoch84 := nz(stoch84, stoch72)HTFstoch = ((stoch12 + stoch24 + stoch36 + stoch48 + stoch60 + stoch72 + stoch84) / 7) - 50stoch = tfadj2 * LTFstoch + (1 - tfadj2) * HTFstoch//Data Selectorfloat data = 0.0if dataSel == "Oscillator 1"    data := rsi * scale1else if dataSel == "Oscillator 2"    data := stoch * scale2        else    data := stoch * scale3//--------------------MAs---------------------PI = 2 * asin(1)laguerre(src, alpha) =>// A 4-element Laguerre filter    L0 = 0.0, L2 = 0.0, L4 = 0.0, L6 = 0.0    L0 := alpha * src + (1 - alpha) * nz(L0[1], src)    L2 := -(1 - alpha) * L0 + nz(L0[1], src) + (1 - alpha) * nz(L2[1], src)    L4 := -(1 - alpha) * L2 + nz(L2[1], src) + (1 - alpha) * nz(L4[1], src)    L6 := -(1 - alpha) * L4 + nz(L4[1], src) + (1 - alpha) * nz(L6[1], src)    (L0 + 2 * L2 + 2 * L4 + L6) / 6highpassFilter(src, highpassLength) =>     a = 0.707 * 2 * PI / highpassLength    alpha1 = 1 + (sin(a) - 1) / cos(a)    b = 1 - alpha1 / 2    c = 1 - alpha1    highpass = 0.0    highpass := highpassLength != 0 ? b * b * (src - 2 * nz(src[1]) + nz(src[2])) + 2 * c * nz(highpass[1]) - c * c * nz(highpass[2]) : srchilbertTransform(src) =>    0.0962 * src + 0.5769 * nz(src[2]) - 0.5769 * nz(src[4]) - 0.0962 * nz(src[6])computeComponent(src, mesaPeriodMult) =>    hilbertTransform(src) * mesaPeriodMultcomputeAlpha(src, fastLimit, slowLimit) =>    mesaPeriod = 0.0, smooth = 0.0, detrender = 0.0, I2 = 0.0, Q2 = 0.0, phase = 0.0    mesaPeriodMult = 0.075 * nz(mesaPeriod[1]) + 0.54    smooth := (4 * src + 3 * nz(src[1]) + 2 * nz(src[2]) + nz(src[3])) / 10    detrender := computeComponent(smooth, mesaPeriodMult)    I1 = nz(detrender[3])    Q1 = computeComponent(detrender, mesaPeriodMult)    jI = computeComponent(I1, mesaPeriodMult)    jQ = computeComponent(Q1, mesaPeriodMult)    I2 := I1 - jQ    Q2 := Q1 + jI    I2 := 0.2 * I2 + 0.8 * nz(I2[1])    Q2 := 0.2 * Q2 + 0.8 * nz(Q2[1])    Re = I2 * nz(I2[1]) + Q2 * nz(Q2[1])    Im = I2 * nz(Q2[1]) - Q2 * nz(I2[1])    Re := 0.2 * Re + 0.8 * nz(Re[1])    Im := 0.2 * Im + 0.8 * nz(Im[1])    if Re != 0 and Im != 0        mesaPeriod := 2 * PI / atan(Im / Re)    if mesaPeriod > 1.5 * nz(mesaPeriod[1])        mesaPeriod := 1.5 * nz(mesaPeriod[1])    if mesaPeriod < 0.67 * nz(mesaPeriod[1])        mesaPeriod := 0.67 * nz(mesaPeriod[1])    if mesaPeriod < 6        mesaPeriod := 6    if mesaPeriod > 50        mesaPeriod := 50    mesaPeriod := 0.2 * mesaPeriod + 0.8 * nz(mesaPeriod[1])    if I1 != 0        phase := (180 / PI) * atan(Q1 / I1)    deltaPhase = nz(phase[1]) - phase    if  deltaPhase < 1        deltaPhase := 1    alpha = fastLimit / deltaPhase    if  alpha < slowLimit        alpha := slowLimit    alphamama(_src, _fastlimit, _slowlimit) =>    alpha = computeAlpha(_src, _fastlimit, _slowlimit)    mama = 0.0       mama := alpha * _src + (1 - alpha) * nz(mama[1], _src)kama(_src, _len) =>    mom = abs(change(_src, _len))    volatility = sum(abs(change(_src)), _len)    er = volatility != 0 ? mom / volatility : 0    fastAlpha = 0.6666    slowAlpha = 0.0645    alpha = pow((er * (fastAlpha - slowAlpha)) + slowAlpha, 2)    kama = 0.0    kama := alpha * _src + (1 - alpha) * nz(kama[1], _src)percent(nom, div) =>     100 * nom / divvidya(_src, _len) =>    alpha = 6 / (_len + 1)    momm = change(_src)    m1 = momm >= 0.0 ? momm : 0.0    m2 = momm >= 0.0 ? 0.0 : -momm    sm1 = sum(m1, _len)    sm2 = sum(m2, _len)    chandeMO = nz(percent(sm1 - sm2, sm1 + sm2))    k = abs(chandeMO) / 100     vidya = 0.0    vidya := alpha * k * _src + (1 - alpha * k) * nz(vidya[1], _src)sSmooth(src, length) =>//Ehlers Super Smooth Filter     arg = sqrt(2) * PI / length    a1 = exp(-arg)    coef2 = 2 * a1 * cos(arg)    coef3 = -pow(a1, 2)    coef1 = 1 - coef2 - coef3    src1 = nz(src[1], src)    src2 = nz(src[2], src1)    ssf = 0.0    ssf := coef1 * (src + src1) * 0.5 + coef2 * nz(ssf[1], src1) + coef3 * nz(ssf[2], src2)    filter(type, src, len) =>// MA type Selector    type == "Laguerre" ? laguerre(src, 4.0 / (1 + len)) : type == "EMA" ? ema(src, len) : type == "SMA" ?  sma(src, len) : type == "MAMA" ? mama(src, 4.5 / len, 0.45 / len) : type == "KAMA" ? kama(src, len) : type == "VIDYA" ? vidya(src, len) : type == "S Smooth" ? sSmooth(src, len) : src//-------------------------Strategies---------------------//-------------MA Strategybool bear = false, bool bull = false, bool range = false, var rangeprice = close, ma2 = 0.0if mastrat    ma2 := filter("Laguerre", data, malmt)   //Market Cycle MA            //Average Change MA        change = (ma2 - ma2[1]) / ma2    suma4 = 0.0    suma4 := nz(suma4[1])    abschange = abs(change)     suma4 := suma4 + abschange * 100    avgChange = suma4 / bar_index    avgChange100 = ma2 * avgChange / 100        mcthr := mcthr * avgChange100    ma2a = ma2 + 50    dataa = data + 50        //Normal Range if ma is flat then is a range    if (mcthr >= -0.15 * avgChange100 and mcthr <= 0.15 * avgChange100)         if (ma2a[1] - ma2a >= mcthr)            bear := true        if (ma2a - ma2a[1] >= mcthr and not(bear))             bull := true         if (abs(ma2a - ma2a[1]) < mcthr and not(bear or bull))            range := true        //MC Change if above or below MA complete change to opossite condition    if (mcthr < -0.15 * avgChange100)         if (abs(ma2a - ma2a[1]) < -mcthr - 0.15 * avgChange100)            range := true        if (dataa > ma2a and data > ma2a and not(range))            bull :=  true         if (dataa < ma2a and data < ma2a and not(range or bull))            bear := true                //MC Range if above or below MA cahnge to range condition    if (mcthr > 0.15 * avgChange100)         if (abs(ma2a - ma2a[1]) < mcthr - 0.15 * avgChange100 or (ma2a - ma2a[1] >= mcthr - 0.15 * avgChange100 and dataa < ma2a and dataa < ma2a or ma2a[1] - ma2a >= mcthr - 0.15 * avgChange100 and dataa > ma2a and dataa > ma2a))            range := true        if (ma2a - ma2a[1] >= mcthr - 0.15 * avgChange100 and not(range))            bull :=  true         if (ma2a[1] - ma2a >= mcthr - 0.15* avgChange100 and not(range or bull))            bear := true                rangeprice := range[1] == false and range ? ma2 : range[1] and range == false ? na : rangeprice[1]//--------------MA CrossOver Strategyma1 = 0.0, ma3 = 0.0if macrossstrat        ma1 := filter("EMA", data, mas)  //"MA Short"    ma3 := filter("Laguerre", data, mal)  //"MA Long"    //-------------------------Entry Strategy---------------------------longentry = 0, shortentry = 0, x2longentry = 0, x2shortentry = 0, shortexit = 0, longexit = 0, overBought = 0, overSold = 0last_open_long = float(na), last_open_short = float(na), var last_close_long = float(na), var last_close_short = float(na)var pyramiding = 0  //To know the current pyramidingvar longCounter = 0, var shortCounter = 0  //To keep track of the position we are invar maxProfit = float(na)   if (longCounter == 0 or shortCounter == 0)    //MA Strat    if mastrat                if (longCounter == 0 and shortCounter == 0 or longCounter == 0 and shortCounter == 1)                 if (bull)                   longentry := 1                longCounter := 1                                if (shortCounter != 0 and sEntries)                    shortexit := 1                                shortCounter := 0                            if (shortCounter == 0 and longCounter == 0 or longCounter == 1 and shortCounter == 0)                           if (bear)                 shortentry := 1                shortCounter := 1                                if (longCounter != 0 and lEntries)                    longexit := 1                                longCounter := 0     //MA CrossOver Strat    if macrossstrat            if (longCounter == 0 and ma1 >= ma3)            longentry := 1            longCounter := 1                        if (shortCounter != 0 and sEntries)                shortexit := 1                        shortCounter := 0                        if (shortCounter == 0 and ma1 < ma3)             shortentry := 1            shortCounter := 1                        if (longCounter != 0 and lEntries)                longexit := 1                        longCounter := 0         //Cross 0 Strat    if crossstrat            if (data >= cross and longCounter == 0)                 longentry := 1            longCounter := 1                        if (shortCounter != 0 and sEntries)                shortexit := 1                        shortCounter := 0                    if (data < cross and shortCounter == 0)             shortentry := 1            shortCounter := 1                        if (longCounter != 0 and lEntries)                longexit := 1                        longCounter := 0                 //Buy/Sell on Extremes Strat    if bsstrat            if data < bsOversold            longentry := 1            longCounter := longCounter + 1                        if (shortCounter != 0 and sEntries)                shortexit := 1                        shortCounter := 0                    if data > bsOverbought            shortentry := 1            shortCounter := shortCounter + 1                if (longCounter != 0 and lEntries)                longexit := 1                        longCounter := 0         //Mean Reversion Strat    if mrstrat            if (shortCounter == 0 and longCounter == 0 and data < mrOversold)            longentry := 1            longCounter := longCounter + 1                        if (shortCounter != 0 and sEntries)                shortexit := 1                        shortCounter := 0                    if (longCounter == 0 and shortCounter == 0 and data > mrOverbought)            shortentry := 1            shortCounter := shortCounter + 1                if (longCounter != 0 and lEntries)                longexit := 1                        longCounter := 0         //Take Profit Strat    if tpstrat            if (shortCounter == 0 and longCounter == 0 and crossunder(data, tpOversold))            longentry := 1            longCounter := longCounter + 1                        if (shortCounter != 0 and sEntries)                shortexit := 1                        shortCounter := 0                if (longCounter == 0 and shortCounter == 0 and crossover(data, tpOverbought))            shortentry := 1            shortCounter := shortCounter + 1                    if (longCounter != 0 and lEntries)                longexit := 1                        longCounter := 0             last_open_long := longentry == 1 or x2longentry == 1 ? close : nz(last_open_long[1])last_open_short := shortentry == 1 or x2shortentry == 1 ? close : nz(last_open_short[1])if longCounter > 0     maxProfit := max(maxProfit[1], close)else if shortCounter > 0    maxProfit := min(maxProfit[1], close)else     maxProfit := 0if longentry == 1 or x2longentry == 1 or shortentry == 1 or x2shortentry == 1     maxProfit := close        //-----------------------Close Strategy-------------------------------    if (longCounter != 0 or shortCounter != 0)        //Max Loss Exits        maxlossLong = close < last_open_long * (1 - emaxl)    maxlossShort = close > last_open_short * (1 + emaxl)    if (longCounter != 0 and maxlossLong)         longexit := 4        longCounter := 0        shortCounter := 0        if (shortCounter != 0 and maxlossShort)         shortexit := 4        shortCounter := 0        longCounter := 0         maxdowntLong = close < maxProfit * (1 - emaxdn)    maxdowntShort = close > maxProfit * (1 + emaxdn)        //Max Downturn Exits    if (longCounter != 0 and maxdowntLong)         longexit := 5        longCounter := 0        shortCounter := 0        if (shortCounter != 0 and maxdowntShort)         shortexit := 5        shortCounter := 0        longCounter := 0        //Mean Reversion Strat    if mrstrat            if (longCounter != 0 and close > last_open_long * (1 + mrtp))            longexit := 2            longCounter := 0                if (longCounter != 0 and close < last_open_long * (1 - mrsl))            longexit := 3            longCounter := 0                if (shortCounter != 0 and close < last_open_short * (1 - mrtp))            shortexit := 2            shortCounter := 0                if (shortCounter != 0 and close > last_open_short * (1 + mrsl))            shortexit := 3            shortCounter := 0            //Take Profit Strat    if tpstrat            if (longCounter != 0 and close > last_open_long * (1 + tp))            longexit := 2            longCounter := 0                if (longCounter != 0 and close < last_open_long * (1 - sl))            longexit := 3            longCounter := 0                if (shortCounter != 0 and close < last_open_short * (1 - tp))            shortexit := 2            shortCounter := 0                if (shortCounter != 0 and close > last_open_short * (1 + sl))            shortexit := 3            shortCounter := 0//--------------------------Backtesting & Orders-----------------------------useTB1 = input(false, title="Time Break 1")startTime1 = input(defval = timestamp("01 Jan 2017"), title = "TB Start Time", type = input.time)days1 = input(title="TB 1 Range (days)", type=input.integer, defval=40, minval=1)// useTB2 = input(false, title="Time Break 2")//startTime2 = input(defval = timestamp("01 Aug 2017 00:00 +0000"), title = "TB Start Time", type = input.time)// days2 = input(title="TB 2 Range (days)", type=input.integer, defval=20, minval=1)useTR = input(true, title="Time Range")startTime = input(defval = timestamp("01 Jan 2000"), title = "TR Start Time", type = input.time)endTime = input(defval = timestamp("01 Jun 2020"), title = "TR End Time", type = input.time)useWF = input(true, title="Walk-Forward") weeks = input(title="WF Range (weeks)", type=input.integer, defval=50, minval=0)//Time Range & Walk Forward Testwindow() =>  // create function "within window of time"    time >= startTime and time <= endTime ? true : falsefinish2 = endTime + weeks * timestamp(1970, 1, 8, 00, 00)  // WF finish windowwindow2() =>  // To show the WF period    time >= endTime and time <= finish2 ? true : falsewindow3() =>  // To include the WF period and the backtest period    time >= startTime and time <= finish2 ? true : false///Time Breaksfinish4 = startTime1 + days1 * timestamp(1970, 1, 2, 00, 00)window4() =>  // create function "within window of time"    time >= startTime1 and time <= finish4 ? true : false    // finish5 = startTime2 + days2 * timestamp(1970, 1, 2, 00, 00)// window5() =>  // create function "within window of time"//     time >= startTime2 and time <= finish5 ? true : false    if useTB1 and window4() //or useTB2 and window5()    longentry := 0    shortentry := 0    x2longentry := 0    x2shortentry := 0//Strategy and Backtest Conditions//smallOrder = (orderqty * ctorder) / close == 0 ? 2 : (orderqty * ctorder) / close//smallOrder = strategy.equity * mcordqty / closeif useTR and useWF == false and window() or useWF and useTR == false and window2() or useWF and useTR and window3()        if lEntries == false         strategy.entry("Short", false, oca_name="oca_short", oca_type=strategy.oca.reduce, when=shortentry == 1)        //strategy.entry("2xShort", false, oca_name="oca_short", oca_type=strategy.oca.reduce, when=x2shortentry == 1)            if sEntries == false             strategy.entry("Long", true, oca_name="oca_long", oca_type=strategy.oca.reduce, when=longentry == 1)        //strategy.entry("2xLong", true, oca_name="oca_long", oca_type=strategy.oca.reduce, when=x2longentry == 1)                        if strategy.position_size != 0        strategy.close("Short", when=shortexit == 1, comment="Exit")     //        strategy.close("Long", when=longexit == 1, comment="Exit")     //        strategy.close("2xShort", when=shortexit == 1, comment="Exit")     //        strategy.close("2xLong", when=longexit == 1, comment="Exit")     //        strategy.close_all(when=longexit == 4 or shortexit == 4, comment="Max Loss")        strategy.close_all(when=longexit == 5 or shortexit == 5, comment="Max Downturn")        strategy.exit("TP", qty_percent=100, stop=high, oca_name="oca_long", when=longexit == 2)        strategy.exit("TP",  qty_percent=100, stop=low, oca_name="oca_short", when=shortexit == 2)        strategy.exit("SL", qty_percent=100, stop=high, oca_name="oca_long", when=longexit == 3)        strategy.exit("SL",  qty_percent=100, stop=low, oca_name="oca_short", when=shortexit == 3)    //-------------------------Plotting----------------------------plotchar(longCounter - shortCounter, title="Position Counter", char="•", color=color.white, transp=100, location=location.top, size=size.tiny)plotchar(avgRet, title="Average Returns", char="•", color=color.white, transp=100, location=location.top, size=size.tiny)cColor = bull ? color.lime : range ? color.maroon : color.orangeplot(mastrat ? ma2 : na, color=cColor, transp=0, title="MA Strat", style=plot.style_linebr)plot(macrossstrat ? ma1 : na, color=color.blue)plot(macrossstrat ? ma3 : na, color=color.orange)plot(data, color=color.black)hline(0)hline(50, linestyle=hline.style_solid)hline(-50, linestyle=hline.style_solid)