Premium SUPER Scalping Killer Algo
Premium SUPER Scalping Killer Algo
//@version=5
indicator('Premium_SUPER_Scalping Killer Algo', shorttitle='Premium_SUPER_Scalping
Killer Algo', overlay=true,max_lines_count=500, max_bars_back=2000,
max_boxes_count=500)
// User inputs
showTomorrowCPR = input(title='Show tomorrow\'s CPR', defval=true)
showHistoricalCPR = input(title='Show historical CPR', defval=true)
showWeeklyCPR = input(title='Show Weekly CPR', defval=true)
showR3wS3w = input(title='Show R3w & S3w', defval=true)
showR3S3 = input(title='Show R3 & S3', defval=true)
showPDHL = input(title='Show previous day\'s High & Low', defval=true)
showPDC = input(title='Show previous day\'s Close', defval=true)
// Defaults
// CPR Colors
cprColor = #FF6EFF
rColor = color.red
sColor = color.green
cColor = #3eecd5
wcprcolor = color.white
//Fill Transparency
fTransp = 95
// Global Functions
// TODO : Update the list of Holiday here in format YYYY, MM, DD, 09, 15
// **09, 15 are session start hour & minutes
IsHoliday(_date) =>
iff_1 = _date == timestamp(2020, 12, 25, 09, 15) ? true : false
iff_2 = _date == timestamp(2020, 11, 30, 09, 15) ? true : iff_1
iff_3 = _date == timestamp(2020, 11, 16, 09, 15) ? true : iff_2
iff_4 = _date == timestamp(2020, 10, 02, 09, 15) ? true : iff_3
iff_5 = _date == timestamp(2020, 05, 25, 09, 15) ? true : iff_4
iff_6 = _date == timestamp(2020, 05, 01, 09, 15) ? true : iff_5
iff_7 = _date == timestamp(2020, 04, 14, 09, 15) ? true : iff_6
iff_8 = _date == timestamp(2020, 04, 10, 09, 15) ? true : iff_7
iff_9 = _date == timestamp(2020, 04, 06, 09, 15) ? true : iff_8
iff_10 = _date == timestamp(2020, 04, 02, 09, 15) ? true : iff_9
iff_11 = _date == timestamp(2020, 03, 10, 09, 15) ? true : iff_10
_date == timestamp(2020, 02, 21, 09, 15) ? true : iff_11
// Skip Weekend
SkipWeekend(_date) =>
_d = dayofweek(_date)
_mul = _d == 6 ? 3 : _d == 7 ? 2 : 1
for i = 1 to noOfHolidays by 1
if IsHoliday(_dt)
_dt := SkipWeekend(_dt)
continue
else
break
_dt
tom_start = start
tom_end = end
// Get series
getSeries(e, timeFrame) =>
request.security(syminfo.tickerid, 'D', e, lookahead=barmerge.lookahead_on)
getwSeries(e, timeFrame) =>
request.security(syminfo.tickerid, 'W', e, lookahead=barmerge.lookahead_on)
// Pivot Range
P = (H + L + C) / 3
TC = (H + L) / 2
BC = P - TC + P
// Support Levels
S1 = P * 2 - H
S2 = P - (H - L)
S3 = L - 2 * (H - P)
Hw = getwSeries(high[1], 'W')
Lw = getwSeries(low[1], 'W')
Cw = getwSeries(close[1], 'W')
Pw = (Hw + Lw + Cw) / 3
TCw = (Hw + Lw) / 2
BCw = Pw - TCw + Pw
S1w = Pw * 2 - Hw
S2w = Pw - (Hw - Lw)
S3w = Lw - 2 * (Hw - Pw)
// Pivot Range
tP = (tH + tL + tC) / 3
tTC = (tH + tL) / 2
tBC = tP - tTC + tP
// Resistance Levels
tR3 = tH + 2 * (tP - tL)
tR2 = tP + tH - tL
tR1 = tP * 2 - tL
// Support Levels
tS1 = tP * 2 - tH
tS2 = tP - (tH - tL)
tS3 = tL - 2 * (tH - tP)
Little = ta.wma(close, 9)
short = ta.ema(close, 21)
middle = ta.ema(close, 89)
longest = ta.ema(close, 175)
//VWAP
PlotVWAP = input(title='Plot VWAP?', defval=true)
VWAPSource = input(title='VWAP Source', defval=hlc3)
VWAPrice = ta.vwap(VWAPSource)
plot(PlotVWAP ? VWAPrice : na, color=color.new(color.white, 0), title='VWAP',
linewidth=2)
if longStop > 0
if doji4price
longStop := longStopPrev
longStop
else
longStop := lowPrice[1] > longStopPrev ? math.max(longStop, longStopPrev) :
longStop
longStop
else
longStop := longStopPrev
longStop
if shortStop > 0
if doji4price
shortStop := shortStopPrev
shortStop
else
shortStop := highPrice[1] < shortStopPrev ? math.min(shortStop,
shortStopPrev) : shortStop
shortStop
else
shortStop := shortStopPrev
shortStop
// Parabolic SAR
src5 = close
len = input.int(14, minval=1, title='Length')
//coloring user input
src1 = close
len1 = input.int(53, minval=1, title='Overbought')
src2 = close
len2 = input.int(47, minval=1, title='Oversold')
src3 = close
len11 = input.int(80, minval=1, title='Very Overbought')
src4 = close
len22 = input.int(25, minval=1, title='Very Oversold')
//rsi processing
up = ta.rma(math.max(ta.change(src5), 0), len)
down = ta.rma(-math.min(ta.change(src5), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)
//coloring function
isBought() =>
rsi > len1 and rsi < len11
isSold() =>
rsi < len2 and rsi > len22
isVeryBought() =>
rsi > len11 and rsi > len1
isVerySold() =>
rsi < len22 and rsi < len2
// Signal
signalLength = input.int(9, minval=1, title='Signal Length')
signal = ta.ema(macd, signalLength)
lookback = input.int(1, minval=0, title='Color Lookback (0 to disable)')
signalColor = lookback == 0 ? #009933 : ta.rising(signal, lookback) ? #5cd65c :
ta.falling(signal, lookback) ? #ff3333 : #ff3333
plotchar(signal, char='¦', title='Signal', color=signalColor,
location=location.bottom, size=size.tiny, transp=0)
// Bollinger Band
// Draw channel.
len10 = input(20)
channelType = input.string(defval='Bollinger', title='Channel Type',
options=['NONE', 'Donchian', 'Bollinger', 'Envelope'])
channelLen = input.int(14, minval=1, title='Channel Length')
envPer = input.float(4, title='Envelope %', minval=0) / 100
// Super Xtrend
atr2 = ta.atr(100) / 2
dev = channelDeviation * atr2
highPrice1 = high[math.abs(ta.highestbars(amplitude))]
lowPrice1 = low[math.abs(ta.lowestbars(amplitude))]
highma = ta.sma(high, amplitude)
lowma = ta.sma(low, amplitude)
if nextTrend == 1
maxLowPrice := math.max(lowPrice1, maxLowPrice)
if trend == 0
if not na(trend[1]) and trend[1] != 0
up1 := na(down1[1]) ? down1 : down1[1]
arrowUp := up - atr2
arrowUp
else
up1 := na(up1[1]) ? maxLowPrice : math.max(maxLowPrice, up1[1])
up1
atrHigh := up1 + dev
atrLow := up1 - dev
atrLow
else
if not na(trend[1]) and trend[1] != 1
down1 := na(up1[1]) ? up1 : up1[1]
arrowDown := down1 + atr2
arrowDown
else
down1 := na(down1[1]) ? minHighPrice : math.min(minHighPrice, down1[1])
down1
atrHigh := down1 + dev
atrLow := down1 - dev
atrLow
// OB
OBMitigationType = input.string("Close", title="OB Mitigation Type",
options=["Close", "Wick"], group="Order Block", tooltip="Choose how Order Blocks
are mitigated")
OBBullMitigation = OBMitigationType=="Close" ? close[1] : low
OBBearMitigation = OBMitigationType=="Close" ? close[1] : high
//OB Colors
col_bullish = input.color(#5db49e, title="Bullish OB Border", inline="a",
group="Order Block")
col_bullish_ob = input.color(color.new(#64C4AC, 85), title="Background",
inline="a", group="Order Block")
// Alerts
buy_alert = input.bool(title='Buy Signal', defval=true, group='Alerts', tooltip='An
alert will be sent when price goes below the top of a bullish order block.')
sell_alert = input.bool(title='Sell Signal', defval=true, group='Alerts',
tooltip='An alert will be sent when price goes above the bottom of a bearish order
block.')
// Delacring Variables
bool ob_created = false
bool ob_created_bull = false
var int cross_index = na
// If the ROC crossover our Sensitivty input - Then create an Order Block
// Sensitivty is negative as this is a Bearish OB
if ta.crossunder(pc, -sens)
ob_created := true
cross_index := bar_index
cross_index
// If the ROC crossover our Sensitivty input - Then create an Order Block
if ta.crossover(pc, sens)
ob_created_bull := true
cross_index := bar_index
cross_index
// -------------------------------
// Bearish OB Creation
// -------------------------------
// Check if we should create a OB, Also check if we haven't created an OB in the
last 5 candles.
if ob_created and cross_index - cross_index[1] > 5
float last_green = 0
float highest = 0
// Loop through the most recent candles and find the first GREEN (Bullish)
candle. We will place our OB here.
for i = 4 to 15 by 1
if close[i] > open[i]
last_green := i
break
// Draw our OB on that candle - then push the box into our box arrays.
drawShortBox := box.new(left=bar_index[last_green], top=high[last_green],
bottom=low[last_green], right=bar_index[last_green], bgcolor=col_bearish_ob,
border_color=col_bearish, extend=extend.right)
array.push(shortBoxes, drawShortBox)
// -------------------------------
// Bullish OB Creation
// -------------------------------
// Check if we should create a OB, Also check if we haven't created an OB in the
last 5 candles.
if ob_created_bull and cross_index - cross_index[1] > 5
float last_red = 0
float highest = 0
// Loop through the most recent candles and find the first RED (Bearish)
candle. We will place our OB here.
for i = 4 to 15 by 1
if close[i] < open[i]
last_red := i
break
// Draw our OB on that candle - then push the box into our box arrays.
drawlongBox := box.new(left=bar_index[last_red], top=high[last_red],
bottom=low[last_red], right=bar_index[last_red], bgcolor=col_bullish_ob,
border_color=col_bullish, extend=extend.right)
array.push(longBoxes, drawlongBox)
settings = "Settings"
zigzag_len = input.int(9, "ZigZag Length", group=settings)
show_zigzag = input.bool(true, "Show Zigzag", group=settings)
fib_factor = input.float(0.33, "Fib Factor for breakout confirmation", 0, 1, 0.01,
group=settings)
tf = switch time_frame
"5m" => "5"
"15m" => "15"
"30m" => "30"
"1h" => "60"
"2h" => "120"
"4h" => "240"
"D" => "D"
=> timeframe.period
f_get_high(ind) =>
[array.get(high_points_arr, array.size(high_points_arr) - 1 - ind),
array.get(high_index_arr, array.size(high_index_arr) - 1 - ind)]
f_get_low(ind) =>
[array.get(low_points_arr, array.size(low_points_arr) - 1 - ind),
array.get(low_index_arr, array.size(low_index_arr) - 1 - ind)]
f_main1() =>
to_up = high >= ta.highest(zigzag_len)
to_down = low <= ta.lowest(zigzag_len)
trend = 1
trend := nz(trend[1], 1)
trend := trend == 1 and to_down ? -1 : trend == -1 and to_up ? 1 : trend
last_trend_up_since = ta.barssince(to_up[1])
low_val = ta.lowest(nz(last_trend_up_since > 0 ? last_trend_up_since : 1, 1))
low_index = bar_index - ta.barssince(low_val == low)
last_trend_down_since = ta.barssince(to_down[1])
high_val = ta.highest(nz(last_trend_down_since > 0 ? last_trend_down_since : 1,
1))
high_index = bar_index - ta.barssince(high_val == high)
if ta.change(trend) != 0
if trend == 1
array.push(low_points_arr, low_val)
array.push(low_index_arr, low_index)
if trend == -1
array.push(high_points_arr, high_val)
array.push(high_index_arr, high_index)
market = 1
market := nz(market[1], 1)
last_l0 = ta.valuewhen(ta.change(market) != 0, l0, 0)
last_h0 = ta.valuewhen(ta.change(market) != 0, h0, 0)
market := last_l0 == l0 or last_h0 == h0 ? market : market == 1 and l0 < l1 and
l0 < l1 - math.abs(h0 - l1) * fib_factor ? -1 : market == -1 and h0 > h1 and h0 >
h1 + math.abs(h1 - l0) * fib_factor ? 1 : market
// For alert
alert_market = 1
alert_market := nz(alert_market[1], 1)
alert_market := last_l0 == l0 or last_h0 == h0 ? alert_market : alert_market ==
1 and trend == -1 and close < l0 and close < l0 - math.abs(h0 - l0) * fib_factor ?
-1 : alert_market == -1 and trend == 1 and close > h0 and close > h0 + math.abs(h0
- l0) * fib_factor ? 1 : alert_market
bu_ob_index = bar_index
bu_ob_index := nz(bu_ob_index[1], bar_index)
for i=h1i to l0i[zigzag_len]
index = bar_index - i
if open[index] > close[index]
bu_ob_index := bar_index[index]
be_ob_index = bar_index
be_ob_index := nz(be_ob_index[1], bar_index)
for i=l1i to h0i[zigzag_len]
index = bar_index - i
if open[index] < close[index]
be_ob_index := bar_index[index]
be_bb_index = bar_index
be_bb_index := nz(be_bb_index[1], bar_index)
for i=h1i - zigzag_len to l1i
index = bar_index - i
if open[index] > close[index]
be_bb_index := bar_index[index]
bu_bb_index = bar_index
bu_bb_index := nz(bu_bb_index[1], bar_index)
for i=l1i - zigzag_len to h1i
index = bar_index - i
if open[index] < close[index]
bu_bb_index := bar_index[index]
bu_ob_since_high = high[bu_ob_since]
bu_ob_since_low = low[bu_ob_since]
be_ob_since_high = high[be_ob_since]
be_ob_since_low = low[be_ob_since]
be_bb_since_high = high[be_bb_since]
be_bb_since_low = low[be_bb_since]
bu_bb_since_high = high[bu_bb_since]
bu_bb_since_low = low[bu_bb_since]
[trend, h0i, h0, l0i, l0, market, h1i, h1, l1i, l1, bu_ob_since_high,
bu_ob_since_low, be_ob_since_high, be_ob_since_low]
f_main2() =>
to_up = high >= ta.highest(zigzag_len)
to_down = low <= ta.lowest(zigzag_len)
trendms = 1
trendms := nz(trendms[1], 1)
trendms := trendms == 1 and to_down ? -1 : trendms == -1 and to_up ? 1 :
trendms
last_trendms_up_since = ta.barssince(to_up[1])
low_val = ta.lowest(nz(last_trendms_up_since > 0 ? last_trendms_up_since : 1,
1))
low_index = bar_index - ta.barssince(low_val == low)
last_trendms_down_since = ta.barssince(to_down[1])
high_val = ta.highest(nz(last_trendms_down_since > 0 ?
last_trendms_down_since : 1, 1))
high_index = bar_index - ta.barssince(high_val == high)
if ta.change(trendms) != 0
if trendms == 1
array.push(low_points_arr, low_val)
array.push(low_index_arr, low_index)
if trendms == -1
array.push(high_points_arr, high_val)
array.push(high_index_arr, high_index)
market = 1
market := nz(market[1], 1)
last_l0 = ta.valuewhen(ta.change(market) != 0, l0, 0)
last_h0 = ta.valuewhen(ta.change(market) != 0, h0, 0)
market := last_l0 == l0 or last_h0 == h0 ? market : market == 1 and l0 < l1 and
l0 < l1 - math.abs(h0 - l1) * fib_factor ? -1 : market == -1 and h0 > h1 and h0 >
h1 + math.abs(h1 - l0) * fib_factor ? 1 : market
// For alert
alert_market = 1
alert_market := nz(alert_market[1], 1)
alert_market := last_l0 == l0 or last_h0 == h0 ? alert_market : alert_market ==
1 and trendms == -1 and close < l0 and close < l0 - math.abs(h0 - l0) *
fib_factor ? -1 : alert_market == -1 and trendms == 1 and close > h0 and close > h0
+ math.abs(h0 - l0) * fib_factor ? 1 : alert_market
bu_ob_index = bar_index
bu_ob_index := nz(bu_ob_index[1], bar_index)
for i=h1i to l0i[zigzag_len]
index = bar_index - i
if open[index] > close[index]
bu_ob_index := bar_index[index]
be_ob_index = bar_index
be_ob_index := nz(be_ob_index[1], bar_index)
for i=l1i to h0i[zigzag_len]
index = bar_index - i
if open[index] < close[index]
be_ob_index := bar_index[index]
be_bb_index = bar_index
be_bb_index := nz(be_bb_index[1], bar_index)
for i=h1i - zigzag_len to l1i
index = bar_index - i
if open[index] > close[index]
be_bb_index := bar_index[index]
bu_bb_index = bar_index
bu_bb_index := nz(bu_bb_index[1], bar_index)
for i=l1i - zigzag_len to h1i
index = bar_index - i
if open[index] < close[index]
bu_bb_index := bar_index[index]
bu_ob_since_high = high[bu_ob_since]
bu_ob_since_low = low[bu_ob_since]
be_ob_since_high = high[be_ob_since]
be_ob_since_low = low[be_ob_since]
be_bb_since_high = high[be_bb_since]
be_bb_since_low = low[be_bb_since]
bu_bb_since_high = high[bu_bb_since]
bu_bb_since_low = low[bu_bb_since]
[trendms, h0i, h0, l0i, l0, market, h1i, h1, l1i, l1, bu_ob_since_high,
bu_ob_since_low, be_ob_since_high, be_ob_since_low] =
request.security(syminfo.tickerid, tf, f_main1())
[alert_market, be_bb_since_high, be_bb_since_low, bu_bb_since_high,
bu_bb_since_low, bu_ob_index, bu_bb_index, be_ob_index, be_bb_index] =
request.security(syminfo.tickerid, tf, f_main2())
if ta.change(alert_market) != 0
alert("MSB", alert.freq_once_per_bar)
//
//ADX Table
if barstate.islast
ADXformatStructure = '#.'
for i = 1 to i_decimal
ADXformatStructure += '0'
switch timeframe.period
"3" =>
BGColor3 := i_TriggerBGColor
TxtColor3 := i_TriggerTxtColor
"5" =>
BGColor5 := i_TriggerBGColor
TxtColor5 := i_TriggerTxtColor
"15" =>
BGColor15 := i_TriggerBGColor
TxtColor15 := i_TriggerTxtColor
recall(x) =>
ta.barssince(not na(x))
//---------------------apparence visuelle----------------------------------------
bull1 = line(na)
bull1 := new_bull1 and not new_bull2 and not new_bull3 and not new_bull4 and not
new_bull5 ? line.new(lox0, lo0, lox1, lo1, color=color.green) : na
bull2 = line(na)
bull2 := new_bull2 and not new_bull3 and not new_bull4 and not new_bull5 ?
line.new(lox0, lo0, lox2, lo2, color=color.green) : na
bull3 = line(na)
bull3 := new_bull3 and not new_bull4 and not new_bull5 ? line.new(lox0, lo0, lox3,
lo3, color=color.green) : na
bull4 = line(na)
bull4 := new_bull4 and not new_bull5 ? line.new(lox0, lo0, lox4, lo4,
color=color.green) : na
bull5 = line(na)
bull5 := new_bull5 ? line.new(lox0, lo0, lox5, lo5, color=color.green) : na
bear1 = line(na)
bear1 := new_bear1 and not new_bear2 and not new_bear3 and not new_bear4 and not
new_bear5 ? line.new(hix0, hi0, hix1, hi1, color=color.red) : na
bear2 = line(na)
bear2 := new_bear2 and not new_bear3 and not new_bear4 and not new_bear5 ?
line.new(hix0, hi0, hix2, hi2, color=color.red) : na
bear3 = line(na)
bear3 := new_bear3 and not new_bear4 and not new_bear5 ? line.new(hix0, hi0, hix3,
hi3, color=color.red) : na
bear4 = line(na)
bear4 := new_bear4 and not new_bear5 ? line.new(hix0, hi0, hix4, hi4,
color=color.red) : na
bear5 = line(na)
bear5 := new_bear5 ? line.new(hix0, hi0, hix5, hi5, color=color.red) : na
//.....................................................//
// Functions
-----------------------------------------------------------------------------------
//
//
-----------------------------------------------------------------------------------
----------- //
//
-----------------------------------------------------------------------------------
----------- //
// Volume Profile (Price by Volume) / Volume Histogram
------------------------------------------ //
if array.size(a_histogram) > 0
for i = 1 to array.size(a_histogram)
line.delete(array.shift(a_histogram))
if priceLevels
f_drawLabelX(bar_index + (profilePlacement == 'Right' ? profileWidth +
horizontalOffset : 0), priceHighest, str.tostring(priceHighest, format.mintick),
xloc.bar_index, yloc.price, color.new(upVolumeColor , 89), profilePlacement ==
'Left' and volumePlacement == 'Top' ? label.style_label_left :
label.style_label_down, upVolumeColor , size.normal, text.align_left, 'Profile
High - during last ' + str.tostring(lookbackLength) + ' bars\n %' +
str.tostring((priceHighest - priceLowest) / priceLowest * 100, '#.##') + ' higher
than the Profile Low')
f_drawLabelX(bar_index + (profilePlacement == 'Right' ? profileWidth +
horizontalOffset : 0), priceLowest , str.tostring(priceLowest , format.mintick),
xloc.bar_index, yloc.price, color.new(downVolumeColor, 89), profilePlacement ==
'Left' and volumePlacement == 'Bottom' ? label.style_label_left :
label.style_label_up , downVolumeColor, size.normal, text.align_left, 'Profile Low
- during last ' + str.tostring(lookbackLength) + ' bars\n %' +
str.tostring((priceHighest - priceLowest) / priceHighest * 100, '#.##') + ' lower
than the Profile High')
if volumeMA
array.push(a_histogram, line.new(bar_index[barIndex],
(volumePlacement == 'Top' ? priceHighest * (1 + priceChangeRate * .05) :
priceLowest * (1 - priceChangeRate * .05)) * (1 + (volumePlacement == 'Top' ? 1 :
-1) * nzVolume[barIndex] / volumeHighest * priceChangeRate / volumeHistHight /
volumeMARate[barIndex]), bar_index[barIndex + 1], (volumePlacement == 'Top' ?
priceHighest * (1 + priceChangeRate * .05) : priceLowest * (1 - priceChangeRate
* .05)) * (1 + (volumePlacement == 'Top' ? 1 : -1) * nzVolume[barIndex + 1] /
volumeHighest * priceChangeRate / volumeHistHight / volumeMARate[barIndex + 1]),
xloc.bar_index, extend.none, volumeMAColor, line.style_solid, 2))
if pointOfControl
array.push(a_profile, box.new(bar_index - lookbackLength + 1, priceLowest +
(array.indexof(volumeStorageT, array.max(volumeStorageT)) + .40) * priceStep,
bar_index + (profilePlacement == 'Right' ? profileWidth : 0), priceLowest +
(array.indexof(volumeStorageT, array.max(volumeStorageT)) + .60) * priceStep,
pocColor, bgcolor = pocColor ))
if priceLevels
f_drawLabelX(bar_index + (profilePlacement == 'Right' ?
horizontalOffset + 5 : 7), priceLowest + (array.indexof(volumeStorageT,
array.max(volumeStorageT)) + .5) * priceStep, str.tostring(priceLowest +
(array.indexof(volumeStorageT, array.max(volumeStorageT)) + .5) * priceStep,
format.mintick), xloc.bar_index, yloc.price, color.new(pocColor, 89),
(profilePlacement == 'Right' ? label.style_label_up : label.style_label_left),
color.new(pocColor, 0), size.normal, text.align_left, 'Point Of Control Price')
if profileDisplay == 'Up/Down'
startBoxIndex := profilePlacement == 'Right' ? bar_index + profileWidth
+ horizontalOffset - int(array.get(volumeStorageB, level) /
array.max(volumeStorageB) * (profileWidth - 9) / 2) : bar_index - lookbackLength +
1
endBoxIndex := profilePlacement == 'Right' ? bar_index + profileWidth
+ horizontalOffset: startBoxIndex + int( array.get(volumeStorageB, level) /
array.max(volumeStorageB) * (profileWidth - 9) / 2)
array.push(a_profile, box.new(startBoxIndex, priceLowest + (level +
0.1) * priceStep, endBoxIndex, priceLowest + (level + 0.9) * priceStep,
upVolumeColor, bgcolor = upVolumeColor ))
if bullBearStr
bullBearPower = 2 * array.get(volumeStorageB, level) -
array.get(volumeStorageT, level)
startBoxIndex := profilePlacement == 'Right' ? bar_index + profileWidth
+ 1 + horizontalOffset + (bullBearPower > 0 ? 1 : -1) * int(bullBearPower /
array.max(volumeStorageT) * (profileWidth - 9) * 1.75) : bar_index - lookbackLength
endBoxIndex := profilePlacement == 'Right' ? bar_index + profileWidth
+ 1 + horizontalOffset: startBoxIndex + (bullBearPower > 0 ? -1 : 1) *
int(bullBearPower / array.max(volumeStorageT) * (profileWidth - 9) * 1.75 )
array.push(a_profile, box.new(startBoxIndex, priceLowest + (level +
0.1) * priceStep, endBoxIndex, priceLowest + (level + 0.9) * priceStep,
bullBearPower > 0 ? bbStrUpColor : bbStrDownColor, bgcolor = bullBearPower > 0 ?
bbStrUpColor : bbStrDownColor ))
// === INPUTS
useDaily = input(true, title='Use Daily Data to Calculate HV (default), otherwise
chart TF')
LookBack = input.int(21, minval=1)
annual = input.int(252, minval=1)
DaystoExpire_ = input.int(defval=0, minval=0, title='Calender Days to Expiry
(0=Auto, default)')
src_ = input(close, title='Settlement Source (close=default)')
sLength_ = input.int(1, minval=1, title='Settlement Volume Weighted Average Length
(1=Use end of day)')
//
showset = input(title="Settlement", defval=true, group='Settlement')
stddev1 = input(true, title='Display 1x Standard Deviation Levels',
group='Settlement')
stddev2 = input(false, title='Display 2x Standard Deviation
Levels',group='Settlement')
stddev3 = input(false, title='Display 3x Standard Deviation
Levels',group='Settlement')
pivotNow = input(false, title='Display Only Todays Deviation
Levels',group='Settlement')
showstd1 = input(title="Dev1 Labels", defval=true, group='Settlement')
showstd2 = input(title="Dev2 Labels", defval=false,group='Settlement')
showstd3 = input(title="Dev3 Labels", defval=false, group='Settlement')
//
// === /INPUTs
dodgerblue = #1E90FF
//
// Test for new Daily Session or start of new month for Daily.
sLength = timeframe.isintraday ? sLength_ : 1
nstart = request.security(syminfo.tickerid, 'D', bar_index, barmerge.gaps_off,
barmerge.lookahead_on)
start21 = request.security(syminfo.tickerid, 'D', time, barmerge.gaps_off,
barmerge.lookahead_on)
first = request.security(syminfo.tickerid, 'D', ta.valuewhen(barstate.islast, time,
0), barmerge.gaps_off, barmerge.lookahead_on)
change_1 = ta.change(start21)
newDay = nohist ? false : timeframe.isintraday ? change_1 : dayofmonth(time) <
dayofmonth(time[1])
SettleM = plot(not nohist and showset and stddev1 and (not pivotNow or firstDay)
and not newDay ? settlement : na, color=color.new(#ec186d, 0), title='Settlement',
linewidth=2, style=plot.style_linebr)
stdhv05u = plot(not nohist and showset and stddev1 and (not pivotNow or firstDay)
and not newDay ? settlement + stdhv05 : na, color=color.new(color.orange, 20),
title='+0.5 SD', linewidth=1, style=plot.style_linebr)
stdhv05d = plot(not nohist and showset and stddev1 and (not pivotNow or firstDay)
and not newDay ? settlement - stdhv05 : na, color=color.new(color.orange, 20),
title='-0.5 SD', linewidth=1, style=plot.style_linebr)
stdhv07u = plot(not nohist and showset and stddev1 and (not pivotNow or firstDay)
and not newDay ? settlement + stdhv07 : na, color=color.new(color.red, 20),
title='+0.7 SD', linewidth=1, style=plot.style_linebr)
stdhv07d = plot(not nohist and showset and stddev1 and (not pivotNow or firstDay)
and not newDay ? settlement - stdhv07 : na, color=color.new(color.red, 20),
title='-0.7 SD', linewidth=1, style=plot.style_linebr)
stdhv1u = plot(not nohist and showset and stddev1 and (not pivotNow or firstDay)
and not newDay ? settlement + stdhv1 : na, color=color.new(color.lime, 20),
title='+1 SD', linewidth=3, style=plot.style_linebr)
stdhv1d = plot(not nohist and showset and stddev1 and (not pivotNow or firstDay)
and not newDay ? settlement - stdhv1 : na, color=color.new(color.lime, 20),
title='-1 SD', linewidth=3, style=plot.style_linebr)
stdhv15u = plot(not nohist and showset and stddev2 and (not pivotNow or firstDay)
and not newDay ? settlement + stdhv15 : na, color=color.new(color.green, 20),
title='+1.5 SD', linewidth=1, style=plot.style_linebr)
stdhv15d = plot(not nohist and showset and stddev2 and (not pivotNow or firstDay)
and not newDay ? settlement - stdhv15 : na, color=color.new(color.green, 20),
title='-1.5 SD', linewidth=1, style=plot.style_linebr)
stdhv2u = plot(not nohist and showset and stddev2 and (not pivotNow or firstDay)
and not newDay ? settlement + stdhv2 : na, color=color.new(color.blue, 20),
title='+2 SD', linewidth=3, style=plot.style_linebr)
stdhv2d = plot(not nohist and showset and stddev2 and (not pivotNow or firstDay)
and not newDay ? settlement - stdhv2 : na, color=color.new(color.blue, 20),
title='-2 SD', linewidth=3, style=plot.style_linebr)
stdhv25u = plot(not nohist and showset and stddev3 and (not pivotNow or firstDay)
and not newDay ? settlement + stdhv25 : na, color=color.new(color.aqua, 20),
title='+2.5 SD', linewidth=1, style=plot.style_linebr)
stdhv25d = plot(not nohist and showset and stddev3 and (not pivotNow or firstDay)
and not newDay ? settlement - stdhv25 : na, color=color.new(color.aqua, 20),
title='-2.5 SD', linewidth=1, style=plot.style_linebr)
//Show Settlement
if showset
if stddev1
if settlement
settlement = label.new(start21, settlement, text='Settlement',
xloc=xloc.bar_time, textcolor=color.new(#ec186d,0), style=label.style_none)
label.delete(settlement[1])
if Stdhv05u
Stdhv05u = label.new(start21, Stdhv05u, text='+0.5',
xloc=xloc.bar_time, textcolor=color.new(color.orange,0), style=label.style_none)
label.delete(Stdhv05u[1])
if Stdhv05d
Stdhv05d = label.new(start21, Stdhv05d, text='-0.5',
xloc=xloc.bar_time, textcolor=color.new(color.orange,0), style=label.style_none)
label.delete(Stdhv05d[1])
if Stdhv07u
Stdhv07u = label.new(start21, Stdhv07u, text='+0.7',
xloc=xloc.bar_time, textcolor=color.new(color.red,0), style=label.style_none)
label.delete(Stdhv07u[1])
if Stdhv07d
Stdhv07d = label.new(start21, Stdhv07d, text='-0.7',
xloc=xloc.bar_time, textcolor=color.new(color.red,0), style=label.style_none)
label.delete(Stdhv07d[1])
if Stdhv1u
Stdhv1u = label.new(start21, Stdhv1u, text='+1.0', xloc=xloc.bar_time,
textcolor=color.new(color.lime,10), style=label.style_none)
label.delete(Stdhv1u[1])
if Stdhv1d
Stdhv1d = label.new(start21, Stdhv1d, text='-1.0', xloc=xloc.bar_time,
textcolor=color.new(color.lime,10), style=label.style_none)
label.delete(Stdhv1d[1])
if showstd2
if Stdhv15u
Stdhv15u = label.new(start21, Stdhv15u, text='+1.5',
xloc=xloc.bar_time, textcolor=color.new(color.green,10), style=label.style_none)
label.delete(Stdhv15u[1])
if Stdhv15d
Stdhv15d = label.new(start21, Stdhv15d, text='-1.5',
xloc=xloc.bar_time, textcolor=color.new(color.green,10), style=label.style_none)
label.delete(Stdhv15d[1])
if Stdhv2u
Stdhv2u = label.new(start21, Stdhv2u, text='+2.0', xloc=xloc.bar_time,
textcolor=color.new(color.blue,10), style=label.style_none)
label.delete(Stdhv2u[1])
if Stdhv2d
Stdhv2d = label.new(start21, Stdhv2d, text='-2.0', xloc=xloc.bar_time,
textcolor=color.new(color.blue,10), style=label.style_none)
label.delete(Stdhv2d[1])
if showstd3
if Stdhv25u
Stdhv25u = label.new(start21, Stdhv25u, text='+2.5',
xloc=xloc.bar_time, textcolor=color.new(color.aqua,10), style=label.style_none)
label.delete(Stdhv25u[1])
if Stdhv25d
Stdhv25d = label.new(start21, Stdhv25d, text='-2.5',
xloc=xloc.bar_time, textcolor=color.new(color.aqua,10), style=label.style_none)
label.delete(Stdhv25d[1])
//
//Offset MA