Pine Script v4 · Strategy
Bull Call Spread Entry Strategy
A Pine Script v4 strategy built on SMA (close, 20), RSI (close, 14) and DMI (14, 14). It has 3 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 26 settings; defaults include Market Ticker to Use QQQ, Market Too Hot Level 1 and Market Too Cool Level -2.5.
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 Bull Call Spread Entry 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 Bull Call Spread Entry 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 Bull Call Spread Entry 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 Bull Call Spread Entry Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Bull Call Spread Entry Strategy run in Zeal Terminal?
- Yes
- It compiles in 1,866 ms and runs 1,000 bars in 186 ms, in the browser.
BTCUSDT · 1D · default settings
- Entry Strength
- Bull Strength
- Bear Strength
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs QQQ 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, $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
4 settings do nothing
“Bollinger Bands Period”, “Bollinger Bands Multiplier”, “Keltner Channel Period”, “Keltner Channel Multiplier” are declared but never read.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 175, 183, 185. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 139
transp = on line 139, 141, 143. v5 folds the transparency into the colour with color.new(c, transp).
Upgrade and export
Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames security → request.security, sma → ta.sma, rsi → ta.rsi, dmi → ta.dmi, bb → ta.bb, kc → ta.kc, lowest → ta.lowest, highest → ta.highest, abs → math.abs, barssince → ta.barssince, tostring → str.tostring.
- 3 strategy calls use the when = argument (line 175, 183, 185). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 3: //@version=4 → //@version=5
- Line 6: input(type = input.bool) → input.bool()
- Line 11: input(type = input.bool) → input.bool()
- Line 12: input(type = input.symbol) → input.symbol()
- Line 13: security → request.security
- Line 13: security → request.security
74 more edits
- Line 13: security → request.security
- Line 14: input(type = input.float) → input.float()
- Line 15: input(type = input.float) → input.float()
- Line 19: input(type = input.integer) → input.int()
- Line 21: input(type = input.bool) → input.bool()
- Line 23: input(type = input.bool) → input.bool()
- Line 24: input(type = input.bool) → input.bool()
- Line 25: input(type = input.bool) → input.bool()
- Line 26: input(type = input.integer) → input.int()
- Line 27: input(type = input.integer) → input.int()
- Line 28: input(type = input.integer) → input.int()
- Line 29: input(type = input.integer) → input.int()
- Line 30: input(type = input.integer) → input.int()
- Line 31: input(type = input.integer) → input.int()
- Line 32: input(type = input.float) → input.float()
- Line 33: input(type = input.integer) → input.int()
- Line 34: input(type = input.integer) → input.int()
- Line 35: input(type = input.integer) → input.int()
- Line 36: sma → ta.sma
- Line 37: sma → ta.sma
- Line 38: sma → ta.sma
- Line 39: rsi → ta.rsi
- Line 40: dmi → ta.dmi
- Line 41: bb → ta.bb
- Line 42: kc → ta.kc
- Line 59: lowest → ta.lowest
- Line 76: highest → ta.highest
- Line 132: abs → math.abs
- Line 139: transp = 100 → color.new(bullOrBearColor, 100)
- Line 141: transp = 100 → color.new(bullColor, 100)
- Line 143: transp = 100 → color.new(bearColor, 100)
- Line 153: input(type = input.integer) → input.int()
- Line 155: input(type = input.integer) → input.int()
- Line 157: input(type = input.integer) → input.int()
- Line 159: input(type = input.integer) → input.int()
- Line 161: input(type = input.integer) → input.int()
- Line 163: input(type = input.integer) → input.int()
- Line 181: barssince → ta.barssince
- Line 182: barssince → ta.barssince
- Line 188: tostring → str.tostring
- Line 188: abs → math.abs
- Line 189: tostring → str.tostring
- Line 190: tostring → str.tostring
- Line 191: tostring → str.tostring
- Line 192: tostring → str.tostring
- Line 196: tostring → str.tostring
- Line 197: tostring → str.tostring
- Line 197: abs → math.abs
- Line 198: tostring → str.tostring
- Line 198: tostring → str.tostring
- Line 199: tostring → str.tostring
- Line 199: tostring → str.tostring
- Line 200: tostring → str.tostring
- Line 200: tostring → str.tostring
- Line 201: tostring → str.tostring
- Line 201: tostring → str.tostring
- Line 202: tostring → str.tostring
- Line 202: tostring → str.tostring
- Line 203: tostring → str.tostring
- Line 203: tostring → str.tostring
- Line 204: tostring → str.tostring
- Line 204: tostring → str.tostring
- Line 205: tostring → str.tostring
- Line 205: tostring → str.tostring
- Line 209: tostring → str.tostring
- Line 209: tostring → str.tostring
- Line 211: tostring → str.tostring
- Line 211: tostring → str.tostring
- Line 213: tostring → str.tostring
- Line 216: tostring → str.tostring
- Line 217: tostring → str.tostring
- Line 218: tostring → str.tostring
- Line 219: tostring → str.tostring
- Line 220: tostring → str.tostring
⋯// © DeuceDavis-//@version=4+//@version=5strategy("Spread Entry Strategy", shorttitle="SE Strategy", max_bars_back=1, overlay=true)//Remove or Add Narrative Label-narrationYes = input(title="Provide Narrative (Troubleshooting)", type=input.bool, defval=false)+narrationYes = input.bool(title="Provide Narrative (Troubleshooting)", defval=false)//Overall Market Condition⋯//Defaults are 1% for being to hot and 2.5% for being too cold-mktFilter = input(title="Use Market Filter", type=input.bool, defval=true)+mktFilter = input.bool(title="Use Market Filter", defval=true)-mkt = input(title="Market Ticker to Use", type=input.symbol, defval="QQQ")+mkt = input.symbol(title="Market Ticker to Use", defval="QQQ")-mktChange = (security(mkt, "D", close) - security(mkt, "D", close[1])) / security(mkt, "D", close[1]) * 100+mktChange = (request.security(mkt, "D", close) - request.security(mkt, "D", close[1])) / request.security(mkt, "D", close[1]) * 100-mktChangeTooHighLevel = input(title="Market Too Hot Level", type=input.float, defval = 1)+mktChangeTooHighLevel = input.float(title="Market Too Hot Level", defval = 1)-mktChangeTooCoolLevel = input(title="Market Too Cool Level", type=input.float, defval = -2.5)+mktChangeTooCoolLevel = input.float(title="Market Too Cool Level", defval = -2.5)mktIsHot = not mktFilter ? false: mktChange >= mktChangeTooHighLevel ? true:false⋯//Sets the level for when an overlay will show using the absolute power on the side of the trade setting up-strengthFilter = input(title="Overlay Signal Strength Level", type=input.integer, defval=6)+strengthFilter = input.int(title="Overlay Signal Strength Level", defval=6)//Filters out Bull and Bear overlays when engaged-useSqueezeFilter = input(title="Remove Strength Indicator When Squeezed", type=input.bool, defval=false)+useSqueezeFilter = input.bool(title="Remove Strength Indicator When Squeezed", defval=false)//Shades the background when the stock is undergoing a squeeze-showSqueezes = input(title="Show Squeezes (Will Override Indicator When Concurrent)", type=input.bool, defval=false) +showSqueezes = input.bool(title="Show Squeezes (Will Override Indicator When Concurrent)", defval=false) -showBear = input(title="Show Bear Side", type=input.bool, defval=true)+showBear = input.bool(title="Show Bear Side", defval=true)-showBull = input(title="Show Bull Side", type=input.bool, defval=true)+showBull = input.bool(title="Show Bull Side", defval=true)-rsiPeriod = input(title="RSI Period", type=input.integer, defval=14)+rsiPeriod = input.int(title="RSI Period", defval=14)-dmiPeriod = input(title="DMI Period", type=input.integer, defval=14)+dmiPeriod = input.int(title="DMI Period", defval=14)-dmiSmoothing = input(title="DMI Smoothing", type=input.integer, defval=14)+dmiSmoothing = input.int(title="DMI Smoothing", defval=14)-bbPeriod = input(title="Bollinger Bands Period", type=input.integer, defval=20)+bbPeriod = input.int(title="Bollinger Bands Period", defval=20)-bbMultiplier = input(title="Bollinger Bands Multiplier", type=input.integer, defval=2)+bbMultiplier = input.int(title="Bollinger Bands Multiplier", defval=2)-kcPeriod = input(title="Keltner Channel Period", type=input.integer, defval=20)+kcPeriod = input.int(title="Keltner Channel Period", defval=20)-kcMultiplier = input(title="Keltner Channel Multiplier", type=input.float, defval=1.5)+kcMultiplier = input.float(title="Keltner Channel Multiplier", defval=1.5)-shortSMAPeriod = input(title="Short SMA Period", type=input.integer, defval=20)+shortSMAPeriod = input.int(title="Short SMA Period", defval=20)-mediumSMAPeriod = input(title="Medium SMA Period", type=input.integer, defval=50)+mediumSMAPeriod = input.int(title="Medium SMA Period", defval=50)-longSMAPeriod = input(title="Long SMA Period", type=input.integer, defval=200)+longSMAPeriod = input.int(title="Long SMA Period", defval=200)-smaShort = sma(close, shortSMAPeriod)+smaShort = ta.sma(close, shortSMAPeriod)-smaMedium = sma(close, mediumSMAPeriod)+smaMedium = ta.sma(close, mediumSMAPeriod)-smaLong = sma(close, longSMAPeriod)+smaLong = ta.sma(close, longSMAPeriod)-rsiPlot = rsi(close, rsiPeriod)+rsiPlot = ta.rsi(close, rsiPeriod)-[diPlus, diMinus, adx] = dmi(dmiPeriod, dmiSmoothing)+[diPlus, diMinus, adx] = ta.dmi(dmiPeriod, dmiSmoothing)-[middleBB, upperBB, lowerBB] = bb(close, 20, 2)+[middleBB, upperBB, lowerBB] = ta.bb(close, 20, 2)-[middleKC, upperKC, lowerKC] = kc(close, 20, 1.5, useTrueRange=true)+[middleKC, upperKC, lowerKC] = ta.kc(close, 20, 1.5, useTrueRange=true)//Bull or Bear side is determined whether the price is above or below the Bollinger Band Basis (BB Middle)⋯//Conditions for Bull Strength-lowerBB_Bounce = lowest(5) <= lowerBB ? 1 : 0+lowerBB_Bounce = ta.lowest(5) <= lowerBB ? 1 : 0adxUpTrend = adx > adx[1] ? 1 : 0⋯//Conditions for Bear Strength-upperBB_Bounce = highest(5) >= upperBB ? 1 : 0+upperBB_Bounce = ta.highest(5) >= upperBB ? 1 : 0adxDownTrend = adx < adx[1] ? 1 : 0⋯ signalYesNo == "No" ? 10 :- abs(tradeCondition) < strengthFilter ? 10 :+ math.abs(tradeCondition) < strengthFilter ? 10 : (bullOrBear == "Bear") and (not showBear) ? 10 :⋯plotshape(tradeCondition, title="Entry Strength", offset=0, style=shape.flag, - location=location.top, color=bullOrBearColor, transp=100)+ location=location.top, color=color.new(bullOrBearColor, 100))plotshape(bullCondition, title="Bull Strength", offset=0, style=shape.flag, - location=location.top, color=bullColor, transp=100)+ location=location.top, color=color.new(bullColor, 100))plotshape(bearCondition, title="Bear Strength", offset=0, style=shape.flag, - location=location.top, color=bearColor, transp=100)+ location=location.top, color=color.new(bearColor, 100))curHour = hour(time) - 5⋯// 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)-startMonth = input(title="Start Month", type=input.integer,+startMonth = input.int(title="Start Month", defval=1, minval=1, maxval=12)-startYear = input(title="Start Year", type=input.integer,+startYear = input.int(title="Start Year", defval=2018, minval=1800, maxval=2100)-endDate = input(title="End Date", type=input.integer,+endDate = input.int(title="End Date", defval=1, minval=1, maxval=31)-endMonth = input(title="End Month", type=input.integer,+endMonth = input.int(title="End Month", defval=12, minval=1, maxval=12)-endYear = input(title="End Year", type=input.integer,+endYear = input.int(title="End Year", defval=2021, minval=1800, maxval=2100)⋯entryBar = strategy.position_size[0] > strategy.position_size[1]-barsPassedBy = barssince(entryBar)+barsPassedBy = ta.barssince(entryBar)-triggerBars = barssince(triggerBar)+triggerBars = ta.barssince(triggerBar)strategy.cancel("BCS", when = (triggerBars>0))⋯narSqueezed = currentlySqueezed ? "A Squeezed" + "\n" : na-narrativeText = narSqueezed + bullOrBear + " Setup Strength " + tostring(abs(tradeCondition)) + "\n\n"+narrativeText = narSqueezed + bullOrBear + " Setup Strength " + str.tostring(math.abs(tradeCondition)) + "\n\n"- + "RSI " + rsiUpDown + " to " + tostring(rsiPlot, "#.##") + "\n\n"+ + "RSI " + rsiUpDown + " to " + str.tostring(rsiPlot, "#.##") + "\n\n"- + "ADX " + adxUpDown + " to " + tostring(adx, "#.##") + "\n\n"+ + "ADX " + adxUpDown + " to " + str.tostring(adx, "#.##") + "\n\n"- + "+DI " + diPlusUpDown + " to " + tostring(diPlus, "#.##") + "\n"+ + "+DI " + diPlusUpDown + " to " + str.tostring(diPlus, "#.##") + "\n"- + "-DI " + diMinusUpDown + " to " + tostring(diMinus, "#.##") + "\n"+ + "-DI " + diMinusUpDown + " to " + str.tostring(diMinus, "#.##") + "\n" + "\n-------------------\n"⋯ + "\n-------------------\n"- + "Bulls " + tostring(bullCondition) + " | "+ + "Bulls " + str.tostring(bullCondition) + " | "- + "Bears " + tostring(abs(bearCondition)) + "\n\n"+ + "Bears " + str.tostring(math.abs(bearCondition)) + "\n\n"- + tostring(bullRSIStat) + " RSI " + tostring(bearRSIStat) + "\n" + + str.tostring(bullRSIStat) + " RSI " + str.tostring(bearRSIStat) + "\n" - + tostring(diMinusStat) + " DI " + tostring(diPlusStat) + "\n"+ + str.tostring(diMinusStat) + " DI " + str.tostring(diPlusStat) + "\n"- + tostring(lowerBBStat) + " BB " + tostring(upperBBStat) + "\n"+ + str.tostring(lowerBBStat) + " BB " + str.tostring(upperBBStat) + "\n"- + tostring(lowerKCStat) + " KC " + tostring(upperKCStat) + "\n" + + str.tostring(lowerKCStat) + " KC " + str.tostring(upperKCStat) + "\n" - + tostring(bbOutsideKC) + " SQ " + tostring(bbOutsideKC) + "\n"+ + str.tostring(bbOutsideKC) + " SQ " + str.tostring(bbOutsideKC) + "\n"- + tostring(lowerBB_Bounce) + " BB Bounce " + tostring(upperBB_Bounce) + "\n" + + str.tostring(lowerBB_Bounce) + " BB Bounce " + str.tostring(upperBB_Bounce) + "\n" - + tostring(adxUpTrend) + " ADX " + tostring(adxDownTrend) + "\n" + + str.tostring(adxUpTrend) + " ADX " + str.tostring(adxDownTrend) + "\n" - + tostring(rsiUnder30) + " RSI 30/70 " + tostring(rsiOver70) + "\n"+ + str.tostring(rsiUnder30) + " RSI 30/70 " + str.tostring(rsiOver70) + "\n" +"\n-------------------\n"⋯ + "\n-------------------\n"- + tostring(shortSMAPeriod, "##") + " SMA is " + rippleWaveUpDn + " " + tostring(mediumSMAPeriod, "##") + " SMA\n"+ + str.tostring(shortSMAPeriod, "##") + " SMA is " + rippleWaveUpDn + " " + str.tostring(mediumSMAPeriod, "##") + " SMA\n" + "and is " + rippleDoD + " compared to prior bar\n\n"- + tostring(mediumSMAPeriod, "##") + " SMA is " + waveTideUpDn + " " + tostring(longSMAPeriod, "##") + " SMA\n"+ + str.tostring(mediumSMAPeriod, "##") + " SMA is " + waveTideUpDn + " " + str.tostring(longSMAPeriod, "##") + " SMA\n" + "and is " + waveDoD + " compared to prior bar\n\n"- + tostring(longSMAPeriod, "##") + " SMA is " + tideDoD + " compared to prior bar\n"+ + str.tostring(longSMAPeriod, "##") + " SMA is " + tideDoD + " compared to prior bar\n" + "entry Conditions\n" + "BullOrBear " + (bullOrBear) + "\n"- + "BullCondition " + tostring(bullCondition,"##") + "\n"+ + "BullCondition " + str.tostring(bullCondition,"##") + "\n"- + "Entry Limit " + tostring(entryLimit,"##.##") + "\n" + + "Entry Limit " + str.tostring(entryLimit,"##.##") + "\n" - + "BullCondition " + tostring(bullCondition,"##") + "\n" + + "BullCondition " + str.tostring(bullCondition,"##") + "\n" - + "Bars Passed " + tostring(barsPassedBy,"##") + "\n" + + "Bars Passed " + str.tostring(barsPassedBy,"##") + "\n" - + "Tigger Bar " + tostring(triggerBars,"##") + "\n" + + "Tigger Bar " + str.tostring(triggerBars,"##") + "\n" ⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 175: when = strategy.position_size <= 0 → if block
- Line 183: when = (triggerBars>0) → if block
- Line 185: when = exitStrategy → if block
⋯if triggerBar and inDateRange- strategy.entry("BCS", strategy.long, 100, limit=entryLimit, when=strategy.position_size <= 0)+ if strategy.position_size <= 0+ strategy.entry("BCS", strategy.long, 100, limit=entryLimit) ⋯triggerBars = ta.barssince(triggerBar)-strategy.cancel("BCS", when = (triggerBars>0))+if (triggerBars>0)+ strategy.cancel("BCS")exitStrategy = (barsPassedBy >= 30) and exitWeekDay-strategy.close("BCS", when=exitStrategy)+if exitStrategy+ strategy.close("BCS")//Narrative Build⋯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.
⋯// © DeuceDavis-//@version=5+//@version=6strategy("Spread Entry Strategy", shorttitle="SE Strategy", max_bars_back=1, overlay=true)⋯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 |
|---|---|---|---|
| Provide Narrative (Troubleshooting) | false | bool | narrativeLabel |
| Use Market Filter | true | bool | mktIsHot mktIsCold |
| Market Ticker to Use | QQQ | symbol | mktChange |
| Market Too Hot Level | 1 | float | mktIsHot |
| Market Too Cool Level | -2.5 | float | mktIsCold |
| Overlay Signal Strength Level | 6 | int (written input.integer) | fillNumber triggerBar |
| Remove Strength Indicator When Squeezed | false | bool | tradeCondition |
| Show Squeezes (Will Override Indicator When Concurrent) | false | bool | fillNumber |
| Show Bear Side | true | bool | fillNumber |
| Show Bull Side | true | bool | fillNumber |
| RSI Period | 14 | int (written input.integer) | rsiPlot |
| DMI Period | 14 | int (written input.integer) | diPlus diMinus adx |
| DMI Smoothing | 14 | int (written input.integer) | diPlus diMinus adx |
| Bollinger Bands Period | 20 | int (written input.integer) | unused |
| Bollinger Bands Multiplier | 2 | int (written input.integer) | unused |
| Keltner Channel Period | 20 | int (written input.integer) | unused |
| Keltner Channel Multiplier | 1.5 | float | unused |
| Short SMA Period | 20 | int (written input.integer) | smaShort narrativeText |
| Medium SMA Period | 50 | int (written input.integer) | smaMedium narrativeText |
| Long SMA Period | 200 | int (written input.integer) | smaLong narrativeText |
| Start Date | 1 | int (written input.integer) · min 1 · max 31 | inDateRange |
| Start Month | 1 | int (written input.integer) · min 1 · max 12 | inDateRange |
| Start Year | 2018 | int (written input.integer) · min 1800 · max 2100 | inDateRange |
| End Date | 1 | int (written input.integer) · min 1 · max 31 | inDateRange |
| End Month | 12 | int (written input.integer) · min 1 · max 12 | inDateRange |
| End Year | 2021 | int (written input.integer) · min 1800 · max 2100 | inDateRange |
What it calculates
- SMA (
sma,ta.smain v5)close, Short SMA Period (20)smaShort · line 36 - SMA (
sma,ta.smain v5)close, Medium SMA Period (50)smaMedium · line 37 - SMA (
sma,ta.smain v5)close, Long SMA Period (200)smaLong · line 38 - RSI (
rsi,ta.rsiin v5)close, RSI Period (14)rsiPlot · line 39 - DMI (
dmi,ta.dmiin v5)DMI Period (14), DMI Smoothing (14)diPlus · line 40 - DMI (
dmi,ta.dmiin v5)DMI Period (14), DMI Smoothing (14)diMinus · line 40 - DMI (
dmi,ta.dmiin v5)DMI Period (14), DMI Smoothing (14)adx · line 40 - BB (
bb,ta.bbin v5)close, 20, 2middleBB · line 41 - BB (
bb,ta.bbin v5)close, 20, 2upperBB · line 41 - BB (
bb,ta.bbin v5)close, 20, 2lowerBB · line 41 - KC (
kc,ta.kcin v5)close, 20, 1.5, useTrueRange = truemiddleKC · line 42 - KC (
kc,ta.kcin v5)close, 20, 1.5, useTrueRange = trueupperKC · line 42 - KC (
kc,ta.kcin v5)close, 20, 1.5, useTrueRange = truelowerKC · line 42 - Lowest (
lowest,ta.lowestin v5)5lowerBB_Bounce · line 59 - Highest (
highest,ta.highestin v5)5upperBB_Bounce · line 76 - Barssince (
barssince,ta.barssincein v5)entryBarbarsPassedBy · line 181 - Barssince (
barssince,ta.barssincein v5)triggerBartriggerBars · line 182
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 80 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 BCS long | strategy.position_size <= 0 | On | 175 |
| cancel BCS | (triggerBars>0) | On | 183 |
| Close BCS | exitStrategy(barsPassedBy >= 30) and exitWeekDay | On | 185 |
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 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 QQQ D, and that data is not available here (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 |
|---|---|---|---|---|---|
| Bull Call Spread Entry Strategy this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| Bollinger -B Candles Strategy by Trendoscope | sma bb lowest highest | v4 strategy | +17.3% | 29 | 5.1% |
| RSI Divergence Strategy by faytterro | rsi lowest barssince highest | v5 strategy | +102.9% | 41 | 2.0% |
| CCI-RSI MR by monikabhay | highest lowest sma rsi bb | v4 strategy | No trades on this market | ||
| Stochastic RSI by Zeal Terminal | rsi highest lowest sma | v5 indicator | indicator | ||
| Solution Zigma - Fibonacci Impulse by ZoomerXeus | highest lowest dmi rsi sma | v5 strategy | does not run in Zeal Terminal | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 1,866 ms | Yes 1,000 bars in 186 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © DeuceDavis//@version=4strategy("Spread Entry Strategy", shorttitle="SE Strategy", max_bars_back=1, overlay=true)//Remove or Add Narrative LabelnarrationYes = input(title="Provide Narrative (Troubleshooting)", type=input.bool, defval=false)//Overall Market Condition//This used to filter out noise caused by overall dramatic market moves//Any comparison ticker can be used, the default is the QQQ ticker//Defaults are 1% for being to hot and 2.5% for being too coldmktFilter = input(title="Use Market Filter", type=input.bool, defval=true)mkt = input(title="Market Ticker to Use", type=input.symbol, defval="QQQ")mktChange = (security(mkt, "D", close) - security(mkt, "D", close[1])) / security(mkt, "D", close[1]) * 100mktChangeTooHighLevel = input(title="Market Too Hot Level", type=input.float, defval = 1)mktChangeTooCoolLevel = input(title="Market Too Cool Level", type=input.float, defval = -2.5)mktIsHot = not mktFilter ? false: mktChange >= mktChangeTooHighLevel ? true:falsemktIsCold = not mktFilter ? false: mktChange <= mktChangeTooCoolLevel ? true:false//Sets the level for when an overlay will show using the absolute power on the side of the trade setting upstrengthFilter = input(title="Overlay Signal Strength Level", type=input.integer, defval=6)//Filters out Bull and Bear overlays when engageduseSqueezeFilter = input(title="Remove Strength Indicator When Squeezed", type=input.bool, defval=false)//Shades the background when the stock is undergoing a squeezeshowSqueezes = input(title="Show Squeezes (Will Override Indicator When Concurrent)", type=input.bool, defval=false) showBear = input(title="Show Bear Side", type=input.bool, defval=true)showBull = input(title="Show Bull Side", type=input.bool, defval=true)rsiPeriod = input(title="RSI Period", type=input.integer, defval=14)dmiPeriod = input(title="DMI Period", type=input.integer, defval=14)dmiSmoothing = input(title="DMI Smoothing", type=input.integer, defval=14)bbPeriod = input(title="Bollinger Bands Period", type=input.integer, defval=20)bbMultiplier = input(title="Bollinger Bands Multiplier", type=input.integer, defval=2)kcPeriod = input(title="Keltner Channel Period", type=input.integer, defval=20)kcMultiplier = input(title="Keltner Channel Multiplier", type=input.float, defval=1.5)shortSMAPeriod = input(title="Short SMA Period", type=input.integer, defval=20)mediumSMAPeriod = input(title="Medium SMA Period", type=input.integer, defval=50)longSMAPeriod = input(title="Long SMA Period", type=input.integer, defval=200)smaShort = sma(close, shortSMAPeriod)smaMedium = sma(close, mediumSMAPeriod)smaLong = sma(close, longSMAPeriod)rsiPlot = rsi(close, rsiPeriod)[diPlus, diMinus, adx] = dmi(dmiPeriod, dmiSmoothing)[middleBB, upperBB, lowerBB] = bb(close, 20, 2)[middleKC, upperKC, lowerKC] = kc(close, 20, 1.5, useTrueRange=true)//Bull or Bear side is determined whether the price is above or below the Bollinger Band Basis (BB Middle)bullOrBear = close < middleBB ? "Bull" : "Bear"//Squeeze ConditionbbOutsideKC = (((lowerBB < lowerKC) and (upperBB > upperKC))) ? 1 : 0currentlySqueezed = bbOutsideKC == 0 ? true : falsesqueezedOut = bbOutsideKC > bbOutsideKC[1] ? 1 : 0//Penalty for -DI and +DI going in same direction (Currently not used)diDirDivergency = (diPlus > diPlus[1]) and (diMinus < diMinus[1]) ? "UpDn" : (diPlus < diPlus[1]) and (diMinus > diMinus[1]) ? "DnUp" : (diPlus > diPlus[1]) and (diMinus > diMinus[1]) ? "UpUp" : "DnDn"diPenalty = (diDirDivergency == "UpUp") or (diDirDivergency == "DnDn") ? 2 : 0adxUpDown = adx > adx[1] ? "Up" : "Down"diMinusUpDown = diMinus > diMinus[1] ? "Up" : "Down"diPlusUpDown = diPlus > diPlus[1] ? "Up" : "Down"rsiUpDown = rsiPlot > rsiPlot[1] ? "Up" : "Down"//Conditions for Bull StrengthlowerBB_Bounce = lowest(5) <= lowerBB ? 1 : 0adxUpTrend = adx > adx[1] ? 1 : 0bullRSIStat = rsiPlot[0] > rsiPlot[1] ? 1 : 0diMinusStat = diMinus[0] < diMinus[1] ? 1 : 0lowerBBStat = close < middleBB and close > lowerBB ? 1 : 0lowerKCStat = close < lowerKC ? 1 : 0rsiUnder30 = rsiPlot < 30 ? 1: 0bullCondition = rsiPlot > 70 ? 0 : bullRSIStat + diMinusStat + lowerBBStat + lowerKCStat + bbOutsideKC + lowerBB_Bounce + adxUpTrend + rsiUnder30 //Conditions for Bear StrengthupperBB_Bounce = highest(5) >= upperBB ? 1 : 0adxDownTrend = adx < adx[1] ? 1 : 0bearRSIStat = rsiPlot[0] < rsiPlot[1] ? 1 : 0diPlusStat = diPlus[0] > diPlus[1] ? 1 : 0upperBBStat = close > middleBB and close < upperBB ? 1 : 0upperKCStat = close > upperKC ? 1 : 0rsiOver70 = rsiPlot > 70 ? 1: 0bearCondition = rsiPlot < 30 ? 0 : ( bearRSIStat + diPlusStat + upperBBStat + upperKCStat + bbOutsideKC + upperBB_Bounce + adxDownTrend + rsiOver70 ) * -1//Overall Trade Condition, used to find the right side//tradeCondition = (bullOrBear == "Bull") ? (bullCondition) : (bearCondition)tradeCondition = (currentlySqueezed and useSqueezeFilter) ? 0 : bullOrBear == "Bull" ? (bullCondition > 1 ? bullCondition : 0) : (bearCondition < -1 ? bearCondition : 0)signalYesNo = "Yes" //Not currently usedbullColor = color.bluebearColor = color.purplesqueezeColor = color.orangevar sessionFills = array.new_color(22)array.set(sessionFills, 0, color.new(bearColor, 0))array.set(sessionFills, 1, color.new(bearColor, 10))array.set(sessionFills, 2, color.new(bearColor, 20))array.set(sessionFills, 3, color.new(bearColor, 30))array.set(sessionFills, 4, color.new(bearColor, 40))array.set(sessionFills, 5, color.new(bearColor, 50))array.set(sessionFills, 6, color.new(bearColor, 60))array.set(sessionFills, 7, color.new(bearColor, 70))array.set(sessionFills, 8, color.new(bearColor, 80))array.set(sessionFills, 9, color.new(bearColor, 90))array.set(sessionFills, 10, color.new(bullColor, 100))array.set(sessionFills, 11, color.new(bullColor, 90))array.set(sessionFills, 12, color.new(bullColor, 80))array.set(sessionFills, 13, color.new(bullColor, 70))array.set(sessionFills, 14, color.new(bullColor, 60))array.set(sessionFills, 15, color.new(bullColor, 50))array.set(sessionFills, 16, color.new(bullColor, 40))array.set(sessionFills, 17, color.new(bullColor, 30))array.set(sessionFills, 18, color.new(bullColor, 20))array.set(sessionFills, 19, color.new(bullColor, 10))array.set(sessionFills, 20, color.new(bullColor, 0))array.set(sessionFills, 21, color.new(squeezeColor, 90))//Calculate Overlay ColorfillNumber = (currentlySqueezed and showSqueezes) ? 21 : (mktIsHot or mktIsCold) ? 10 : signalYesNo == "No" ? 10 : abs(tradeCondition) < strengthFilter ? 10 : (bullOrBear == "Bear") and (not showBear) ? 10 : (bullOrBear == "Bull") and (not showBull) ? 10 : tradeCondition + 10bgcolor(array.get(sessionFills, fillNumber))//plot(lowerKC, title='lowerKC', color=#00ffaa, linewidth=2, style=plot.style_line)bullOrBearColor = bullOrBear == "Bull" ? color.green : color.redplotshape(tradeCondition, title="Entry Strength", offset=0, style=shape.flag, location=location.top, color=bullOrBearColor, transp=100)plotshape(bullCondition, title="Bull Strength", offset=0, style=shape.flag, location=location.top, color=bullColor, transp=100)plotshape(bearCondition, title="Bear Strength", offset=0, style=shape.flag, location=location.top, color=bearColor, transp=100)curHour = hour(time) - 5rippleDoD = smaShort > smaShort[1] ? "UP" : "DOWN"waveDoD = smaMedium > smaMedium[1] ? "UP" : "DOWN"tideDoD = smaLong > smaLong[1] ? "UP" : "DOWN"rippleWaveUpDn = smaShort > smaMedium ? "ABOVE" : "BELOW"waveTideUpDn = smaMedium > smaLong ? "ABOVE" : "BELOW"// STEP 1:// Make input options that configure backtest date rangestartDate = input(title="Start Date", type=input.integer, defval=1, minval=1, maxval=31)startMonth = input(title="Start Month", type=input.integer, defval=1, minval=1, maxval=12)startYear = input(title="Start Year", type=input.integer, defval=2018, minval=1800, maxval=2100)endDate = input(title="End Date", type=input.integer, defval=1, minval=1, maxval=31)endMonth = input(title="End Month", type=input.integer, defval=12, minval=1, maxval=12)endYear = input(title="End Year", type=input.integer, defval=2021, minval=1800, maxval=2100)// STEP 2:// 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)) entryLimit = closetriggerBar = (bullOrBear=="Bull" and bullCondition >= strengthFilter and (not mktIsHot and not mktIsCold))if triggerBar and inDateRange strategy.entry("BCS", strategy.long, 100, limit=entryLimit, when=strategy.position_size <= 0) // strategy.entry("sell", strategy.short, 10, when=strategy.position_size > 0)//plot(strategy.equity)exitWeekDay = dayofweek == 5 ? 1 : 0 //Exiting on ThursdayentryBar = strategy.position_size[0] > strategy.position_size[1]barsPassedBy = barssince(entryBar)triggerBars = barssince(triggerBar)strategy.cancel("BCS", when = (triggerBars>0))exitStrategy = (barsPassedBy >= 30) and exitWeekDaystrategy.close("BCS", when=exitStrategy)//Narrative BuildnarSqueezed = currentlySqueezed ? "A Squeezed" + "\n" : nanarrativeText = narSqueezed + bullOrBear + " Setup Strength " + tostring(abs(tradeCondition)) + "\n\n" + "RSI " + rsiUpDown + " to " + tostring(rsiPlot, "#.##") + "\n\n" + "ADX " + adxUpDown + " to " + tostring(adx, "#.##") + "\n\n" + "+DI " + diPlusUpDown + " to " + tostring(diPlus, "#.##") + "\n" + "-DI " + diMinusUpDown + " to " + tostring(diMinus, "#.##") + "\n" + "\n-------------------\n" + "Box Score" + "\n-------------------\n" + "Bulls " + tostring(bullCondition) + " | " + "Bears " + tostring(abs(bearCondition)) + "\n\n" + tostring(bullRSIStat) + " RSI " + tostring(bearRSIStat) + "\n" + tostring(diMinusStat) + " DI " + tostring(diPlusStat) + "\n" + tostring(lowerBBStat) + " BB " + tostring(upperBBStat) + "\n" + tostring(lowerKCStat) + " KC " + tostring(upperKCStat) + "\n" + tostring(bbOutsideKC) + " SQ " + tostring(bbOutsideKC) + "\n" + tostring(lowerBB_Bounce) + " BB Bounce " + tostring(upperBB_Bounce) + "\n" + tostring(adxUpTrend) + " ADX " + tostring(adxDownTrend) + "\n" + tostring(rsiUnder30) + " RSI 30/70 " + tostring(rsiOver70) + "\n" +"\n-------------------\n" + "Additional Narrative" + "\n-------------------\n" + tostring(shortSMAPeriod, "##") + " SMA is " + rippleWaveUpDn + " " + tostring(mediumSMAPeriod, "##") + " SMA\n" + "and is " + rippleDoD + " compared to prior bar\n\n" + tostring(mediumSMAPeriod, "##") + " SMA is " + waveTideUpDn + " " + tostring(longSMAPeriod, "##") + " SMA\n" + "and is " + waveDoD + " compared to prior bar\n\n" + tostring(longSMAPeriod, "##") + " SMA is " + tideDoD + " compared to prior bar\n" + "entry Conditions\n" + "BullOrBear " + (bullOrBear) + "\n" + "BullCondition " + tostring(bullCondition,"##") + "\n" + "Entry Limit " + tostring(entryLimit,"##.##") + "\n" + "BullCondition " + tostring(bullCondition,"##") + "\n" + "Bars Passed " + tostring(barsPassedBy,"##") + "\n" + "Tigger Bar " + tostring(triggerBars,"##") + "\n" narrativeLabel = narrationYes ? label.new(x=time, y=((low+high)/2), xloc=xloc.bar_time, text=narrativeText, color=bullOrBear=="Bull" ? bullColor : bearColor, textcolor=color.white, style=label.style_label_left) : na label.set_x(id=narrativeLabel, x=label.get_x(narrativeLabel) + 1)label.delete(narrativeLabel[1])