Pine Script v5 · Strategy
TICK strategy for SPY options
A Pine Script v5 strategy built on RMA (ta.tr, 14), EMA (tickC, 5) and WMA (_src, _length). It has 13 order rules, 4 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade is one contract and pays 0.0625 commission. 32 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 strategy for SPY options 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 strategy for SPY options 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 strategy for SPY options run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L73:C49: 'bgcolor' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download.
- Does TICK strategy for SPY options use a stop loss?
- Yes
- strategy.exit sets a stop on line 194, 195, 199, 200.
- Does TICK strategy for SPY options run in Zeal Terminal?
- Yes
- It compiles in 82 ms and runs 1,000 bars in 195 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 D data, not available: not a Binance spot market 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.
-
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 196, 197, 201, 202. 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 |
|---|---|---|---|
| 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 154 |
| # 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 155 |
| Reinvest percentage | 20 | float | trade_amount |
| Stop trading after Max daily profit | 1200 | float | pause_trade1 |
| Minimum bars to hold order | 6 | int | exit Exit exit Exit close Long close Short line 193 |
| Daily ATR | |||
| ATR period | 14 | int · min 1 | datr |
| % ATR to use for SL / PT | 5 | float · min 1 · max 100 · step 0.1 | percentage |
| VIX Volatility Index | |||
| VIX Threshold for entry | 20.0 | float · step 0.5 | L_entry0 S_entry0 |
| TICK Indicator | |||
| Fast EMA period | 5 | int | tickAVG |
| Slow EMA period | 21 | int | tickAVG_L |
| Hull MA period | 21 | int | tickHMA |
| Hull MA Smoothing | 5 | int | tickHMA_MA |
| TICK Divergence | |||
| Pivot Lookback Right | 0 | 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 | 2 | int | plFound phFound |
| Max of Lookback Range | 60 | int | line 96 |
| Min of Lookback Range | 5 | int | line 96 |
| Plot Bullish | true | bool | bullCond |
| Plot Hidden Bullish | true | bool | hiddenBullCond |
| Plot Bearish | true | bool | bearCond |
| Plot Hidden Bearish | false | bool | hiddenBearCond |
| RSI | |||
| RSI Length | 14 | int · min 1 | rsi_up rsi_down |
| RSI Signal Length | 1 | int · min 1 | rsi_ma |
| RSI Overbought/Oversold levels +/- from 50 | 20 | int | L_entry0 S_entry0 |
| Moving Averages | |||
| Fast EMA | 8 | int · min 1 | ema1 |
What it calculates
- RMAta.tr, ATR period (14)
datr · line 29 - EMAtickC, Fast EMA period (5)
tickAVG · line 44 - EMAtickC, Slow EMA period (21)
tickAVG_L · line 45 - WMA2 * ta.wma(_src, _length / 2) - ta.wma(_src, _length), math.round(math.sqrt(_length))
_return · line 47 - EMAtickHMA, Hull MA Smoothing (5)
tickHMA_MA · line 50 - PivotlowtickC, Pivot Lookback Left (2), Pivot Lookback Right (0)
plFound · line 92 - PivothightickC, Pivot Lookback Left (2), Pivot Lookback Right (0)
phFound · line 93 - RMA / Changemath.max(ta.change(src), 0), RSI Length (14)
rsi_up · line 137 - RMA / Change-math.min(ta.change(src), 0), RSI Length (14)
rsi_down · line 138 - SMArsi, RSI Signal Length (1)
rsi_ma · line 140 - EMAsrc, Fast EMA (8)
ema1 · line 147
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 116 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 barstate.isconfirmed | On | 185 |
| Open Short short | (S_entry1) and window and barstate.isconfirmed | On | 187 |
| Open Long2 long | L_entry2 and not(L_entry1) and window and barstate.isconfirmed | On | 190 |
| Open Short2 short | (S_entry2) and not(S_entry2) and window and barstate.isconfirmed | On | 192 |
| Exit Exit stop | BSLE() > min_hold and window2 and barstate.isconfirmed | On | 194 |
| Exit Exit stop | BSLE() > min_hold and window2 and barstate.isconfirmed | On | 195 |
| Close Long | L_exit1 or L_exit2 | On | 196 |
| Close Short | S_exit1 or S_exit2 | On | 197 |
| Exit Exit2 stop | window2 and barstate.isconfirmed | On | 199 |
| Exit Exit2 stop | window2 and barstate.isconfirmed | On | 200 |
| Close Long2 | L_exit1 or L_exit2 | On | 201 |
| Close Short2 | S_exit1 or S_exit2 | On | 202 |
| Close | time(timeframe.period, "1550-1600:23456") | On | 204 |
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 data3 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 D, and that data is not available here (not a Binance spot market; not a Binance spot market). 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 strategy for SPY options this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Ta Strategy by AHMEDABDELAZIZZIZO | pivothigh pivotlow ema rma sma | v5 strategy | +0.3% | 8 | 0.3% |
| TICK Scalping strategy, SPY 1 min by PtGambler | rma ema wma sma pivotlow pivothigh | v5 strategy | No trades on this market | ||
| Villa Dinamic Pivot Supertrend Strategy by VILIO_Trading | pivothigh pivotlow ema sma | v5 strategy | No trades on this market | ||
| Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10k | sma ema rma | v4 strategy | −19.4% | 36 | 70.0% |
| SPX Scalping Strategy by connor2279 | sma ema wma rma | v5 strategy | +1.5% | 109 | 5.0% |
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.
- 4 strategy calls use the when = argument (line 196, 197, 201, 202). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 10 settings use the untyped input() (line 6, 9, 78, 79, 80, 81, 82, 83, 84, 85). 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 6: input() → input.int()
- Line 9: input() → input.int()
- Line 78: input() → input.int()
- Line 79: input() → input.int()
- Line 80: input() → input.int()
- Line 81: input() → input.int()
8 more edits
- Line 82: input() → input.bool()
- Line 83: input() → input.bool()
- Line 84: input() → input.bool()
- Line 85: input() → input.bool()
- Line 196: when = L_exit1 or L_exit2 → if block
- Line 197: when = S_exit1 or S_exit2 → if block
- Line 201: when = L_exit1 or L_exit2 → if block
- Line 202: when = S_exit1 or S_exit2 → 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.red : na, transp=30)-lbR = input(title='Pivot Lookback Right', defval=0, group = "TICK Divergence")+lbR = input.int(title='Pivot Lookback Right', defval=0, group = "TICK Divergence")-lbL = input(title='Pivot Lookback Left', defval=2, group = "TICK Divergence")+lbL = input.int(title='Pivot Lookback Left', defval=2, group = "TICK Divergence")-rangeUpper = input(title='Max of Lookback Range', defval=60, group = "TICK Divergence")+rangeUpper = input.int(title='Max of Lookback Range', defval=60, group = "TICK Divergence")-rangeLower = input(title='Min of Lookback Range', defval=5, group = "TICK Divergence")+rangeLower = input.int(title='Min of Lookback Range', defval=5, 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=true, group = "TICK Divergence")+plotHiddenBull = input.bool(title='Plot Hidden Bullish', defval=true, 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 = "Stopped out")- strategy.close("Long", when = L_exit1 or L_exit2)+ if L_exit1 or L_exit2+ strategy.close("Long")- strategy.close("Short", when = S_exit1 or S_exit2)+ if S_exit1 or S_exit2+ strategy.close("Short")if window2 and barstate.isconfirmed⋯ strategy.exit("Exit2", "Short2", stop = short_SL, comment = "Stopped out")- strategy.close("Long2", when = L_exit1 or L_exit2)+ if L_exit1 or L_exit2+ strategy.close("Long2")- strategy.close("Short2", when = S_exit1 or S_exit2)+ if S_exit1 or S_exit2+ strategy.close("Short2")if time(timeframe.period, "1550-1600:23456")⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L73:C49: 'bgcolor' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © platsn-//@version=5+//@version=6strategy("TICK strategy for SPY", 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 82 ms | With a workaround 1,000 bars in 195 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//@version=5strategy("TICK strategy for SPY", overlay=false, pyramiding=3, initial_capital=5000, commission_type=strategy.commission.cash_per_contract, commission_value = 0.0625) // ******************** 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, "0945-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")daily_max = input.float(1200, title="Stop trading after Max daily profit", group="Trading Options")// ***************************************************************************************************** Daily ATR *****************************************************atrlen = input.int(14, minval=1, title="ATR period", group = "Daily ATR")iPercent = input.float(5, minval=1, maxval=100, step=0.1, title="% ATR to use for SL / PT", group = "Daily ATR") percentage = iPercent * 0.01datr = request.security(syminfo.tickerid, "1D", ta.rma(ta.tr, atrlen))datrp = datr * percentage// plot(datr,"Daily ATR")// plot(datrp, "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(5, title = "Fast EMA period", group = "TICK Indicator")malen2 = input.int(21, title = "Slow EMA period", group = "TICK Indicator")malen3 = input.int(21, title = "Hull MA period", group = "TICK Indicator")malen4 = input.int(5, title = "Hull MA Smoothing", group = "TICK Indicator")//get TICK data// tickO = request.security("USI:TICK", timeframe.period, open)tickC = request.security("USI:TICK", timeframe.period, close)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.ema(tickHMA, malen4)tick_bull = tickAVG > tickAVG[1]tick_bear = tickAVG < tickAVG[1]//Plot Tick dataplot(tickC, 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.small)plotshape(ta.crossover(tickHMA,tickHMA_MA) ,"Cross up", color=color.green, style=shape.triangleup, location = location.bottom, size =size.small)tick_revUp = tickHMA[2] >= tickHMA[1] and tickHMA > tickHMA[1]tick_revDown = tickHMA[2] <= tickHMA[1] and tickHMA < tickHMA[1]plotshape(tick_revDown,"Cross down", color=color.orange, style=shape.triangledown, location = location.top, size =size.tiny)plotshape(tick_revUp ,"Cross up", color=color.blue, style=shape.triangleup, location = location.bottom, size =size.tiny)//Backgroundbgcolor(tickAVG_L > 0 ? color.green : color.red, transp=90)bgcolor(tickC > 499 ? color.green : na, transp=70)bgcolor(tickC < -499 ? color.red : na, transp=70)bgcolor(tickC > 999 ? color.green : na, transp=30)bgcolor(tickC < -999 ? color.red : na, transp=30)lbR = input(title='Pivot Lookback Right', defval=0, group = "TICK Divergence")lbL = input(title='Pivot Lookback Left', defval=2, group = "TICK Divergence")rangeUpper = input(title='Max of Lookback Range', defval=60, group = "TICK Divergence")rangeLower = input(title='Min of Lookback Range', defval=5, group = "TICK Divergence")plotBull = input(title='Plot Bullish', defval=true, group = "TICK Divergence")plotHiddenBull = input(title='Plot Hidden Bullish', defval=true, 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, transp=0)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, transp=0)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, transp=0)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, transp=0)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 = closersi_len = input.int(14, minval=1, title="RSI Length", group = "RSI")rsi_ma_len = input.int(1, 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.sma(rsi,rsi_ma_len)rsi_avg = math.avg(rsi,rsi_ma)rsi_bull = rsi_avg > rsi_avg[1]rsi_bear = rsi_avg < rsi_avg[1]rsi_thres = input.int(20,"RSI Overbought/Oversold levels +/- from 50", group = "RSI")//-------------------------------------------------------- Moving Average ------------------------------------emalen1 = input.int(8, minval=1, title='Fast EMA', group= "Moving Averages")ema1 = ta.ema(src, emalen1)//-------------------------------------------------------------------------------------profit = strategy.netprofittrade_amount = math.floor(strategy.initial_capital / close) BSLE()=> strategy.opentrades > 0 ? (bar_index - strategy.opentrades.entry_bar_index(strategy.opentrades-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// --------------------daily_profit = 0.0for i = 0 to strategy.closedtrades-1 if strategy.closedtrades.exit_time(i) > time_tradingday daily_profit += strategy.closedtrades.profit(i)// plot(daily_profit, "Daily P/L")pause_trade1 = daily_profit > daily_maxtrade_amount := pause_trade1 ? 1 : trade_amountL_entry0 = ta.crossover(tickHMA, tickHMA_MA) and rsi_avg > 50 and rsi < 50 + rsi_thres and VIX > vix_thres and tickAVG > 0 //and close > ema1S_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_entry0 and close > ema1 S_entry1 = S_entry0 and close < ema1L_entry2 = strategy.opentrades == 0 and ta.barssince(L_entry0) < 2 and close > ema1S_entry2 = strategy.opentrades == 0 and ta.barssince(S_entry0) < 2 and close < ema1long_SL = low[1] - datrpshort_SL = high[1] + datrpif strategy.opentrades > 0 long_SL := math.min(long_SL[BSLE()], low[1] - datrp) short_SL := math.max(short_SL[BSLE()], high[1] + datrp)L_exit1 = tickHMA < tickHMA_MA and rsi_bearS_exit1 = tickHMA > tickHMA_MA and rsi_bullL_exit2 = bearCondS_exit2 = bullCondtrade_amount_long = trade_amounttrade_amount_short = trade_amountif (L_entry1) and window and barstate.isconfirmed //and not(pause_trade1) strategy.entry("Long", strategy.long, trade_amount_long)if (S_entry1) and window and barstate.isconfirmed //and not(pause_trade1) strategy.entry("Short", strategy.short, trade_amount_short) if L_entry2 and not(L_entry1) and window and barstate.isconfirmed //and not(pause_trade1) strategy.entry("Long2", strategy.long, trade_amount_long, comment="Long 2")if (S_entry2) and not(S_entry2) and window and barstate.isconfirmed //and not(pause_trade1) strategy.entry("Short2", strategy.short, trade_amount_short, comment="Short 2" )if BSLE() > min_hold and window2 and barstate.isconfirmed strategy.exit("Exit", "Long", stop = long_SL, comment = "Stopped out") strategy.exit("Exit", "Short", stop = short_SL, comment = "Stopped out") strategy.close("Long", when = L_exit1 or L_exit2) strategy.close("Short", when = S_exit1 or S_exit2)if window2 and barstate.isconfirmed strategy.exit("Exit2", "Long2", stop = long_SL, comment = "Stopped out") strategy.exit("Exit2", "Short2", stop = short_SL, comment = "Stopped out") strategy.close("Long2", when = L_exit1 or L_exit2) strategy.close("Short2", when = S_exit1 or S_exit2)if time(timeframe.period, "1550-1600:23456") strategy.close_all()