BNT5.0 Premium Indicator

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 12

//@version=5

indicator('BNT5.0', overlay=true)
var line futureCallLine = na
var line futurePutLine = na
var line futureTopPivotLine = na
var line futureCentralPivotLine = na
var line futureBottomPivotLine = na

length = input(title='ATR Period', defval=1)


mult = input.float(title='ATR Multiplier', step=0.1, defval=9.0)

atr = mult * ta.atr(length)

longStop = hl2 - atr


longStopPrev = nz(longStop[1], longStop)
longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop

shortStop = hl2 + atr


shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) :
shortStop

dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and close > shortStopPrev ? 1 : dir == 1 and close <
longStopPrev ? -1 : dir

plotshape(dir == 1 and dir[1] == -1 ? longStop : na, title='Buy',


style=shape.triangleup, location=location.belowbar, size=size.normal, text='Buy',
textcolor=color.new(#0f0f0f, 0), color=color.new(color.green, 0))
plotshape(dir == -1 and dir[1] == 1 ? shortStop : na, title='Sell',
style=shape.triangledown, location=location.abovebar, size=size.normal,
text='Sell', textcolor=color.new(#0f0f0f, 0), color=color.new(color.red, 0))

barcolor(dir == 1 ? color.new(color.green, 0) : color.new(color.red, 0))

alertcondition(dir == 1 and dir[1] == -1 , title='Buy', message='Buy!')


alertcondition(dir == -1 and dir[1] == 1 , title='Sell', message='Sell!')

len = input.int(21, minval=1, title="Length")


src = input(close, title="Source")
offset = input.int(title="Offset", defval=0, minval=-500, maxval=500)
out = ta.ema(src, len)
plot(out, title="EMA", color=color.red, offset=offset)

ma(source, length, type) =>


switch type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)

typeMA = input.string(title = "Method", defval = "SMA", options=["SMA", "EMA",


"SMMA (RMA)", "WMA", "VWMA"], group="Smoothing")
smoothingLength = input.int(title = "Length", defval = 5, minval = 1, maxval = 100,
group="Smoothing")

smoothingLine = ma(out, smoothingLength, typeMA)


plot(smoothingLine, title="Smoothing Line", color=color.new(color.orange, 0),
offset=offset, display=display.none)

tradeSource = input.source(close, title='Source For Trigger')

autoTF = input.string('Auto', title="Select Higher Timeframe",


options=['Auto','Manual'], group='Pivot Settings')
manPivotTF = input.timeframe('D', title='If Manual, Time Frame for Pivots',
group='Pivot Settings', options=['60','90', '120','D', '2D', '3D', '4D', 'W',
'2W', '3W', '4W', 'M','2M', '3M', '6M'])

//nearStrikePremiumRisk = input.int(1, "Premium Risk Level[1-5 (Higher is


riskier)]", maxval=5, step=1,
// group="Near Strike Calculation Method")
nearStrikeMethod = input.string('Traditional Pivot S1/R1',
title="Near Strike Calculation Source",
options=['Traditional Pivot S1/R1',
'Camarilla Pivot R1/S1',
'Camarilla Pivot R2/S2',
'Manual Offset From Central Pivot Point'],
group="Near Strike Calculation Method")

nearStrikeManualOffset = input.float(0, "Manual Offset Value", group="Near Strike


Calculation Method")

spreadMethod = input.string('Auto', title='Determine Spread', options=['Auto',


'Manual'], group='Spread Method')
manSpreadValue = input.float(5.0, title="Spread Width, if Manual", group='Spread
Method')

showHistoricalTradeLabel = input.bool(false, title='Show Historical Strike Value


Labels', group='Visual')
showHistoricalResults = input.bool(true, title='Show Historical Win/Loss
Percentages', group='Visual')
showFuture = input.bool(false, title='Extend Developing Levels Into Future',
group='Visual')

//pivotPeriodShift =input.int(defval=1, title='Lookback Period for Pivot',


group='Primary Settings')
pivotPeriodShift = 1

sendStandardAlert = input.bool(false, title='Enable Standard Alert',


group='Alerts')
sendDiscordWebhookAlert = input.bool(false, title='Enable Discord Webhook Alert',
group='Alerts')
sendPremiumZoneChangeAlert = input.bool(false, title='Enable Price Movement Into
Different Zone', group='Alerts')

plotTS1R1 = input.bool(false, title='Plot Traditional Pivot R1/S1',


group='Traditional Pivot Plots')
plotTS2R2 = input.bool(false, title='Plot Traditional Pivot R2/S2',
group='Traditional Pivot Plots')
plotTS3R3 = input.bool(false, title='Plot Traditional Pivot R3/S3',
group='Traditional Pivot Plots')

plotCS1R1 = input.bool(false, title='Plot Camarilla Pivot R1/S1',


group='Camarilla Pivot Plots')
plotCS2R2 = input.bool(false, title='Plot Camarilla Pivot R2/S2',
group='Camarilla Pivot Plots')
plotCS3R3 = input.bool(false, title='Plot Camarilla Pivot R3/S3',
group='Camarilla Pivot Plots')
plotCS4R4 = input.bool(false, title='Plot Camarilla Pivot R4/S4',
group='Camarilla Pivot Plots')
plotCS5R5 = input.bool(false, title='Plot Camarilla Pivot R5/S5',
group='Camarilla Pivot Plots')

tradeOnMon = input.bool(true, title='Mondays', group='Trade Days (Good for


Dailies)')
tradeOnTue = input.bool(true, title='Tuesdays', group='Trade Days (Good for
Dailies)')
tradeOnWed = input.bool(true, title='Wednesdays', group='Trade Days (Good for
Dailies)')
tradeOnThu = input.bool(true, title='Thursdays', group='Trade Days (Good for
Dailies)')
tradeOnFri = input.bool(true, title='Fridays', group='Trade Days (Good for
Dailies)')

var tradeTheDay = true


switch
dayofweek == dayofweek.monday => tradeTheDay := tradeOnMon
dayofweek == dayofweek.tuesday => tradeTheDay := tradeOnTue
dayofweek == dayofweek.wednesday => tradeTheDay := tradeOnWed
dayofweek == dayofweek.thursday => tradeTheDay := tradeOnThu
dayofweek == dayofweek.friday => tradeTheDay := tradeOnFri

//auto higher time frame


HTFo = timeframe.period == '1' ? '30' :
timeframe.period == '3' ? '60' :
timeframe.period == '5' ? '240' :
timeframe.period == '15' ? 'D' :
timeframe.period == '30' ? 'D' :
timeframe.period == '45' ? 'D' :
timeframe.period == '60' ? 'W' :
timeframe.period == '120' ? 'W' :
timeframe.period == '180' ? 'W' :
timeframe.period == '240' ? 'W' :
timeframe.period == 'D' ? 'W' :
timeframe.period == 'W' ? '4W' : 'D'

pivotTF = autoTF == 'Auto' ? HTFo : manPivotTF

devPivotTFHigh = request.security(syminfo.tickerid, pivotTF, high,


lookahead=barmerge.lookahead_on)
devPivotTFLow = request.security(syminfo.tickerid, pivotTF, low,
lookahead=barmerge.lookahead_on)
devPivotTFClose = request.security(syminfo.tickerid, pivotTF, close,
lookahead=barmerge.lookahead_on)
pivotTFHigh = request.security(syminfo.tickerid, pivotTF, high[pivotPeriodShift],
lookahead=barmerge.lookahead_on)
pivotTFLow = request.security(syminfo.tickerid, pivotTF, low[pivotPeriodShift],
lookahead=barmerge.lookahead_on)
pivotTFClose = request.security(syminfo.tickerid, pivotTF, close[pivotPeriodShift],
lookahead=barmerge.lookahead_on)
priorPivotTFHigh = request.security(syminfo.tickerid, pivotTF,
high[pivotPeriodShift + 1], lookahead=barmerge.lookahead_on)
priorPivotTFLow = request.security(syminfo.tickerid, pivotTF, low[pivotPeriodShift
+ 1], lookahead=barmerge.lookahead_on)
priorPivotTFClose = request.security(syminfo.tickerid, pivotTF,
close[pivotPeriodShift + 1], lookahead=barmerge.lookahead_on)
pivotLastBar = request.security(syminfo.tickerid, pivotTF, barstate.islast,
lookahead=barmerge.lookahead_on)

RANGE = pivotTFHigh- pivotTFLow

//CPR Calculations
centralPivot = (pivotTFHigh + pivotTFLow + pivotTFClose) / 3
tempBottomPivot = (pivotTFHigh + pivotTFLow) / 2
tempTopPivot = (centralPivot - tempBottomPivot) + centralPivot

bottomPivot = (tempBottomPivot > tempTopPivot) ? tempTopPivot : tempBottomPivot


topPivot = bottomPivot == tempBottomPivot ? tempTopPivot : tempBottomPivot

cprRange = topPivot - bottomPivot

//Traditional Pivot Point Calculations


tS1 = 2 * centralPivot - pivotTFHigh
tS2 = centralPivot - (pivotTFHigh - pivotTFLow)
tS3 = tS1 - (pivotTFHigh - pivotTFLow)
tR1 = 2 * centralPivot - pivotTFLow
tR2 = centralPivot + (pivotTFHigh - pivotTFLow)
tR3 = tR1 + (pivotTFHigh - pivotTFLow)

//Camarilla Pivot Point Calculations


camR5 = pivotTFHigh / pivotTFLow * pivotTFClose
camR4 = pivotTFClose + RANGE * 1.1 / 2
camR3 = pivotTFClose + RANGE * 1.1 / 4
camR2 = pivotTFClose + RANGE * 1.1 / 6
camR1 = pivotTFClose + RANGE * 1.1 / 12
camS1 = pivotTFClose - RANGE * 1.1 / 12
camS2 = pivotTFClose - RANGE * 1.1 / 6
camS3 = pivotTFClose - RANGE * 1.1 / 4
camS4 = pivotTFClose - RANGE * 1.1 / 2
camS5 = pivotTFClose - (camR5 - pivotTFClose)

//Developing CPR & tR1 & tS1


devCentralPivot = (devPivotTFHigh + devPivotTFLow + devPivotTFClose) / 3
devTempBottomPivot = (devPivotTFHigh + devPivotTFLow) / 2
devTempTopPivot = (devCentralPivot - devTempBottomPivot) + devCentralPivot

devBottomPivot = (devTempBottomPivot > devTempTopPivot) ? devTempTopPivot :


devTempBottomPivot
devTopPivot = devBottomPivot == devTempBottomPivot ? devTempTopPivot :
devTempBottomPivot
devTS1 = 2 * devCentralPivot - devPivotTFHigh
devTR1 = 2 * devCentralPivot - devPivotTFLow

//spreadValue Floor & Ceiling


spreadValueCalc(calcValue, spreadValue, callOrPutSide) =>
var retValue = 0.00
switch
callOrPutSide == 'Call' => retValue := (math.ceil(calcValue/spreadValue)) *
spreadValue
callOrPutSide == 'Put' => retValue := (math.floor(calcValue/spreadValue)) *
spreadValue

//Strike Values
spreadValue = spreadMethod == "Auto" ? close >= 1000 ? 50.0 :
close >= 500 ? 10.0 :
close >= 100 ? 5.0 :
close >= 50 ? 2.5 :
close >= 20 ? 1 :
close < 20 ? 0.5 : 0
:
manSpreadValue

callTriggerValue = nearStrikeMethod == 'Traditional Pivot S1/R1' ? tS1 :


nearStrikeMethod == 'Camarilla Pivot R1/S1' ? camS1 :
nearStrikeMethod == 'Camarilla Pivot R2/S2' ? camS2 :
centralPivot

putTriggerValue = nearStrikeMethod == 'Traditional Pivot S1/R1' ? tR1 :


nearStrikeMethod == 'Camarilla Pivot R1/S1' ? camR1 :
nearStrikeMethod == 'Camarilla Pivot R2/S2' ? camR2 :
centralPivot

callNearStrikeSource = nearStrikeMethod == 'Traditional Pivot S1/R1' ?


math.max(pivotTFHigh, tR1) :
nearStrikeMethod == 'Camarilla Pivot R1/S1' ? math.max(pivotTFHigh, camR1) :
nearStrikeMethod == 'Camarilla Pivot R2/S2' ? math.max(pivotTFHigh, camR2) :
centralPivot + nearStrikeManualOffset

putNearStrikeSource = nearStrikeMethod == 'Traditional Pivot S1/R1' ?


math.min(pivotTFLow, tS1) :
nearStrikeMethod == 'Camarilla Pivot R1/S1' ? math.min(pivotTFLow, camS1) :
nearStrikeMethod == 'Camarilla Pivot R2/S2' ? math.min(pivotTFLow, camS2) :
centralPivot - nearStrikeManualOffset

calcCallValue = close < callTriggerValue ? topPivot : math.avg(centralPivot,


callNearStrikeSource)
callStrikeValue = spreadValueCalc(calcCallValue, spreadValue, 'Call')
callStrikeValue2 = callStrikeValue + spreadValue
calcPutValue = close > putTriggerValue ? bottomPivot : math.avg(centralPivot,
putNearStrikeSource)
putStrikeValue = spreadValueCalc(calcPutValue, spreadValue, 'Put')
putStrikeValue2 = putStrikeValue - spreadValue
icCallStrikeValue = spreadValueCalc(tR1,spreadValue, 'Call')
icCallStrikeValue2 = icCallStrikeValue + spreadValue
icPutStrikeValue = spreadValueCalc(tS1, spreadValue, 'Put')
icPutStrikeValue2 = icPutStrikeValue - spreadValue

//Tomorrow's Strikes
calcDevCallValue = close < devTS1 ? devTopPivot : math.avg(devCentralPivot,
math.max(devPivotTFHigh, devTR1))
calcDevPutValue = close > devTR1 ? devBottomPivot : math.avg(devCentralPivot,
math.min(devPivotTFLow, devTS1))
devCallStrikeValue = spreadValueCalc(calcDevCallValue, spreadValue, 'Call')
devPutStrikeValue = spreadValueCalc(calcDevPutValue, spreadValue, 'Put')

//New Bar
is_newbar(res, sess) =>
t = time(res, sess)
na(t[1]) and not na(t) or t[1] < t

openingBarClosed = is_newbar(pivotTF, session.regular)[1]


openingBarOpen = is_newbar(pivotTF, session.regular)
//Trade Calculations

var tradeDecision = "No Trade"


var strikeValue = 0.00
var strikeValue2 = 0.00
var yPlacement = 0.00
var labelStyle = label.style_label_lower_right
var tradeLabelText = "None"
var alertText ="None"

string tradeType = switch


tradeSource > topPivot => "Sell Put"
tradeSource < bottomPivot => "Sell Call"
(tradeSource < topPivot and tradeSource > bottomPivot) => "Sell IC"

if openingBarClosed and tradeTheDay


tradeDecision := tradeType[1]
strikeValue :=
tradeDecision == "Sell Put" ? putStrikeValue :
tradeDecision == "Sell Call" ? callStrikeValue :
tradeDecision == "Sell IC" ? icCallStrikeValue : na
strikeValue2 :=
tradeDecision == "Sell Put" ? putStrikeValue2 :
tradeDecision == "Sell Call" ? callStrikeValue2 :
tradeDecision == "Sell IC" ? icPutStrikeValue : na
tradeLabelText := tradeDecision + ' for ' + str.tostring(strikeValue, '#.##')
yPlacement :=
tradeDecision == "Sell Put" ? putStrikeValue :
tradeDecision == "Sell Call" ? callStrikeValue :
tradeDecision == "Sell IC" ? icCallStrikeValue : na
labelStyle := tradeDecision == "Sell Put" ? label.style_label_upper_left :
tradeDecision == "Sell Call" ? label.style_label_lower_left :
tradeDecision == "Sell IC" ? label.style_label_lower_left :
label.style_label_lower_left

alertText := tradeDecision == "Sell Put" ?"Sell Put Strike " +


str.tostring(strikeValue, '#.##') + " | " + "Buy Put Strike " +
str.tostring(strikeValue2, '#.##') :
tradeDecision == "Sell Call" ? "Sell Call Strike " +
str.tostring(strikeValue, '#.##') + " | " + "Buy Call Strike " +
str.tostring(strikeValue2, '#.##') :
tradeDecision == "Sell IC" ? "IC | Sell Call Strike " +
str.tostring(icCallStrikeValue, '#.##') + " | " + "Buy Call Strike " +
str.tostring(icCallStrikeValue2, '#.##') + " | " + "Sell Put Strike " +
str.tostring(icPutStrikeValue, '#.##') + " | " + "Buy Put Strike " +
str.tostring(icPutStrikeValue2, '#.##') : na
if showHistoricalTradeLabel or pivotLastBar
label.new(x=bar_index, y=yPlacement, color=color.new(#0c0c0c, 0),
textcolor=color.white, size=size.small, style=labelStyle, text=alertText)

alertText := "Ticker: " + syminfo.ticker + " - " + alertText

plot((tradeTheDay and not openingBarOpen) ? strikeValue : na, "Strike Value",


color=color.black, style=plot.style_linebr)

//Prior Day Trade Result


var wins = 0
var losses = 0
var callWins = 0
var callLosses = 0
var icWins = 0
var icLosses = 0
var putWins = 0
var putLosses = 0
var callCount = 0
var icCount = 0
var putCount = 0
var tradeResult = "No Trade"

if openingBarOpen and tradeTheDay[1]


if tradeDecision == "Sell Put"
wins := close[1] > strikeValue ? wins + 1 : wins
losses := close[1] < strikeValue ? losses + 1 : losses
tradeResult := close[1] > strikeValue ? "Win" : "Loss"
putWins := close[1] > strikeValue ? putWins + 1 : putWins
putLosses := close[1] < strikeValue ? putLosses + 1 : putLosses
putCount := putCount + 1
if tradeDecision == "Sell Call"
wins := close[1] < strikeValue ? wins + 1 : wins
losses := close[1] > strikeValue ? losses + 1 : losses
tradeResult := close[1] < strikeValue ? "Win" : "Loss"
callWins := close[1] < strikeValue ? callWins + 1 : callWins
callLosses := close[1] > strikeValue ? callLosses + 1 : callLosses
callCount := callCount + 1
if tradeDecision == "Sell IC"
wins := (close[1] > strikeValue2 and close[1] < strikeValue) ? wins + 1 :
wins
losses := (close[1] < strikeValue2 or close[1] > strikeValue) ? losses +
1 : losses
tradeResult := (close[1] > strikeValue2 and close[1] < strikeValue) ? "Win"
: "Loss"
icWins := (close[1] > strikeValue2 and close[1] < strikeValue) ? icWins + 1
: icWins
icLosses := (close[1] < strikeValue2 or close[1] > strikeValue) ? icLosses
+ 1 : icLosses
icCount := icCount + 1

label.new(x=bar_index -1, y=yPlacement, color=color.new(tradeResult == "Win" ?


color.green : color.red,50),textcolor=color.black, size=size.small,
style=labelStyle, text=tradeResult)

// Results & Current Trade

string premiumValue = switch


(strikeValue < bottomPivot and close < bottomPivot) or
(strikeValue > topPivot and close > topPivot) => "Optimal (Hedge)"
(strikeValue < bottomPivot and close < centralPivot) or
(strikeValue > topPivot and close > centralPivot) => "Good"
(strikeValue < bottomPivot and close < topPivot) or
(strikeValue > topPivot and close > bottomPivot) => "Decent"
=> "Standard"

var table resultsDisplay = table.new(position.bottom_right, 4, 5)


var table currentSetup = table.new(position.top_right, 2, 3)
if barstate.islast
var tfLabelText ="nothing"
tfLabelText := '----Current Setup----\n\n'
tfLabelText := tfLabelText + 'Pivot Timeframe: ' + pivotTF
tfLabelText := tfLabelText + '\n' + tradeLabelText
table.cell(currentSetup, 0, 0, 'Pivot TF', text_color=color.black)
table.cell(currentSetup, 1, 0, pivotTF, text_color=color.black)
table.cell(currentSetup, 0, 1, tradeDecision, text_color=color.black)
table.cell(currentSetup, 1, 1, str.tostring(strikeValue, '#.##'),
text_color=color.black)
table.cell(currentSetup, 0, 2, 'Timing', text_color=color.black)
table.cell(currentSetup, 1, 2, premiumValue, text_color=color.black)

//Plot Future Values


if showFuture
if na(futureCallLine)
futureCallLine := line.new(x1=bar_index, y1=devCallStrikeValue,
x2=bar_index + 5, y2=devCallStrikeValue, color=color.gray, extend=extend.right)
else
line.set_xy1(futureCallLine, bar_index, devCallStrikeValue)
line.set_xy2(futureCallLine, bar_index + 5, devCallStrikeValue)

if na(futurePutLine)
futurePutLine := line.new(x1=bar_index, y1=devPutStrikeValue,
x2=bar_index + 5, y2=devPutStrikeValue, color=color.gray, extend=extend.right)
else
line.set_xy1(futurePutLine, bar_index, devPutStrikeValue)
line.set_xy2(futurePutLine, bar_index + 5, devPutStrikeValue)

if na(futureTopPivotLine)
futureTopPivotLine := line.new(x1=bar_index, y1=devTopPivot,
x2=bar_index + 5, y2=devTopPivot, color=color.black, extend=extend.right)
else
line.set_xy1(futureTopPivotLine, bar_index, devTopPivot)
line.set_xy2(futureTopPivotLine, bar_index + 5, devTopPivot)

if na(futureCentralPivotLine)
futureCentralPivotLine := line.new(x1=bar_index, y1=devCentralPivot,
x2=bar_index + 5, y2=devCentralPivot, color=color.purple, extend=extend.right)
else
line.set_xy1(futureCentralPivotLine, bar_index, devCentralPivot)
line.set_xy2(futureCentralPivotLine, bar_index + 5, devCentralPivot)

if na(futureBottomPivotLine)
futureBottomPivotLine := line.new(x1=bar_index, y1=devBottomPivot,
x2=bar_index + 5, y2=devBottomPivot, color=color.black, extend=extend.right)
else
line.set_xy1(futureBottomPivotLine, bar_index, devBottomPivot)
line.set_xy2(futureBottomPivotLine, bar_index + 5, devBottomPivot)

// We only populate the table on the last bar.


if showHistoricalResults
table.cell(resultsDisplay, 1, 0, 'Trades', text_color=color.black)
table.cell(resultsDisplay, 2, 0, 'Wins', text_color=color.black)
table.cell(resultsDisplay, 3, 0, 'Win %', text_color=color.black)
table.cell(resultsDisplay, 0, 1, 'All', text_color=color.black)
table.cell(resultsDisplay, 1, 1, str.tostring(wins+losses, '#'),
text_color=color.black)
table.cell(resultsDisplay, 2, 1, str.tostring(wins, '#'),
text_color=color.black)
table.cell(resultsDisplay, 3, 1, str.tostring(wins/(wins+losses)*100,
'#.#') , text_color=color.black)
table.cell(resultsDisplay, 0, 2, 'Calls', text_color=color.black)
table.cell(resultsDisplay, 1, 2, str.tostring(callWins + callLosses, '#'),
text_color=color.black)
table.cell(resultsDisplay, 2, 2, str.tostring(callWins, '#') ,
text_color=color.black)
table.cell(resultsDisplay, 3, 2,
str.tostring(callWins/(callWins+callLosses)*100, '#.#') , text_color=color.black)
table.cell(resultsDisplay, 0, 3, 'Puts', text_color=color.black)
table.cell(resultsDisplay, 1, 3, str.tostring(putWins + putLosses, '#'),
text_color=color.black)
table.cell(resultsDisplay, 2, 3, str.tostring(putWins, '#') ,
text_color=color.black)
table.cell(resultsDisplay, 3, 3, str.tostring(putWins/(putWins +
putLosses)*100, '#.#') , text_color=color.black)
table.cell(resultsDisplay, 0, 4, 'ICs', text_color=color.black)
table.cell(resultsDisplay, 1, 4, str.tostring(icWins + icLosses, '#'),
text_color=color.black)
table.cell(resultsDisplay, 2, 4, str.tostring(icWins, '#') ,
text_color=color.black)
table.cell(resultsDisplay, 3, 4, str.tostring(icWins/(icWins +
icLosses)*100, '#.#') , text_color=color.black)

//Alerts
sendAlert = close < 6000

webHookAlertMessage = '{\"content\":\"' + alertText + '\"}'

//{"content":"{{ticker}} Long Entry Triggered | Open: {{open}} | Close:


{{close}} Low: {{low}} |High: {{high}}"}

if (sendStandardAlert and openingBarClosed)


alert(alertText, alert.freq_once_per_bar)

if (sendDiscordWebhookAlert and openingBarClosed)


alert(webHookAlertMessage, alert.freq_once_per_bar)
premiumZoneChange =
(premiumValue == "Optimal (Hedge)" and premiumValue[1]!= "Optimal (Hedge)")
or
(premiumValue == "Good" and (premiumValue[1] != "Optimal (Hedge)" and
premiumValue[1] != "Good"))
or
(premiumValue == "Decent" and (premiumValue[1] != "Optimal (Hedge)" and
premiumValue[1] != "Good" and premiumValue[1] != "Decent"))

if premiumZoneChange and sendPremiumZoneChangeAlert


alert(syminfo.ticker + " Premium Zone has changed to " + premiumValue,
alert.freq_once_per_bar)

///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
ShowSD1 = input.bool(false, 'Supply Demand Zone', group='Supply Demand 1',
inline='Supply Demand 1')
ShowSZ1 = input.bool(false, 'Support Zone', group='Supply Demand 1', inline='Supply
Demand 1')
ShowRZ1 = input.bool(false, 'Resistance Zone', group='Supply Demand 1',
inline='Supply Demand 1')
RSI1Length = input.int(7, minval=1, title='RSI 1 Length', group='Supply Demand 1')
RSI1OBOSIn = input.string(defval='70 / 30', title='OB / OS', options=['70 / 30',
'75 / 25', '80 / 20', '85 / 15', '90 / 10', '95 / 5'], group='Supply Demand 1')
NumberOfConfirmationBarsRSI1 = input.int(3, title='Confirmation Bars',
group='Supply Demand 1')

RSI1SDColorIn = input.color(color.new(color.blue, 85), 'Fill Colors - Supply


Demand', group='Supply Demand 1', inline='Fill 1')
RSI1SupportColorIn = input.color(color.new(color.lime, 92), 'Support',
group='Supply Demand 1', inline='Fill 1')
RSI1ResistanceColorIn = input.color(color.new(color.red, 92), 'Resistance',
group='Supply Demand 1', inline='Fill 1')

RSI1 = ta.rsi(close, RSI1Length)

RSI1OB = RSI1OBOSIn == '70 / 30' ? 70 : RSI1OBOSIn == '75 / 25' ? 75 :


RSI1OBOSIn== '80 / 20' ? 80 : RSI1OBOSIn == '90 / 10' ? 90 : RSI1OBOSIn == '95 /
5' ? 95 :100
RSI1OS = RSI1OBOSIn == '70 / 30' ? 30 : RSI1OBOSIn == '75 / 25' ? 25 :
RSI1OBOSIn== '80 / 20' ? 20 : RSI1OBOSIn == '90 / 10' ? 10 : RSI1OBOSIn == '95 /
5' ? 5 : 0

RSI1incrementer_up = RSI1 > RSI1OB ? 1 : 0


RSI1incrementer_down = RSI1 < RSI1OS ? 1 : 0
RSI1incrementer_both = RSI1 > RSI1OB or RSI1 < RSI1OS ? 1 : 0

///////////////////////////////////////////////////////////////////////////////////
RSI1rsx = 0
if RSI1incrementer_both
RSI1rsx := nz(RSI1rsx[1], 0) + RSI1incrementer_both
else
RSI1rsx := 0
var float RSI1rxH = na
if RSI1rsx >= NumberOfConfirmationBarsRSI1
RSI1rxH := high
var float RSI1rxL = na
if RSI1rsx >= NumberOfConfirmationBarsRSI1
RSI1rxL := low
RSI1rH = fixnan(RSI1rxH)
RSI1rL = fixnan(RSI1rxL)
///////////////////////////////////////////////////////
RSI1rsu = 0
if RSI1incrementer_up
RSI1rsu := nz(RSI1rsu[1], 0) + RSI1incrementer_up
else
RSI1rsu := 0
RSI1rssH = if RSI1rsu >= NumberOfConfirmationBarsRSI1
RSI1x = high
RSI1rssL = if RSI1rsu >= NumberOfConfirmationBarsRSI1
RSI1y = low
RSI1ResistanceZoneHigh = fixnan(RSI1rssH)
RSI1ResistanceZoneLow = fixnan(RSI1rssL)
////////////////////////////////////////////////////////
RSI1rsd = 0
if RSI1incrementer_down
RSI1rsd := nz(RSI1rsd[1], 0) + RSI1incrementer_down
else
RSI1rsd := 0
RSI1rsrH = if RSI1rsd >= NumberOfConfirmationBarsRSI1
RSI1x = high

RSI1rsrL = if RSI1rsd >= NumberOfConfirmationBarsRSI1


RSI1y = low

RSI1SupportZoneHigh = fixnan(RSI1rsrH)
RSI1SupportZoneLow = fixnan(RSI1rsrL)

////////////////////////////////////////////////////////

RSI1_ResZoneColor = RSI1ResistanceZoneHigh != RSI1ResistanceZoneHigh[1] ?


na :RSI1ResistanceColorIn
RSI1_SupZoneColor = RSI1SupportZoneLow != RSI1SupportZoneLow[1] ?
na :RSI1SupportColorIn
RSI1SDColor = RSI1rH != RSI1rH[1] ? na : RSI1SDColorIn

////////////////////////////////////////////////////////

RSI1RZHigh = plot(ShowRZ1 ? RSI1ResistanceZoneHigh : na, style=plot.style_cross,


title='Resistance Zone - 1 - High', color=color.new(RSI1_ResZoneColor, 90))
RSI1RZLow = plot(ShowRZ1 ? RSI1ResistanceZoneLow : na, style=plot.style_cross,
title='Resistance Zone - 1 - Low', color=color.new(RSI1_ResZoneColor, 100))
fill(RSI1RZHigh, RSI1RZLow, color=color.new(RSI1_ResZoneColor, 90), title='Support
Zone - 1 -Fill')

RSI1SZHigh = plot(ShowSZ1 ? RSI1SupportZoneHigh : na, style=plot.style_cross,


title='Support Zone - 1 - High', color=color.new(RSI1_SupZoneColor, 100))
RSI1SZLow = plot(ShowSZ1 ? RSI1SupportZoneLow : na, style=plot.style_cross,
title='Support Zone - 1 - Low', color=color.new(RSI1_SupZoneColor, 100))
fill(RSI1SZHigh, RSI1SZLow, color=color.new(RSI1_SupZoneColor, 90), title='Support
Zone - 1 -Fill')

PlotRSI1rH = plot(ShowSD1 ? RSI1rH : na, style=plot.style_cross,


linewidth=1,title='Supply Demand - 1 - High', color=color.new(RSI1SDColor, 90))
PlotRSI1rL = plot(ShowSD1 ? RSI1rL : na, style=plot.style_cross,
linewidth=1,title='Supply Demand - 1 - Low', color=color.new(RSI1SDColor, 90))
fill(PlotRSI1rH, PlotRSI1rL, color=color.new(RSI1SDColor, 90), title='Supply Demand
- 1 - Fill')

////////////////////////////////////////////////////////

PriceInRSI1SDZone = close <= RSI1rH and close >= RSI1rL and RSI1rH == RSI1rH[1]
PriceEntersRSI1SDZone = PriceInRSI1SDZone and not PriceInRSI1SDZone[1]

alertcondition(PriceEntersRSI1SDZone, title='Alert - Price Enters S/D Zone


1',message='Price Enters S/D Zone 1 - RSI S/D')

///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//

ShowSD2 = input.bool(true, 'Supply Demand Zone', group='Supply Demand 2',


inline='Supply Demand 2')
ShowSZ2 = input.bool(false, 'Support Zone', group='Supply Demand 2', inline='Supply
Demand 2')
ShowRZ2 = input.bool(false, 'Resistance Zone', group='Supply Demand 2',
inline='Supply Demand 2')
RSI2Length = input.int(14, minval=1, title='RSI 2 Length', group='Supply Demand 2')
RSI2OBOSIn = input.string(defval='70 / 30', title='OB / OS', options=['70 / 30',
'75 / 25', '80 / 20', '85 / 15', '90 / 10', '95 / 5'], group='Supply Demand 2')
NumberOfConfirmationBarsRSI2 = input.int(3, title='Confirmation Bars',
group='Supply Demand 2')

RSI2SDColorIn = input.color(color.new(color.blue, 85), 'Fill Colors - Supply


Demand', group='Supply Demand 2', inline='Fill 2')
RSI2SupportColorIn = input.color(color.new(color.lime, 92), 'Support',
group='Supply Demand 2', inline='Fill 2')
RSI2ResistanceColorIn = input.color(color.new(color.red, 92), 'Resistance',
group='Supply Demand 2', inline='Fill 2')

RSI2 = ta.rsi(close, RSI2Length)

RSI2OB = RSI2OBOSIn == '70 / 30' ? 70 : RSI2OBOSIn == '75 / 25' ? 75 :


RSI2OBOSIn== '80 / 20' ? 80 : RSI2OBOSIn == '90 / 10' ? 90 : RSI2OBOSIn == '95 /
5' ? 95 :100
RSI2OS = RSI2OBOSIn == '70 / 30' ? 30 : RSI2OBOSIn == '75 / 25' ? 25 :
RSI2OBOSIn== '80 / 20' ? 20 : RSI2OBOSIn == '90 / 10' ? 10 : RSI2OBOSIn == '95 /
5' ? 5 : 0

RSI2incrementer_up = RSI2 > RSI2OB ? 1 : 0


RSI2incrementer_down = RSI2 < RSI2OS ? 1 : 0
RSI2incrementer_both = RSI2 > RSI2OB or RSI2 < RSI2OS ? 1 : 0

RSI2rsx = 0

if RSI2incrementer_both
RSI2rsx := nz(RSI2rsx[1], 0) + RSI2incrementer_both
else
RSI2rsx := 0

RSI2rxH = if RSI2rsx >= NumberOfConfirmationBarsRSI2


RSI2x = high
RSI2rxL = if RSI2rsx >= NumberOfConfirmationBarsRSI2
RSI2y = low

RSI2rH = fixnan(RSI2rxH)
RSI2rL = fixnan(RSI2rxL)

///////////////////////////////////////////////////////
RSI2rsu = 0

if RSI2incrementer_up
RSI2rsu := nz(RSI2rsu[1], 0) + RSI2incrementer_up
else
RSI2rsu := 0

RSI2rssH = if RSI2rsu >= NumberOfConfirmationBarsRSI2


RSI2x = high
RSI2x

RSI2rssL = if RSI2rsu >= NumberOfConfirmationBarsRSI2


RSI2y = low
RSI2y

You might also like