Pine Script v5 · Strategy
TICK Scalping strategy, SPY 1 min
A Pine Script v5 strategy built on RMA (ta.tr, 4), EMA (tickC, 21) and WMA (_src, _length). It has 20 order rules, 6 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays 0.0625 commission. 49 settings; defaults include Start Year 2011, Start Month 1 and Start Day 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 TICK Scalping strategy, SPY 1 min repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: the script acts only when barstate.isconfirmed is true, which Zeal Terminal's engine never reports during a live replay (it does not run a bar's closing update in live mode), so the replay cannot test this script.
- How did TICK Scalping strategy, SPY 1 min 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.
- Does TICK Scalping strategy, SPY 1 min 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.
- Does TICK Scalping strategy, SPY 1 min use a stop loss?
- Yes
- strategy.exit sets a stop on line 278, 279, 281, 282.
- Does TICK Scalping strategy, SPY 1 min run in Zeal Terminal?
- Yes
- It compiles in 126 ms and runs 1,000 bars in 262 ms, in the browser.
BTCUSDT · 1D · default settings
- HLine
- HLine
- HLine
- HLine
- HLine
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs VIX D data, not available: not a Binance spot market Needs USI:TICK 5 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Values that depend on it are empty on this chart.
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $5,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
1 setting does nothing
“TICK divergence lookback period (only if trading TICK divergence” 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 283, 284, 285, 286, 287, 288. The upgraded version below moves each call inside an if block.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Use As Indicator OnlyDisables strategy signals | false | bool | line 240 |
| Trading window | |||
| Start Year | 2011 | int | timestart |
| Start Month | 1 | int · min 1 · max 12 | timestart |
| Start Day | 1 | int · min 1 · max 31 | timestart |
| Finish Year | 2050 | int | timefinish |
| Finish Month | 12 | int · min 1 · max 12 | timefinish |
| Finish Day | 31 | int · min 1 · max 31 | timefinish |
| Trading Options | |||
| Trading Options only | true | bool | line 202 |
| # of options per trade | 10 | int | trade_amount |
| Multiplier for trading options (adjust to approx. options P&L) | 0.007 | float · step 0.001 | trade_amount |
| Reinvest profit | false | bool | line 203 |
| Reinvest percentage | 20 | float | trade_amount |
| Trade with TICK divergences | true | bool | entry Long entry Short line 244 line 250 |
| TICK divergence lookback period (only if trading TICK divergence | 5 | int | unused |
| Trade with optimal Stochastic | true | bool | line 225 |
| Lookback period for entry condition, waiting for Stochastic | 12 | int | line 226 line 230 |
| Stochastic RSI k value offset from 50 for entry threshold (ie. 10 means long entry under k=60 | 0 | int | L_entry1 S_entry1 |
| Trade with Chasing entries | true | bool | entry Long entry Short line 246 line 252 |
| Chase entry lookback period | 10 | int | L_entry3 S_entry3 |
| Stochastic RSI k value offset from 50 for chase entry threshold (ie. 30 means long entry under k=80 | 30 | int | L_entry3 S_entry3 |
| Trade with Price Target | true | bool | exit Exit exit Exit exit Exit exit Exit line 277 |
| No entry between 10 - 10:30 | false | bool | line 211 |
| Hold 1/2 position overnight on Tues/Thurs | true | bool | line 292 |
| Minimum bars to hold order | 6 | int | close Long close Short close Long close Short close Long close Short line 276 |
| Daily ATR | |||
| ATR period | 4 | int · min 1 | datr |
| % ATR to use for SL | 9 | float · min 1 · max 100 · step 0.5 | SL_atr |
| % ATR to use for PT (only if trading w/ PT) | 17.5 | float · min 1 · max 100 · step 0.5 | PT_atr |
| VIX Volatility Index | |||
| VIX Threshold for entry | 20.0 | float · step 0.5 | L_entry0 S_entry0 L_entry2 S_entry2 L_entry3 S_entry3 |
| TICK Indicator | |||
| Fast EMA period | 21 | int | tickAVG |
| Slow EMA period | 102 | int | tickAVG_L |
| Hull MA period | 135 | int | tickHMA |
| Hull MA Smoothing | 25 | int | tickHMA_MA |
| TICK Divergence | |||
| Pivot Lookback Right | 5 | int | plFound phFound oscHL priceLL oscLL priceHL oscLH priceHH oscHH priceLH Regular Bullish Regular Bullish Label Hidden Bullish Hidden Bullish Label Regular Bearish Regular Bearish Label Hidden Bearish Hidden Bearish Label |
| Pivot Lookback Left | 10 | int | plFound phFound |
| Max of Lookback Range | 300 | int | line 127 |
| Min of Lookback Range | 25 | int | line 127 |
| Plot Bullish | true | bool | bullCond |
| Plot Hidden Bullish | false | bool | hiddenBullCond |
| Plot Bearish | true | bool | bearCond |
| Plot Hidden Bearish | false | bool | hiddenBearCond |
| RSI | |||
| RSI Length | 70 | int · min 1 | rsi_up rsi_down |
| RSI Signal Length | 6 | int · min 1 | rsi_ma |
| RSI Overbought/Oversold levels +/- from 50 | 15 | int | L_entry0 S_entry0 L_entry3 S_entry3 |
| Fast RSI Length | 14 | int · min 1 | rsi_up2 rsi_down2 |
| Stochastic RSI | |||
| Stoch K | 3 | int · min 1 | k |
| Stoch D | 3 | int · min 1 | d |
| RSI Length | 14 | int · min 1 | rsi_stoch |
| Stochastic Length | 14 | int · min 1 | k |
| Moving Averages | |||
| Filtering EMA | 20 | int · min 1 | ema1 |
What it calculates
- RMAta.tr, ATR period (4)
datr · line 61 - EMAtickC, Fast EMA period (21)
tickAVG · line 79 - EMAtickC, Slow EMA period (102)
tickAVG_L · line 80 - WMA2 * ta.wma(_src, _length / 2) - ta.wma(_src, _length), math.round(math.sqrt(_length))
_return · line 82 - SMAtickHMA, Hull MA Smoothing (25)
tickHMA_MA · line 85 - PivotlowtickC, Pivot Lookback Left (10), Pivot Lookback Right (5)
plFound · line 123 - PivothightickC, Pivot Lookback Left (10), Pivot Lookback Right (5)
phFound · line 124 - RMA / Changemath.max(ta.change(src), 0), RSI Length (70)
rsi_up · line 168 - RMA / Change-math.min(ta.change(src), 0), RSI Length (70)
rsi_down · line 169 - WMArsi, RSI Signal Length (6)
rsi_ma · line 171 - RMA / Changemath.max(ta.change(src), 0), Fast RSI Length (14)
rsi_up2 · line 177 - RMA / Change-math.min(ta.change(src), 0), Fast RSI Length (14)
rsi_down2 · line 178 - RSIsrc, RSI Length (14)
rsi_stoch · line 186 - SMA / Stochta.stoch(rsi_stoch, rsi_stoch, rsi_stoch, lengthStoch), Stoch K (3)
k · line 187 - SMAk, Stoch D (3)
d · line 188 - EMAma_src, Filtering EMA (20)
ema1 · line 192 - BarssinceL_entry0
BSL · line 221 - BarssinceS_entry0
BSS · line 222 - Lowestlow, 5
long_SL · line 255 - Highesthigh, 5
short_SL · line 256
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 131 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | L_entry1 and window and not(trade_pause) and not(trade_pause2) and barstate.isconfirmed | On | 242 |
| Open Long long | trade_TICKdiverg and L_entry2 and window and not(trade_pause) and not(trade_pause2) and barstate.isconfirmed and strategy.opentrades == 0 | On | 245 |
| Open Long long | trade_chase and L_entry3 and window and not(trade_pause) and not(trade_pause2) and barstate.isconfirmed and strategy.opentrades == 0 | On | 247 |
| Open Short short | S_entry1 and window and not(trade_pause) and not(trade_pause2) and barstate.isconfirmed | On | 249 |
| Open Short short | trade_TICKdiverg and S_entry2 and window and not(trade_pause) and not(trade_pause2) and barstate.isconfirmed and strategy.opentrades == 0 | On | 251 |
| Open Short short | trade_chase and S_entry3 and window and not(trade_pause) and not(trade_pause2) and barstate.isconfirmed and strategy.opentrades == 0 | On | 253 |
| Exit Exit stop and limit | trade_PT | On “Trade with Price Target” | 278 |
| Exit Exit stop and limit | trade_PT | On “Trade with Price Target” | 279 |
| Exit Exit stop | trade_PT | On “Trade with Price Target” | 281 |
| Exit Exit stop | trade_PT | On “Trade with Price Target” | 282 |
| Close Long | L_exit1tickHMA < tickHMA_MA and rsi_bear | On | 283 |
| Close Short | S_exit1tickHMA > tickHMA_MA and rsi_bull | On | 284 |
| Close Long | L_exit2 | On | 285 |
| Close Short | S_exit2 | On | 286 |
| Close Long | L_exit3tickH > 1000 | On | 287 |
| Close Short | S_exit3tickL < -1000 | On | 288 |
| Close | time(timeframe.period, "1550-1551:246") | On | 294 |
| Close Long | time(timeframe.period, "1550-1551:35") | On | 296 |
| Close Short | time(timeframe.period, "1550-1551:35") | On | 297 |
| Close | time(timeframe.period, "1550-1551:23456") | On | 300 |
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.
- ClearHigher-timeframe data5 request.security call(s), none with lookahead on.
- 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
Not run on other markets: the script requests VIX D, USI:TICK 5, and that data is not available here (not a Binance spot market; a lower timeframe than the chart; the engine does not evaluate intrabar data). Its results would rest on empty values.
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| TICK Scalping strategy, SPY 1 min this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| MACD 5 iN 1 [Pro-Tool] by HamidBox | sma ema rsi pivotlow pivothigh highest lowest | v4 strategy | No trades on this market | ||
| X48 - Strategy - MA Type Cross + TPSL - Future&Spot - V.2 by X4815162342 | ema rsi sma highest lowest pivothigh pivotlow | v5 strategy | does not run in Zeal Terminal | ||
| HAERI 𝐍𝐄𝐓𝐖𝐎𝐑𝐊 by ahhanegin | ema wma rsi pivotlow pivothigh sma highest lowest rma barssince | v4 strategy | does not run in Zeal Terminal | ||
| MACD Willy Strategy by PtGambler | rma sma ema highest lowest wma | v5 strategy | No trades on this market | ||
| TICK strategy for SPY options by PtGambler | rma ema wma pivotlow pivothigh sma | v5 strategy | No trades on this market | ||
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 6 strategy calls use the when = argument (line 283, 284, 285, 286, 287, 288). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 10 settings use the untyped input() (line 26, 29, 109, 110, 111, 112, 113, 114, 115, 116). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 26: input() → input.int()
- Line 29: input() → input.int()
- Line 109: input() → input.int()
- Line 110: input() → input.int()
- Line 111: input() → input.int()
- Line 112: input() → input.int()
10 more edits
- Line 113: input() → input.bool()
- Line 114: input() → input.bool()
- Line 115: input() → input.bool()
- Line 116: input() → input.bool()
- Line 283: when = L_exit1 → if block
- Line 284: when = S_exit1 → if block
- Line 285: when = L_exit2 → if block
- Line 286: when = S_exit2 → if block
- Line 287: when = L_exit3 → if block
- Line 288: when = S_exit3 → if block
⋯// ******************** Trade Period **************************************-startY = input(title='Start Year', defval=2011, group = "Trading window")+startY = input.int(title='Start Year', defval=2011, group = "Trading window")startM = input.int(title='Start Month', defval=1, minval=1, maxval=12, group = "Trading window")startD = input.int(title='Start Day', defval=1, minval=1, maxval=31, group = "Trading window")-finishY = input(title='Finish Year', defval=2050, group = "Trading window")+finishY = input.int(title='Finish Year', defval=2050, group = "Trading window")finishM = input.int(title='Finish Month', defval=12, minval=1, maxval=12, group = "Trading window")⋯bgcolor(tickC < -999 ? color.new(color.red,30) : na)-lbR = input(title='Pivot Lookback Right', defval=5, group = "TICK Divergence")+lbR = input.int(title='Pivot Lookback Right', defval=5, group = "TICK Divergence")-lbL = input(title='Pivot Lookback Left', defval=10, group = "TICK Divergence")+lbL = input.int(title='Pivot Lookback Left', defval=10, group = "TICK Divergence")-rangeUpper = input(title='Max of Lookback Range', defval=300, group = "TICK Divergence")+rangeUpper = input.int(title='Max of Lookback Range', defval=300, group = "TICK Divergence")-rangeLower = input(title='Min of Lookback Range', defval=25, group = "TICK Divergence")+rangeLower = input.int(title='Min of Lookback Range', defval=25, group = "TICK Divergence")-plotBull = input(title='Plot Bullish', defval=true, group = "TICK Divergence")+plotBull = input.bool(title='Plot Bullish', defval=true, group = "TICK Divergence")-plotHiddenBull = input(title='Plot Hidden Bullish', defval=false, group = "TICK Divergence")+plotHiddenBull = input.bool(title='Plot Hidden Bullish', defval=false, group = "TICK Divergence")-plotBear = input(title='Plot Bearish', defval=true, group = "TICK Divergence")+plotBear = input.bool(title='Plot Bearish', defval=true, group = "TICK Divergence")-plotHiddenBear = input(title='Plot Hidden Bearish', defval=false, group = "TICK Divergence")+plotHiddenBear = input.bool(title='Plot Hidden Bearish', defval=false, group = "TICK Divergence")bearColor = color.red⋯ strategy.exit("Exit", "Short", stop = short_SL, comment = "SL hit")- strategy.close("Long", when = L_exit1, comment = "Exit, TICK/RSI reversal") + if L_exit1+ strategy.close("Long", comment = "Exit, TICK/RSI reversal") - strategy.close("Short", when = S_exit1, comment = "Exit, TICK/RSI reversal")+ if S_exit1+ strategy.close("Short", comment = "Exit, TICK/RSI reversal")- strategy.close("Long", when = L_exit2, comment = "Exit, Bearish Divergence") + if L_exit2+ strategy.close("Long", comment = "Exit, Bearish Divergence") - strategy.close("Short", when = S_exit2, comment = "Exit, Bullish Divergence")+ if S_exit2+ strategy.close("Short", comment = "Exit, Bullish Divergence")- strategy.close("Long", when = L_exit3, comment = "Exit, TICK overbought") + if L_exit3+ strategy.close("Long", comment = "Exit, TICK overbought") - strategy.close("Short", when = S_exit3, comment = "Exit, TICK oversold")+ if S_exit3+ strategy.close("Short", comment = "Exit, TICK oversold") // strategy.close("Long", when = L_exit4, comment = "Exit, TICK/RSI reversal 2") ⋯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.
⋯// - There is an option to show P/L for reinvesting profits-//@version=5+//@version=6strategy("TICK strategy, SPY 1 min", overlay=false, pyramiding=3, initial_capital=5000, commission_type=strategy.commission.cash_per_contract, commission_value = 0.0625) ⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 126 ms | With a workaround 1,000 bars in 262 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
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.
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/// © platsn// How it works:// When trading the indices, many rely on the TICK for market directions. This strategy is a trend following strategy that uses a combination of conditions using the following indicators:// - TICK// - RSI// - VIX volatility index// - EMA// For entries, the conditions are:// 1. TICK moving average crossover with a delayed signal line// 2. Bullish or bearish RSI signal, RSI > 50 for bullish , < 50 for bearish// 3. VIX must be above a certain threshold to take advantage of high market volatility// 4. Price must be on top of EMA line for long, and below for short// 5. Price has not moved significantly already (this delta can be set)// For exits, there are 3 scenarios:// 1. Stop loss set by a percentage of the daily ATR value// 2. Trend changes on the TICK and the RSI// 3. Bearish or bullish divergence on price with TICK// This strategy automatically signal to close all trades at 3:50 pm EST at the end of the day.// Extras:// - There is an option to show P/L for reinvesting profits//@version=5strategy("TICK strategy, SPY 1 min", overlay=false, pyramiding=3, initial_capital=5000, commission_type=strategy.commission.cash_per_contract, commission_value = 0.0625) indicator_only = input.bool(false,"Use As Indicator Only", tooltip = "Disables strategy signals")// ******************** Trade Period **************************************startY = input(title='Start Year', defval=2011, group = "Trading window")startM = input.int(title='Start Month', defval=1, minval=1, maxval=12, group = "Trading window")startD = input.int(title='Start Day', defval=1, minval=1, maxval=31, group = "Trading window")finishY = input(title='Finish Year', defval=2050, group = "Trading window")finishM = input.int(title='Finish Month', defval=12, minval=1, maxval=12, group = "Trading window")finishD = input.int(title='Finish Day', defval=31, minval=1, maxval=31, group = "Trading window")timestart = timestamp(startY, startM, startD, 00, 00)timefinish = timestamp(finishY, finishM, finishD, 23, 59)t1 = time(timeframe.period, "0930-1545:23456")window = time >= timestart and time <= timefinish and t1 ? true : false t2 = time(timeframe.period, "0930-1555:23456")window2 = time >= timestart and time <= timefinish and t2 ? true : false trade_options = input.bool(defval=true,title="Trading Options only", group = "Trading Options")option_amt = input.int(defval=10,title="# of options per trade", group = "Trading Options")option_multiplier = input.float(0.007, title="Multiplier for trading options (adjust to approx. options P&L)", step=0.001, group = "Trading Options")reinvest = input.bool(defval=false,title="Reinvest profit", group = "Trading Options")reinvest_percent = input.float(defval=20, title = "Reinvest percentage", group="Trading Options")trade_TICKdiverg = input.bool(true, title="Trade with TICK divergences", group = "Trading Options")diverg_lookback = input.int(defval=5, title="TICK divergence lookback period (only if trading TICK divergence", group = "Trading Options")trade_optimal = input.bool(true, title="Trade with optimal Stochastic", group = "Trading Options")entry_lookback = input.int(defval=12, title="Lookback period for entry condition, waiting for Stochastic", group = "Trading Options")k_entry_thres = input.int(defval=0, title="Stochastic RSI k value offset from 50 for entry threshold (ie. 10 means long entry under k=60", group = "Trading Options")trade_chase = input.bool(true, title="Trade with Chasing entries", group = "Trading Options")chase_lookback = input.int(defval=10, title="Chase entry lookback period", group = "Trading Options")k_chase_thres = input.int(defval=30, title="Stochastic RSI k value offset from 50 for chase entry threshold (ie. 30 means long entry under k=80", group = "Trading Options")trade_PT = input.bool(true, title="Trade with Price Target", group = "Trading Options")no_longat10 = input.bool(false, title="No entry between 10 - 10:30", group = "Trading Options")hold_ON = input.bool(true, title="Hold 1/2 position overnight on Tues/Thurs", group = "Trading Options")// ***************************************************************************************************** Daily ATR *****************************************************atrlen = input.int(4, minval=1, title="ATR period", group = "Daily ATR")SL_atr_perc = input.float(9, minval=1, maxval=100, step=0.5, title="% ATR to use for SL", group = "Daily ATR")PT_atr_perc = input.float(17.5, minval=1, maxval=100, step=0.5, title="% ATR to use for PT (only if trading w/ PT)", group = "Daily ATR") SL_atr = SL_atr_perc * 0.01PT_atr = PT_atr_perc * 0.01datr = request.security(syminfo.tickerid, "1D", ta.rma(ta.tr, atrlen))d_SL_atr = datr * SL_atrd_PT_atr = datr * PT_atr// plot(datr,"Daily ATR")// plot(d_SL_atr, "Daily % ATR")//*********************************************************** VIX volatility index ****************************************VIX = request.security("VIX", timeframe.period, close)vix_thres = input.float(20.0, "VIX Threshold for entry", step=0.5, group="VIX Volatility Index")// ***************************************************** TICK Indictor *****************************************************malen1 = input.int(21, title = "Fast EMA period", group = "TICK Indicator")malen2 = input.int(102, title = "Slow EMA period", group = "TICK Indicator")malen3 = input.int(135, title = "Hull MA period", group = "TICK Indicator")malen4 = input.int(25, title = "Hull MA Smoothing", group = "TICK Indicator")//get TICK data// tickO = request.security("USI:TICK", timeframe.period, open)tickH = request.security("USI:TICK", "5", high)tickC = request.security("USI:TICK", "5", close)tickL = request.security("USI:TICK", "5", low)tickAVG = ta.ema(tickC,malen1)tickAVG_L = ta.ema(tickC,malen2)f_hma(_src, _length) => _return = ta.wma(2 * ta.wma(_src, _length / 2) - ta.wma(_src, _length), math.round(math.sqrt(_length))) _returntickHMA = f_hma(tickC, malen3)tickHMA_MA = ta.sma(tickHMA, malen4)tick_bull = tickAVG > tickAVG[5]tick_bear = tickAVG < tickAVG[5]//Plot Tick dataplot(barstate.isconfirmed? tickC : na, title='TICK', color = color.new(color.white,30) , style=plot.style_line, linewidth = 1) //color = tickC > 0 ? color.green : color.redplot(tickAVG, title='TICK 9 EMA', color = color.yellow, style=plot.style_line, linewidth = 1)plot(tickAVG_L, title='TICK 21 EMA', color = color.new(color.red,70), style=plot.style_line, linewidth = 1)plot(tickHMA, title='TICK 21 HMA', color = color.blue, style=plot.style_line, linewidth = 2)plot(tickHMA_MA, title='TICK HMA Smoothed', color = color.purple, style=plot.style_line, linewidth = 2)hline(0, color=color.white, linewidth = 1, linestyle = hline.style_solid)hline(1000, color=color.green, linestyle=hline.style_solid, linewidth = 2)hline(500, color=color.gray, linestyle=hline.style_dashed)hline(-1000, color=color.red, linestyle=hline.style_solid, linewidth = 2)hline(-500, color=color.gray, linestyle=hline.style_dashed)// plotshape(ta.crossunder(tickHMA,tickAVG) ,"Cross down", color=color.red, style=shape.triangledown, location = location.top, size =size.tiny)// plotshape(ta.crossover(tickHMA,tickAVG) ,"Cross up", color=color.green, style=shape.triangleup, location = location.bottom, size =size.tiny)plotshape(ta.crossunder(tickHMA,tickHMA_MA) ,"Cross down", color=color.red, style=shape.triangledown, location = location.top, size =size.tiny)plotshape(ta.crossover(tickHMA,tickHMA_MA) ,"Cross up", color=color.green, style=shape.triangleup, location = location.bottom, size =size.tiny)//Backgroundbgcolor(tickAVG_L > 0 ? color.new(color.green, 90) : color.new(color.red, 90))bgcolor(tickC > 499 ? color.new(color.green, 70) : na)bgcolor(tickC < -499 ? color.new(color.red, 70) : na)bgcolor(tickC > 999 ?color.new(color.green,30) : na)bgcolor(tickC < -999 ? color.new(color.red,30) : na)lbR = input(title='Pivot Lookback Right', defval=5, group = "TICK Divergence")lbL = input(title='Pivot Lookback Left', defval=10, group = "TICK Divergence")rangeUpper = input(title='Max of Lookback Range', defval=300, group = "TICK Divergence")rangeLower = input(title='Min of Lookback Range', defval=25, group = "TICK Divergence")plotBull = input(title='Plot Bullish', defval=true, group = "TICK Divergence")plotHiddenBull = input(title='Plot Hidden Bullish', defval=false, group = "TICK Divergence")plotBear = input(title='Plot Bearish', defval=true, group = "TICK Divergence")plotHiddenBear = input(title='Plot Hidden Bearish', defval=false, group = "TICK Divergence")bearColor = color.redbullColor = color.greenhiddenBullColor = color.new(color.green, 80)hiddenBearColor = color.new(color.red, 80)textColor = color.whitenoneColor = color.new(color.white, 100)plFound = na(ta.pivotlow(tickC, lbL, lbR)) ? false : truephFound = na(ta.pivothigh(tickC, lbL, lbR)) ? false : true_inRange(cond) => bars = ta.barssince(cond == true) rangeLower <= bars and bars <= rangeUpper//----------------------------------------------- TICK Divergence -------------------------------// Regular Bullish// Osc: Higher LowoscHL = tickC[lbR] > ta.valuewhen(plFound, tickC[lbR], 1) and _inRange(plFound[1])// Price: Lower LowpriceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)bullCond = plotBull and priceLL and oscHL and plFoundplot(plFound ? tickC[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, color=bullCond ? bullColor : noneColor)plotshape(bullCond ? tickC[lbR] : na, offset=-lbR, title='Regular Bullish Label', text=' Bull ', style=shape.labelup, location=location.absolute, color=color.new(bullColor, 0), textcolor=color.new(textColor, 0))//------------------------------------------------------------------------------// Hidden Bullish// Osc: Lower LowoscLL = tickC[lbR] < ta.valuewhen(plFound, tickC[lbR], 1) and _inRange(plFound[1])// Price: Higher LowpriceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFoundplot(plFound ? tickC[lbR] : na, offset=-lbR, title='Hidden Bullish', linewidth=2, color=hiddenBullCond ? hiddenBullColor : noneColor)plotshape(hiddenBullCond ? tickC[lbR] : na, offset=-lbR, title='Hidden Bullish Label', text=' H Bull ', style=shape.labelup, location=location.absolute, color=color.new(bullColor, 0), textcolor=color.new(textColor, 0))//------------------------------------------------------------------------------// Regular Bearish// Osc: Lower HighoscLH = tickC[lbR] < ta.valuewhen(phFound, tickC[lbR], 1) and _inRange(phFound[1])// Price: Higher HighpriceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)bearCond = plotBear and priceHH and oscLH and phFoundplot(phFound ? tickC[lbR] : na, offset=-lbR, title='Regular Bearish', linewidth=2, color=bearCond ? bearColor : noneColor)plotshape(bearCond ? tickC[lbR] : na, offset=-lbR, title='Regular Bearish Label', text=' Bear ', style=shape.labeldown, location=location.absolute, color=color.new(bearColor, 0), textcolor=color.new(textColor, 0))//------------------------------------------------------------------------------// Hidden Bearish// Osc: Higher HighoscHH = tickC[lbR] > ta.valuewhen(phFound, tickC[lbR], 1) and _inRange(phFound[1])// Price: Lower HighpriceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFoundplot(phFound ? tickC[lbR] : na, offset=-lbR, title='Hidden Bearish', linewidth=2, color=hiddenBearCond ? hiddenBearColor : noneColor)plotshape(hiddenBearCond ? tickC[lbR] : na, offset=-lbR, title='Hidden Bearish Label', text=' H Bear ', style=shape.labeldown, location=location.absolute, color=color.new(bearColor, 0), textcolor=color.new(textColor, 0))//-------------------------------------------------------- RSI ------------------------------------src = close //request.security(syminfo.ticker, "5",close)rsi_len = input.int(70, minval=1, title="RSI Length", group = "RSI")rsi_ma_len = input.int(6, minval=1, title="RSI Signal Length", group = "RSI")rsi_up = ta.rma(math.max(ta.change(src), 0), rsi_len)rsi_down = ta.rma(-math.min(ta.change(src), 0), rsi_len)rsi = rsi_down == 0 ? 100 : rsi_up == 0 ? 0 : 100 - (100 / (1 + rsi_up / rsi_down))rsi_ma = ta.wma(rsi,rsi_ma_len)rsi_avg = rsi_ma//math.avg(rsi,rsi_ma)rsi_bull = rsi_avg > rsi_avg[1]rsi_bear = rsi_avg < rsi_avg[1]rsi_thres = input.int(15,"RSI Overbought/Oversold levels +/- from 50", group = "RSI")rsi_len2 = input.int(14, minval=1, title="Fast RSI Length", group = "RSI")rsi_up2 = ta.rma(math.max(ta.change(src), 0), rsi_len2)rsi_down2 = ta.rma(-math.min(ta.change(src), 0), rsi_len2)rsi2 = rsi_down2 == 0 ? 100 : rsi_up2 == 0 ? 0 : 100 - (100 / (1 + rsi_up2 / rsi_down2))//-------------------------------------------------------- Stochastic RSI ------------------------------------// Stochastic Main ParameterssmoothK = input.int(3, minval=1, title='Stoch K', group = "Stochastic RSI")smoothD = input.int(3, minval=1, title='Stoch D', group = "Stochastic RSI")lengthRSI = input.int(14, "RSI Length", minval=1, group = "Stochastic RSI")lengthStoch = input.int(14, "Stochastic Length", minval=1, group = "Stochastic RSI")rsi_stoch = ta.rsi(src, lengthRSI)k = ta.sma(ta.stoch(rsi_stoch, rsi_stoch, rsi_stoch, lengthStoch), smoothK)d = ta.sma(k, smoothD)//-------------------------------------------------------- Moving Average ------------------------------------ma_src = closeemalen1 = input.int(20, minval=1, title='Filtering EMA', group= "Moving Averages")ema1 = ta.ema(ma_src, emalen1)//------------------------------------------------------------- Trade options ------------------------profit = strategy.netprofittrade_amount = math.floor(strategy.initial_capital / close) BSLE()=> strategy.opentrades > 0 ? (bar_index - strategy.opentrades.entry_bar_index(strategy.opentrades-1)) : na BSLExit()=> strategy.opentrades == 0 ? (bar_index - strategy.closedtrades.exit_bar_index(strategy.closedtrades-1)) : namin_hold = input.int(6,"Minimum bars to hold order", group = "Trading Options")if trade_options if strategy.netprofit > 0 and reinvest// and strategy.closedtrades.profit(strategy.closedtrades-1) > 0 trade_amount := math.floor(strategy.initial_capital * option_multiplier) * (option_amt + math.floor(((profit*reinvest_percent*0.01)/strategy.initial_capital)*10)) else trade_amount := math.floor(strategy.initial_capital * option_multiplier) * option_amt// **************************************************************************************************************************************** Trade Pauses ****************************************bool trade_pause = falsebool trade_pause2 = falsetrade_pause := falseif no_longat10 and time(timeframe.period, "1000-1030:23456") trade_pause2 := trueelse trade_pause2 := false // ---------------------------------------------------------------- Entry Conditions ------------------------------------------------------------L_entry0 = ta.crossover(tickHMA, tickHMA_MA) and rsi_avg > 50 and rsi < 50 + rsi_thres and VIX > vix_thres and tickAVG > 0 and close > ema1 S_entry0 = ta.crossunder(tickHMA,tickHMA_MA) and rsi_avg < 50 and rsi > 50 - rsi_thres and VIX > vix_thres and tickAVG < 0 and close < ema1L_entry1 = L_entry0S_entry1 = S_entry0 BSL = ta.barssince(L_entry0)BSS = ta.barssince(S_entry0)// plot(BSL, "Bars since long entry condition")// plot(BSS, "Bars since short entry condition")if trade_optimal and strategy.opentrades == 0 if BSL < entry_lookback L_entry1 := k < 50 + k_entry_thres and k > k[1] else L_entry1 := L_entry0 if BSS < entry_lookback S_entry1 := k > 50 - k_entry_thres and k < k[1] else S_entry1 := S_entry0// plotshape(L_entry0 ,"Long entry condition", color=color.blue, style=shape.triangleup, location = location.bottom, size =size.tiny)// plotshape(S_entry0 ,"Short entry condition", color=color.orange, style=shape.triangledown, location = location.top, size =size.tiny)L_entry2 = bullCond and tickHMA > tickHMA_MA and rsi > rsi_ma and VIX > vix_thres and tickAVG > 0 and close > ema1 S_entry2 = bearCond and tickHMA < tickHMA_MA and rsi < rsi_ma and VIX > vix_thres and tickAVG < 0 and close < ema1 L_entry3 = BSLExit() < chase_lookback and close > close[BSLExit()] and tickHMA > tickHMA_MA and tickHMA > tickHMA[1] and rsi_avg > 50 and rsi < 50 + rsi_thres and VIX > vix_thres and tickAVG > tickAVG[1] and close > ema1 and k < 50 + k_chase_thres S_entry3 = BSLExit() < chase_lookback and close < close[BSLExit()] and tickHMA < tickHMA_MA and tickHMA < tickHMA[1] and rsi_avg < 50 and rsi > 50 - rsi_thres and VIX > vix_thres and tickAVG < tickAVG[1] and close < ema1 and k > 50 - k_chase_thres if not indicator_only if L_entry1 and window and not(trade_pause) and not(trade_pause2) and barstate.isconfirmed strategy.entry("Long", strategy.long, trade_amount, comment="Long") if trade_TICKdiverg and L_entry2 and window and not(trade_pause) and not(trade_pause2) and barstate.isconfirmed and strategy.opentrades == 0 //limit to 1 entry, ignoring pyramiding strategy.entry("Long", strategy.long, trade_amount, comment="Long, TICK divergence") if trade_chase and L_entry3 and window and not(trade_pause) and not(trade_pause2) and barstate.isconfirmed and strategy.opentrades == 0 //limit to 1 entry, ignoring pyramiding strategy.entry("Long", strategy.long, trade_amount, comment="Long, Chase") if S_entry1 and window and not(trade_pause) and not(trade_pause2) and barstate.isconfirmed strategy.entry("Short", strategy.short, trade_amount, comment="Short") if trade_TICKdiverg and S_entry2 and window and not(trade_pause) and not(trade_pause2) and barstate.isconfirmed and strategy.opentrades == 0 //limit to 1 entry, ignoring pyramiding strategy.entry("Short", strategy.short, trade_amount, comment="Short, TICK divergence") if trade_chase and S_entry3 and window and not(trade_pause) and not(trade_pause2) and barstate.isconfirmed and strategy.opentrades == 0 //limit to 1 entry, ignoring pyramiding strategy.entry("Short", strategy.short, trade_amount, comment="Short, Chase")// ---------------------------------------------------------------- SL / PT -------------------------------------------------------------------long_SL = ta.lowest(low,5) - d_SL_atrshort_SL = ta.highest(high,5) + d_SL_atrif strategy.opentrades > 0 long_SL := math.min(long_SL[BSLE()], low[1] - d_SL_atr) short_SL := math.max(short_SL[BSLE()], high[1] + d_SL_atr)// plot(long_SL, "Long SL")// plot(short_SL,"Short SL")long_PT = close + d_PT_atrshort_PT = close - d_PT_atrif strategy.opentrades > 0 long_PT := strategy.opentrades.entry_price(0) + d_PT_atr short_PT := strategy.opentrades.entry_price(0) - d_PT_atr// ---------------------------------------------------------------- Exit Conditions ------------------------------------------------------------L_exit1 = tickHMA < tickHMA_MA and rsi_bearS_exit1 = tickHMA > tickHMA_MA and rsi_bullL_exit2 = bearCondS_exit2 = bullCondL_exit3 = tickH > 1000S_exit3 = tickL < -1000L_exit4 = strategy.opentrades.profit(strategy.opentrades-1) > 0 and tickHMA < tickHMA[1] and rsi2 < 50S_exit4 = strategy.opentrades.profit(strategy.opentrades-1) > 0 and tickHMA > tickHMA[1] and rsi2 > 50if BSLE() > min_hold and window2 if trade_PT strategy.exit("Exit", "Long", stop = long_SL, limit = long_PT, comment = "SL/PT hit") strategy.exit("Exit", "Short", stop = short_SL, limit = short_PT, comment = "SL/PT hit") else strategy.exit("Exit", "Long", stop = long_SL, comment = "SL hit") strategy.exit("Exit", "Short", stop = short_SL, comment = "SL hit") strategy.close("Long", when = L_exit1, comment = "Exit, TICK/RSI reversal") strategy.close("Short", when = S_exit1, comment = "Exit, TICK/RSI reversal") strategy.close("Long", when = L_exit2, comment = "Exit, Bearish Divergence") strategy.close("Short", when = S_exit2, comment = "Exit, Bullish Divergence") strategy.close("Long", when = L_exit3, comment = "Exit, TICK overbought") strategy.close("Short", when = S_exit3, comment = "Exit, TICK oversold") // strategy.close("Long", when = L_exit4, comment = "Exit, TICK/RSI reversal 2") // strategy.close("Short", when = S_exit4, comment = "Exit, TICK/RSI reversal 2") if hold_ON if time(timeframe.period, "1550-1551:246") strategy.close_all() if time(timeframe.period, "1550-1551:35") strategy.close("Long", qty_percent = 50, comment="Close 1/2 EOD") strategy.close("Short", qty_percent = 50, comment="Close 1/2 EOD")else if time(timeframe.period, "1550-1551:23456") strategy.close_all()