Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Williams Fractals Strategy

A Pine Script v4 strategy built on EMA (close, 20) and RMA or Change (max(change(rsi_src), 0), 14). It has 5 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 1000 in cash and pays no commission. 25 settings; defaults include Theme dark, Fractal Periods 2 and EMA Length A 20.

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 Williams Fractals Strategy repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Williams Fractals Strategy do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its 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 Williams Fractals Strategy be converted to Pine Script v5?
Not tested
The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
Does Williams Fractals Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 140, 142.
Does Williams Fractals Strategy run in Zeal Terminal?
Yes
It compiles in 42 ms and runs 1,000 bars in 144 ms, in the browser.

BTCUSDT · 1D · default settings

  • long label
  • short label
  • 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 (25)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$100,000$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. Zeal Terminal's engine currently reads an order side written as long = true, long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 119, 121) so the engine trades the way the script says.
Net profit
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
0.00%
$0.00

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.

Review

What a careful reader of this script would point out, found by checking the source and the backtest.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    1 setting has no label

    In the settings dialog theme (line 7) shows an empty name. The labels on this page come from the variable names.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

  • Note

    Uses long =, which v5 renamed line 119

    long = on line 119, 121. v5 writes it as direction = strategy.long or strategy.short.

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 ema → ta.ema, rma → ta.rma, max → math.max, change → ta.change, min → math.min.

v4 → v5

Not verified

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

  • Line 4: //@version=4 → //@version=5
  • Line 7: input(type = input.string) → input.string()
  • Line 19: input(type = input.integer) → input.int()
  • Line 57: input(type = input.integer) → input.int()
  • Line 58: ema → ta.ema
  • Line 62: input(type = input.integer) → input.int()
22 more edits
  • Line 63: ema → ta.ema
  • Line 68: input(type = input.integer) → input.int()
  • Line 69: ema → ta.ema
  • Line 74: input(type = input.source) → input.source()
  • Line 75: rma → ta.rma
  • Line 75: max → math.max
  • Line 75: change → ta.change
  • Line 76: rma → ta.rma
  • Line 76: min → math.min
  • Line 76: change → ta.change
  • Line 85: input(type = input.integer) → input.int()
  • Line 87: input(type = input.integer) → input.int()
  • Line 89: input(type = input.integer) → input.int()
  • Line 91: input(type = input.integer) → input.int()
  • Line 93: input(type = input.integer) → input.int()
  • Line 95: input(type = input.integer) → input.int()
  • Line 103: input(type = input.float) → input.float()
  • Line 105: input(type = input.float) → input.float()
  • Line 119: long = true → direction = strategy.long
  • Line 121: long = false → direction = strategy.short
  • Line 124: input(type = input.float) → input.float()
  • Line 126: input(type = input.float) → input.float()
⋯// v 1.1-//@version=4+//@version=5strategy("Williams Fractals Strategy by ȼhąţhµяąɲǥą", overlay=true, default_qty_type=strategy.cash, default_qty_value=1000, currency='USD')// *************Appearance*************-theme = input(type=input.string, defval="dark", options=["light","dark"], group="Appearance")+theme = input.string(defval="dark", options=["light","dark"], group="Appearance")show_fractals = input(false, "Show Fractals", group="Appearance")⋯// Define "n" as the number of periods and keep a minimum value of 2 for error handling.-n = input(title="Fractal Periods", defval=2, minval=2, type=input.integer, group="Williams Fractals")+n = input.int(title="Fractal Periods", defval=2, minval=2, group="Williams Fractals")// UpFractal⋯src_a = input(close, title="EMA Source A", group="EMA")-offset_a = input(title="EMA Offset A", type=input.integer, defval=0, minval=-500, maxval=500, group="EMA")+offset_a = input.int(title="EMA Offset A", defval=0, minval=-500, maxval=500, group="EMA")-out_a = ema(src_a, len_a)+out_a = ta.ema(src_a, len_a)plot(show_ema ? out_a : na, title="EMA A", color=color_green, offset=offset_a)⋯src_b = input(close, title="EMA Source B", group="EMA")-offset_b = input(title="EMA Offset B", type=input.integer, defval=0, minval=-500, maxval=500, group="EMA")+offset_b = input.int(title="EMA Offset B", defval=0, minval=-500, maxval=500, group="EMA")-out_b = ema(src_b, len_b)+out_b = ta.ema(src_b, len_b)ema_b_color = (theme == "dark") ? color_yellow : color_orange⋯src_c = input(close, title="EMA Source C", group="EMA")-offset_c = input(title="EMA Offset C", type=input.integer, defval=0, minval=-500, maxval=500, group="EMA")+offset_c = input.int(title="EMA Offset C", defval=0, minval=-500, maxval=500, group="EMA")-out_c = ema(src_c, len_c)+out_c = ta.ema(src_c, len_c)ema_c_color = (theme == "dark") ? color_white : color_blue⋯rsi_len = input(14, minval=1, title="RSI Length", group="RSI")-rsi_src = input(close, "RSI Source", type = input.source, group="RSI")+rsi_src = input.source(close, "RSI Source", group="RSI")-up = rma(max(change(rsi_src), 0), rsi_len)+up = ta.rma(math.max(ta.change(rsi_src), 0), rsi_len)-down = rma(-min(change(rsi_src), 0), rsi_len)+down = ta.rma(-math.min(ta.change(rsi_src), 0), rsi_len)rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))⋯// Make input options that configure backtest date range-startDate = input(title="Start Date", type=input.integer,+startDate = input.int(title="Start Date",     defval=1, minval=1, maxval=31, group="Orders")-startMonth = input(title="Start Month", type=input.integer,+startMonth = input.int(title="Start Month",     defval=1, minval=1, maxval=12, group="Orders")-startYear = input(title="Start Year", type=input.integer,+startYear = input.int(title="Start Year",     defval=2018, minval=1800, maxval=2100, group="Orders")-endDate = input(title="End Date", type=input.integer,+endDate = input.int(title="End Date",     defval=1, minval=1, maxval=31, group="Orders")-endMonth = input(title="End Month", type=input.integer,+endMonth = input.int(title="End Month",     defval=12, minval=1, maxval=12, group="Orders")-endYear = input(title="End Year", type=input.integer,+endYear = input.int(title="End Year",     defval=2022, minval=1800, maxval=2100, group="Orders")⋯// Make inputs that set the take profit % (optional)-longProfitPerc = input(title="Long Take Profit (%)",-     type=input.float, minval=0.0, step=0.1, defval=0.5, group="Orders") * 0.01+longProfitPerc = input.float(title="Long Take Profit (%)", minval=0.0, step=0.1, defval=0.5, group="Orders") * 0.01-shortProfitPerc = input(title="Short Take Profit (%)",-     type=input.float, minval=0.0, step=0.1, defval=0.5, group="Orders") * 0.01+shortProfitPerc = input.float(title="Short Take Profit (%)", minval=0.0, step=0.1, defval=0.5, group="Orders") * 0.01// Figure out take profit price⋯if (inDateRange and long and strategy.opentrades == 0)-    strategy.entry(id="Long", long=true)+    strategy.entry(id="Long", direction = strategy.long)if (inDateRange and short and strategy.opentrades == 0)-    strategy.entry(id="Short", long=false)+    strategy.entry(id="Short", direction = strategy.short)    // Set stop loss level with input options (optional)-longLossPerc = input(title="Long Stop Loss (%)",-     type=input.float, minval=0.0, step=0.1, defval=3.1, group="Orders") * 0.01+longLossPerc = input.float(title="Long Stop Loss (%)", minval=0.0, step=0.1, defval=3.1, group="Orders") * 0.01-shortLossPerc = input(title="Short Stop Loss (%)",-     type=input.float, minval=0.0, step=0.1, defval=3.1, group="Orders") * 0.01+shortLossPerc = input.float(title="Short Stop Loss (%)", minval=0.0, step=0.1, defval=3.1, group="Orders") * 0.01// Determine stop loss price⋯

Clean v5

Not verified

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

  • Line 8: input() → input.bool()
  • Line 9: input() → input.bool()
  • Line 55: input() → input.int()
  • Line 56: input() → input.source()
  • Line 60: input() → input.int()
  • Line 61: input() → input.source()
3 more edits
  • Line 66: input() → input.int()
  • Line 67: input() → input.source()
  • Line 73: input() → input.int()
⋯theme = input.string(defval="dark", options=["light","dark"], group="Appearance")-show_fractals = input(false, "Show Fractals", group="Appearance")+show_fractals = input.bool(false, "Show Fractals", group="Appearance")-show_ema = input(false, "Show EMAs", group="Appearance")+show_ema = input.bool(false, "Show EMAs", group="Appearance")// *************colors*************⋯// *************EMA*************-len_a = input(20, minval=1, title="EMA Length A", group="EMA")+len_a = input.int(20, minval=1, title="EMA Length A", group="EMA")-src_a = input(close, title="EMA Source A", group="EMA")+src_a = input.source(close, title="EMA Source A", group="EMA")offset_a = input.int(title="EMA Offset A", defval=0, minval=-500, maxval=500, group="EMA")⋯plot(show_ema ? out_a : na, title="EMA A", color=color_green, offset=offset_a)-len_b = input(50, minval=1, title="EMA Length B", group="EMA")+len_b = input.int(50, minval=1, title="EMA Length B", group="EMA")-src_b = input(close, title="EMA Source B", group="EMA")+src_b = input.source(close, title="EMA Source B", group="EMA")offset_b = input.int(title="EMA Offset B", defval=0, minval=-500, maxval=500, group="EMA")⋯plot(show_ema ? out_b : na, title="EMA B", color=ema_b_color, offset=offset_b)-len_c = input(100, minval=1, title="EMA Length C", group="EMA")+len_c = input.int(100, minval=1, title="EMA Length C", group="EMA")-src_c = input(close, title="EMA Source C", group="EMA")+src_c = input.source(close, title="EMA Source C", group="EMA")offset_c = input.int(title="EMA Offset C", defval=0, minval=-500, maxval=500, group="EMA")⋯// *************RSI*************-rsi_len = input(14, minval=1, title="RSI Length", group="RSI")+rsi_len = input.int(14, minval=1, title="RSI Length", group="RSI")rsi_src = input.source(close, "RSI Source", group="RSI")⋯

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.

⋯// v 1.1-//@version=5+//@version=6strategy("Williams Fractals Strategy by ȼhąţhµяąɲǥą", overlay=true, default_qty_type=strategy.cash, default_qty_value=1000, currency='USD')⋯

Settings

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

SettingDefaultType and rangeFeeds
Appearance
Theme (no label in the script)darkstring · options ["light","dark"]ema_b_color ema_c_color
Show Fractalsfalseboolplotshape
Show EMAsfalseboolEMA A EMA B EMA C
Williams Fractals
Fractal Periods2int (written input.integer) · min 2upflagDownFrontier upflagUpFrontier0 upflagUpFrontier1 upflagUpFrontier2 upflagUpFrontier3 upflagUpFrontier4 downflagDownFrontier downflagUpFrontier0 downflagUpFrontier1 downflagUpFrontier2 downflagUpFrontier3 downflagUpFrontier4 line 27 line 43 plotshape
EMA
EMA Length A20int · min 1out_a
EMA Source Aclosesourceout_a
EMA Offset A0int (written input.integer) · min -500 · max 500EMA A
EMA Length B50int · min 1out_b
EMA Source Bclosesourceout_b
EMA Offset B0int (written input.integer) · min -500 · max 500EMA B
EMA Length C100int · min 1out_c
EMA Source Cclosesourceout_c
EMA Offset C0int (written input.integer) · min -500 · max 500EMA C
RSI
RSI Length14int · min 1up down
RSI Sourceclosesourceup down
Orders
Start Date1int (written input.integer) · min 1 · max 31inDateRange
Start Month1int (written input.integer) · min 1 · max 12inDateRange
Start Year2018int (written input.integer) · min 1800 · max 2100inDateRange
End Date1int (written input.integer) · min 1 · max 31inDateRange
End Month12int (written input.integer) · min 1 · max 12inDateRange
End Year2022int (written input.integer) · min 1800 · max 2100inDateRange
Long Take Profit (%)0.5float · min 0.0 · step 0.1longExitPrice
Short Take Profit (%)0.5float · min 0.0 · step 0.1shortExitPrice
Long Stop Loss (%)3.1float · min 0.0 · step 0.1longStopPrice
Short Stop Loss (%)3.1float · min 0.0 · step 0.1shortStopPrice

What it calculates

  • EMA (ema, ta.ema in v5)EMA Source A (close), EMA Length A (20)out_a · line 58
  • EMA (ema, ta.ema in v5)EMA Source B (close), EMA Length B (50)out_b · line 63
  • EMA (ema, ta.ema in v5)EMA Source C (close), EMA Length C (100)out_c · line 69
  • RMA / Change (rma, ta.rma in v5)max(change(rsi_src), 0), RSI Length (14)up · line 75
  • RMA / Change (rma, ta.rma in v5)-min(change(rsi_src), 0), RSI Length (14)down · line 76

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

The script has 68 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Long long(inDateRange and long and strategy.opentrades == 0)On119
Open Short short(inDateRange and short and strategy.opentrades == 0)On121
Exit ExL stop and limit(strategy.position_size > 0)On140
Exit ExS stop and limit(strategy.position_size < 0)On142
Close (not inDateRange)On145

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.

Settings heatmap

Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (EMA Length A 10, EMA Length B 25) made 0.0% before 26 Dec 2025 and 0.0% after it, against 0.0% for the defaults. 0% of the 64 combinations made money in-sample and 0% out-of-sample.

Before 26 Dec 2025 · in-sample
EMA Length B ↓ · EMA Length A →1012141720242834
250%0%0%0%0%0%0%0%
300%0%0%0%0%0%0%0%
350%0%0%0%0%0%0%0%
430%0%0%0%0%0%0%0%
500%0%0%0%0%0%0%0%
600%0%0%0%0%0%0%0%
700%0%0%0%0%0%0%0%
850%0%0%0%0%0%0%0%
From 26 Dec 2025 · out-of-sample
EMA Length B ↓ · EMA Length A →1012141720242834
250%0%0%0%0%0%0%0%
300%0%0%0%0%0%0%0%
350%0%0%0%0%0%0%0%
430%0%0%0%0%0%0%0%
500%0%0%0%0%0%0%0%
600%0%0%0%0%0%0%0%
700%0%0%0%0%0%0%0%
850%0%0%0%0%0%0%0%

Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. 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
Williams Fractals Strategy this page—v4 strategy0.0%00.0%
DCA After Downtrend v2 (by BHD_Trade_Bot) by BHD_Trade_Botema rmav5 strategyNo trades on this market
Strategy Myth-Busting #10 - InsideBar+EMA - [MYN] by myncryptoema rmav5 strategyNo trades on this market
Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10kema rmav4 strategy−19.4%3670.0%
Take Profit On Trend v2 (by BHD_Trade_Bot) by BHD_Trade_Botema rmav5 strategy+9.4%624.0%
Daytrade strategy RSI CCI EMA 4-8 by SoftKill21ema rmav4 strategy+0.0%260.0%

Where it runs

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

Zeal Terminal's engine currently reads an order side written as long = true, long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 119, 121) so the engine trades the way the script says.

“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/// © B_L_A_C_K_S_C_O_R_P_I_O_N// v 1.1//@version=4strategy("Williams Fractals Strategy by ȼhąţhµяąɲǥą", overlay=true, default_qty_type=strategy.cash, default_qty_value=1000, currency='USD')// *************Appearance*************theme = input(type=input.string, defval="dark", options=["light","dark"], group="Appearance")show_fractals = input(false, "Show Fractals", group="Appearance")show_ema = input(false, "Show EMAs", group="Appearance")// *************colors*************color_green = color.greencolor_red = color.redcolor_yellow = color.yellowcolor_orange = color.orangecolor_blue = color.bluecolor_white = color.white// *************WF*************// Define "n" as the number of periods and keep a minimum value of 2 for error handling.n = input(title="Fractal Periods", defval=2, minval=2, type=input.integer, group="Williams Fractals")// UpFractalbool upflagDownFrontier = truebool upflagUpFrontier0 = truebool upflagUpFrontier1 = truebool upflagUpFrontier2 = truebool upflagUpFrontier3 = truebool upflagUpFrontier4 = truefor i = 1 to n    upflagDownFrontier := upflagDownFrontier and (high[n-i] < high[n])    upflagUpFrontier0 := upflagUpFrontier0 and (high[n+i] < high[n])    upflagUpFrontier1 := upflagUpFrontier1 and (high[n+1] <= high[n] and high[n+i + 1] < high[n])    upflagUpFrontier2 := upflagUpFrontier2 and (high[n+1] <= high[n] and high[n+2] <= high[n] and high[n+i + 2] < high[n])    upflagUpFrontier3 := upflagUpFrontier3 and (high[n+1] <= high[n] and high[n+2] <= high[n] and high[n+3] <= high[n] and high[n+i + 3] < high[n])    upflagUpFrontier4 := upflagUpFrontier4 and (high[n+1] <= high[n] and high[n+2] <= high[n] and high[n+3] <= high[n] and high[n+4] <= high[n] and high[n+i + 4] < high[n])flagUpFrontier = upflagUpFrontier0 or upflagUpFrontier1 or upflagUpFrontier2 or upflagUpFrontier3 or upflagUpFrontier4upFractal = (upflagDownFrontier and flagUpFrontier)// downFractalbool downflagDownFrontier = truebool downflagUpFrontier0 = truebool downflagUpFrontier1 = truebool downflagUpFrontier2 = truebool downflagUpFrontier3 = truebool downflagUpFrontier4 = truefor i = 1 to n    downflagDownFrontier := downflagDownFrontier and (low[n-i] > low[n])    downflagUpFrontier0 := downflagUpFrontier0 and (low[n+i] > low[n])    downflagUpFrontier1 := downflagUpFrontier1 and (low[n+1] >= low[n] and low[n+i + 1] > low[n])    downflagUpFrontier2 := downflagUpFrontier2 and (low[n+1] >= low[n] and low[n+2] >= low[n] and low[n+i + 2] > low[n])    downflagUpFrontier3 := downflagUpFrontier3 and (low[n+1] >= low[n] and low[n+2] >= low[n] and low[n+3] >= low[n] and low[n+i + 3] > low[n])    downflagUpFrontier4 := downflagUpFrontier4 and (low[n+1] >= low[n] and low[n+2] >= low[n] and low[n+3] >= low[n] and low[n+4] >= low[n] and low[n+i + 4] > low[n])flagDownFrontier = downflagUpFrontier0 or downflagUpFrontier1 or downflagUpFrontier2 or downflagUpFrontier3 or downflagUpFrontier4downFractal = (downflagDownFrontier and flagDownFrontier)plotshape(downFractal and show_fractals, style=shape.triangleup, location=location.belowbar, offset=-n, color=color_green)plotshape(upFractal and show_fractals, style=shape.triangledown, location=location.abovebar, offset=-n, color=color_red)// *************EMA*************len_a = input(20, minval=1, title="EMA Length A", group="EMA")src_a = input(close, title="EMA Source A", group="EMA")offset_a = input(title="EMA Offset A", type=input.integer, defval=0, minval=-500, maxval=500, group="EMA")out_a = ema(src_a, len_a)plot(show_ema ? out_a : na, title="EMA A", color=color_green, offset=offset_a)len_b = input(50, minval=1, title="EMA Length B", group="EMA")src_b = input(close, title="EMA Source B", group="EMA")offset_b = input(title="EMA Offset B", type=input.integer, defval=0, minval=-500, maxval=500, group="EMA")out_b = ema(src_b, len_b)ema_b_color = (theme == "dark") ? color_yellow : color_orangeplot(show_ema ? out_b : na, title="EMA B", color=ema_b_color, offset=offset_b)len_c = input(100, minval=1, title="EMA Length C", group="EMA")src_c = input(close, title="EMA Source C", group="EMA")offset_c = input(title="EMA Offset C", type=input.integer, defval=0, minval=-500, maxval=500, group="EMA")out_c = ema(src_c, len_c)ema_c_color = (theme == "dark") ? color_white : color_blueplot(show_ema ? out_c : na, title="EMA C", color=ema_c_color, offset=offset_c)// *************RSI*************rsi_len = input(14, minval=1, title="RSI Length", group="RSI")rsi_src = input(close, "RSI Source", type = input.source, group="RSI")up = rma(max(change(rsi_src), 0), rsi_len)down = rma(-min(change(rsi_src), 0), rsi_len)rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))// *************Calculation*************long = (out_a > out_b) and (out_a > out_c) and downFractal and low[2] > out_c and rsi[2] < rsishort = (out_a < out_b) and (out_a < out_c) and upFractal and high[2] < out_c and rsi[2] > rsiplotshape(long, style=shape.labelup, color=color_green, location=location.belowbar, title="long label", text= "L", textcolor=color_white)plotshape(short, style=shape.labeldown, color=color_red, location=location.abovebar, title="short label", text= "S", textcolor=color_white)// *************End of Signals calculation*************// Make input options that configure backtest date rangestartDate = input(title="Start Date", type=input.integer,     defval=1, minval=1, maxval=31, group="Orders")startMonth = input(title="Start Month", type=input.integer,     defval=1, minval=1, maxval=12, group="Orders")startYear = input(title="Start Year", type=input.integer,     defval=2018, minval=1800, maxval=2100, group="Orders")endDate = input(title="End Date", type=input.integer,     defval=1, minval=1, maxval=31, group="Orders")endMonth = input(title="End Month", type=input.integer,     defval=12, minval=1, maxval=12, group="Orders")endYear = input(title="End Year", type=input.integer,     defval=2022, minval=1800, maxval=2100, group="Orders")// Look if the close time of the current bar// falls inside the date rangeinDateRange = (time >= timestamp(syminfo.timezone, startYear,         startMonth, startDate, 0, 0)) and     (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))// Make inputs that set the take profit % (optional)longProfitPerc = input(title="Long Take Profit (%)",     type=input.float, minval=0.0, step=0.1, defval=0.5, group="Orders") * 0.01shortProfitPerc = input(title="Short Take Profit (%)",     type=input.float, minval=0.0, step=0.1, defval=0.5, group="Orders") * 0.01// Figure out take profit pricelongExitPrice  = strategy.position_avg_price * (1 + longProfitPerc)shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)// Plot take profit values for confirmationplot(series=(strategy.position_size > 0) ? longExitPrice : na,     color=color_green, style=plot.style_circles,     linewidth=1, title="Long Take Profit")plot(series=(strategy.position_size < 0) ? shortExitPrice : na,     color=color_green, style=plot.style_circles,     linewidth=1, title="Short Take Profit")// Submit entry ordersif (inDateRange and long and strategy.opentrades == 0)    strategy.entry(id="Long", long=true)if (inDateRange and short and strategy.opentrades == 0)    strategy.entry(id="Short", long=false)    // Set stop loss level with input options (optional)longLossPerc = input(title="Long Stop Loss (%)",     type=input.float, minval=0.0, step=0.1, defval=3.1, group="Orders") * 0.01shortLossPerc = input(title="Short Stop Loss (%)",     type=input.float, minval=0.0, step=0.1, defval=3.1, group="Orders") * 0.01// Determine stop loss pricelongStopPrice  = strategy.position_avg_price * (1 - longLossPerc)shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)// Plot stop loss values for confirmationplot(series=(strategy.position_size > 0) ? longStopPrice : na,     color=color_red, style=plot.style_cross,     linewidth=1, title="Long Stop Loss")plot(series=(strategy.position_size < 0) ? shortStopPrice : na,     color=color_red, style=plot.style_cross,     linewidth=1, title="Short Stop Loss")// Submit exit orders based on calculated stop loss priceif (strategy.position_size > 0)    strategy.exit(id="ExL",limit=longExitPrice, stop=longStopPrice)if (strategy.position_size < 0)    strategy.exit(id="ExS", limit=shortExitPrice, stop=shortStopPrice)// Exit open market position when date range endsif (not inDateRange)    strategy.close_all()