//Merged By [Link]
top
//@version=5
indicator("2024 ALGO ", overlay=true, max_labels_count=500, max_boxes_count=500,
max_lines_count=500, max_bars_back=5000, overlay = true)
textDate = timestamp(2023, 01, 01)
var int textBarIndex = na
if time[1] < textDate and time >= textDate
textBarIndex := bar_index
import PineCoders/Time/3
//INPUTS
var GRP1 = "== Midnight Hunter Band Setting =="
HalfLength = [Link](56, "Centered TMA Half Period", group = GRP1)
string PriceType = [Link]("Weighted", "Price to use", options = ["Close",
"Open", "High", "Low", "Median", "Typical", "Weighted", "Average"], group = GRP1)
AtrPeriod = [Link](110, "Average true range period", group = GRP1)
AtrMultiplier = [Link](2.5, "Average true range multiplier", group = GRP1)
TMAangle = [Link](4, "Centered TMA angle caution", group = GRP1)
tmawidth = [Link](defval = 1, title = 'Band LineWidth', minval = 1, maxval = 4,
group = GRP1)
//Gold Hunter Setting : 56 , 110 , 2.5 , 4
//VARIABLES
float tmac = na
float tmau = na
float tmad = na
var float pastTmac = na //from the previous candle
var float pastTmau = na
var float pastTmad = na
float tmau_temp = na //before looping
float tmac_temp = na
float tmad_temp = na
float point = [Link] //NEEDS MORE TESTS
bool last = false //checks if a loop is needed
bool longalert = false
bool shortalert = false
string timeframe = na
if [Link] and [Link] >= 60 and [Link] <
1440
timeframe := [Link]([Link] / 60) + " H"
else if [Link] and [Link] < 60
timeframe := [Link]([Link]) + " M"
else if [Link] and [Link] >= 1440
timeframe := [Link]([Link]) + " D"
else
timeframe := [Link]
i_timeZone = [Link](defval = 'GMT+7', title = "TimeZone Text Alert")//TH
Time
current_time = [Link](hour(timenow, i_timeZone), '00:') +
[Link](minute(timenow, i_timeZone), '00:') + [Link](second(timenow,
i_timeZone), '00')
showTF1 = [Link](defval=true, title="📑>> Show Table Status Eg. Trend and
Indicator Value", group = " >> Table For Analyze Trend")
var float limit_price = na
var string alertSignal = "EMPTY" //needed for alarms to avoid repetition
//COLORS
var GRP2 = "== Midnight Colors =="
var color colorBuffer = na
color colorDOWN = [Link]([Link]([Link], 0), "Bear Color", inline = "5",
group = GRP1)
color colorUP = [Link]([Link]([Link], 0), "Bull Color", inline = "5",
group = GRP1)
color colorBands = [Link](#ffffff, "3 Bands Color", inline = "5", group =
GRP1)
bool cautionInput = [Link](false, "Caution Label", inline = "6", group = GRP1)
//ALERTS
var GRP3 = "Alerts (Needs to create alert manually after every change)"
bool crossUpInput = [Link](false, "Crossing up", inline = "7", group = GRP3)
bool crossDownInput = [Link](false, "Crossing down", inline = "7", group =
GRP3)
bool comingBackInput = [Link](false, "Coming back", inline = "7", group = GRP3)
bool onArrowDownInput = [Link](true, "On arrow down", inline = "8", group =
GRP3)
bool onArrowUpInput = [Link](true, "On arrow up", inline = "8", group = GRP3)
//CLEAR LINES
a_allLines = [Link]
if [Link](a_allLines) > 0
for p = 0 to [Link](a_allLines) - 1
[Link]([Link](a_allLines, p))
//GET PRICE
Price(x) =>
float price = switch PriceType
"Close" => close[x]
"Open" => open[x]
"High" => high[x]
"Low" => low[x]
"Median" => (high[x] + low[x]) / 2
"Typical" => (high[x] + low[x] + close[x]) / 3
"Weighted" => (high[x] + low[x] + close[x] + close[x]) / 4
"Average" => (high[x] + low[x] + close[x] + open[x])/ 4
price
//MAIN
for i = HalfLength to 0
//ATR
atr = 0.0
for j = 0 to AtrPeriod - 1
atr += [Link](high[i + j + 10], close[i + j + 11]) - [Link](low[i + j +
10], close[i + j + 11])
atr /= AtrPeriod
//BANDS
sum = (HalfLength + 1) * Price(i)
sumw = (HalfLength + 1)
k = HalfLength
for j = 1 to HalfLength
sum += k * Price(i + j)
sumw += k
if (j <= i)
sum += k * Price(i - j)
sumw += k
k -= 1
tmac := sum/sumw
tmau := tmac+AtrMultiplier*atr
tmad := tmac-AtrMultiplier*atr
//ALERTS
if i == 0 //Only on a real candle
if (high > tmau and alertSignal != "UP") //crossing up band
if crossUpInput == true //checks if activated
alert("Crossing up Band", alert.freq_once_per_bar_close) //calling
alert
alertSignal := "UP" //to avoid repeating
else if (low < tmad and alertSignal != "DOWN") //crossing down band
if crossDownInput == true
alert("Crossing down Band", alert.freq_once_per_bar_close)
alertSignal := "DOWN"
else if (alertSignal == "DOWN" and high >= tmad and alertSignal != "EMPTY")
//back from the down band
if comingBackInput == true
alert("Coming back", alert.freq_once_per_bar_close)
alertSignal := "EMPTY"
else if (alertSignal == "UP" and low <= tmau and alertSignal !=
"EMPTY") //back from the up band
if comingBackInput == true
alert("Coming back", alert.freq_once_per_bar_close)
alertSignal := "EMPTY"
//CHANGE TREND COLOR
if pastTmac != 0.0
if tmac > pastTmac
colorBuffer := colorUP
if tmac < pastTmac
colorBuffer := colorDOWN
//SIGNALS
reboundD = 0.0
reboundU = 0.0
caution = 0.0
if pastTmac != 0.0
if (high[i + 1] > pastTmau and close[i + 1] > open[i + 1] and close[i] <
open[i])
reboundD := high[i] + AtrMultiplier * atr / 2
if (tmac - pastTmac > TMAangle * point)
caution := reboundD + 10 * point
if (low[i + 1] < pastTmad and close[i + 1] < open[i + 1] and close[i] >
open[i])
reboundU := low[i] - AtrMultiplier * atr / 2
if (pastTmac - tmac > TMAangle * point)
caution := reboundU - 10 * point
//LAST REAL
if [Link] and i == HalfLength
last := true
tmau_temp := tmau
tmac_temp := tmac
tmad_temp := tmad
//DRAW HANDICAPPED BANDS
if [Link] and i < HalfLength
[Link](bar_index - (i + 1), pastTmau, bar_index - (i), tmau, width = 2,
style = line.style_dotted, color = colorBands, force_overlay = true)
[Link](bar_index - (i + 1), pastTmad, bar_index - (i), tmad, width = 2,
style = line.style_dotted, color = colorBands, force_overlay = true)
//DRAW SIGNALS
if reboundD != 0
//[Link](bar_index - (i), reboundD, color = colorDOWN, style =
label.style_triangledown, size = [Link], textcolor = na)
[Link](bar_index - (i), reboundD, '▼', color = na, textcolor =
colorDOWN, textalign= text.align_center, force_overlay = true)
if i == 0 and onArrowDownInput == true //alert
longalert := true
limit_price := close
alert("↘️ Midnight Hunter : Sell Alert ↘️\n🪙 Asset : " + [Link]
+ "\n🕛 TimeFrame : " + [Link](timeframe) + "\n💹 Sell Price : " +
[Link](limit_price) + " $\n\n⏰ Signal Time : " + [Link](current_time),
alert.freq_once_per_bar_close)
if caution != 0 and cautionInput == true
[Link](bar_index - (i), reboundD, color = colorUP, style =
label.style_xcross, size = [Link], textcolor = na, force_overlay = true)
if reboundU != 0
//[Link](bar_index - (i), reboundU, color = colorUP, style =
label.style_triangleup, size = [Link], textcolor = na)
[Link](bar_index - (i), reboundU, '▲', color = na, textcolor = colorUP,
textalign = text.align_center, force_overlay = true)
if i == 0 and onArrowUpInput == true //alert
shortalert := true
limit_price := close
alert("↗️ Midnight Hunter : Buy Alert ↗️\n🪙 Asset : " + [Link] +
"\n🕛 TimeFrame : " + [Link](timeframe) + "\n💹 Buy Price : " +
[Link](limit_price) + " $\n\n⏰ Signal Time : " + [Link](current_time),
alert.freq_once_per_bar_close)
if caution != 0 and cautionInput == true
[Link](bar_index - (i), reboundU, color = colorDOWN, style =
label.style_xcross, size = [Link], textcolor = na, force_overlay = true)
//SAVE HISTORY
pastTmac := tmac
pastTmau := tmau
pastTmad := tmad
//LOOP IS ONLY FOR HANDICAPPED
if [Link] != true
break
//DRAW REAL BANDS
plot(last ? tmau_temp : tmau, title = "TMA Up", color = colorBands,
linewidth=tmawidth, style = plot.style_line, offset = -HalfLength, force_overlay =
true)
plot(last ? tmad_temp : tmad, title = "TMA Down", color = colorBands,
linewidth=tmawidth, style = plot.style_line, offset = -HalfLength, force_overlay =
true)
///////////////////// RSI BB Divergence
/////"RSI Divergence Indicator with Bollinger Bands"
// Input parameters for RSI
len = [Link](title="RSI Period", minval=1, defval=14)
src = input(title="RSI Source", defval=close)
// Input parameters for Bollinger Bands
bbLength = [Link](title="Bollinger Bands Length", minval=1, defval=20)
bbStdDev = [Link](title="Bollinger Bands Std Dev", minval=0.1, defval=2.0)
// Lookback periods for pivots
lbR = input(title="Pivot Lookback Right", defval=5, display=display.data_window)
lbL = input(title="Pivot Lookback Left", defval=5, display=display.data_window)
// Range limits
rangeUpper = input(title="Max of Lookback Range", defval=60,
display=display.data_window)
rangeLower = input(title="Min of Lookback Range", defval=5,
display=display.data_window)
// Plotting options for divergence signals
plotBull = input(title="Plot Bullish", defval=true)//, display=display.data_window)
plotHiddenBull = input(title="Plot Hidden Bullish", defval=false)//,
display=display.data_window)
plotBear = input(title="Plot Bearish", defval=true)//, display=display.data_window)
plotHiddenBear = input(title="Plot Hidden Bearish", defval=false)//,
display=display.data_window)
// Colors for signals
bearColor = [Link]
bullColor = [Link]
hiddenBullColor = [Link]([Link], 80)
hiddenBearColor = [Link]([Link], 80)
textColor = [Link]
noneColor = [Link]([Link], 100)
// Compute RSI
osc = [Link](src, len)
// Calculate Bollinger Bands based on RSI values
basis = [Link](osc, bbLength) // Middle band for RSI
dev = bbStdDev * [Link](osc, bbLength) // Standard deviation of RSI
upperBand = basis + dev // Upper Bollinger Band
lowerBand = basis - dev // Lower Bollinger Band
// Plot RSI
//plot(osc, title="RSI", linewidth=2, color=#2962FF)
//hline(50, title="Middle Line", color=#787B86, linestyle=hline.style_dotted)
//obLevel = hline(70, title="Overbought", color=#787B86,
linestyle=hline.style_dotted)
//osLevel = hline(30, title="Oversold", color=#787B86,
linestyle=hline.style_dotted)
//fill(obLevel, osLevel, title="Background", color=[Link](33, 150, 243, 90))
// Plot Bollinger Bands
//plot(upperBand, title="Upper Band (RSI)", color=[Link], linewidth=1)
//plot(lowerBand, title="Lower Band (RSI)", color=[Link], linewidth=1)
//plot(basis, title="Middle Band (SMA of RSI)", color=[Link], linewidth=1)
//fill(plot(upperBand), plot(lowerBand), color=[Link](173, 216, 230, 90),
title="BB Fill")
plFound = na([Link](osc, lbL, lbR)) ? false : true
phFound = na([Link](osc, lbL, lbR)) ? false : true
_inRange(cond) =>
bars = [Link](cond == true)
rangeLower <= bars and bars <= rangeUpper
// Regular Bullish Divergence
oscHL = osc[lbR] > [Link](plFound, osc[lbR], 1) and _inRange(plFound[1])
priceLL = low[lbR] < [Link](plFound, low[lbR], 1)
bullCondAlert = priceLL and oscHL and plFound
bullCond = plotBull and bullCondAlert
//plot(plFound ? osc[lbR] : na, offset=-lbR, title="Regular Bullish", linewidth=2,
color=(bullCond ? bullColor : noneColor), display=[Link])
plotshape(bullCond ? osc[lbR] : na, offset=-lbR, title="Regular Bullish Label",
text=" Bull ", style=[Link], location=[Link], color=bullColor,
textcolor=textColor, force_overlay = true)
// Hidden Bullish Divergence
oscLL = osc[lbR] < [Link](plFound, osc[lbR], 1) and _inRange(plFound[1])
priceHL = low[lbR] > [Link](plFound, low[lbR], 1)
hiddenBullCondAlert = priceHL and oscLL and plFound
hiddenBullCond = plotHiddenBull and hiddenBullCondAlert
//plot(plFound ? osc[lbR] : na, offset=-lbR, title="Hidden Bullish", linewidth=2,
color=(hiddenBullCond ? hiddenBullColor : noneColor), display=[Link])
plotshape(hiddenBullCond ? osc[lbR] : na, offset=-lbR, title="Hidden Bullish
Label", text=" H Bull ", style=[Link], location=[Link],
color=bullColor, textcolor=textColor, force_overlay = true)
// Regular Bearish Divergence
oscLH = osc[lbR] < [Link](phFound, osc[lbR], 1) and _inRange(phFound[1])
priceHH = high[lbR] > [Link](phFound, high[lbR], 1)
bearCondAlert = priceHH and oscLH and phFound
bearCond = plotBear and bearCondAlert
//plot(phFound ? osc[lbR] : na, offset=-lbR, title="Regular Bearish", linewidth=2,
color=(bearCond ? bearColor : noneColor), display=[Link])
// add in
plotshape(bearCond ? osc[lbR] : na, offset=-lbR, title="Regular Bearish Label",
text=" Sell ", style=[Link], location=[Link], color=bearColor,
textcolor=textColor, force_overlay = true)
// Hidden Bearish Divergence
oscHH = osc[lbR] < [Link](plFound, osc[lbR], 1) and _inRange(plFound[1])
priceLH = low[lbR] > [Link](plFound, low[lbR], 1)
hiddenBearCondAlert = priceHL and oscLL and plFound
hiddenBearCond = plotHiddenBear and hiddenBearCondAlert
//plot(plFound ? osc[lbR] : na, offset=-lbR, title="Hidden Bearish", linewidth=2,
color=(hiddenBearCond ? hiddenBearColor : noneColor), display=[Link])
plotshape(hiddenBearCond ? osc[lbR] : na, offset=-lbR, title="Hidden Bearish
Label", text=" H Bear ", style=[Link], location=[Link],
color=bearColor, textcolor=textColor, force_overlay = true)
plotshape([Link](osc, lowerBand), title = "Book Short Profit", text = "Book
Profit", style=[Link], location=[Link], color=bearColor,
textcolor=textColor, force_overlay = true )
plotshape([Link](osc, upperBand), title = "Book Long Profit", text = "Book
Profit", style=[Link], location=[Link], color=bullColor,
textcolor=textColor, force_overlay = true )
// OB code is here
// INDICATOR SETTINGS
swing_length = [Link](8, title='Swing High/Low Length', group='Settings',
minval=1, maxval=50)
history_of_demand_to_keep = [Link](20, title='History To Keep', minval=5,
maxval=50)
box_width = [Link](9, title='Supply/Demand Box Width', group='Settings',
minval=1, maxval=10)
// INDICATOR VISUAL SETTINGS
show_price_action_labels = [Link](true, title='Show Price Action Labels',
group='Visual Settings', inline='2')
supply_color = [Link]([Link](#a52323, 65), title='Supply Zone',
group='Visual Settings', inline='3')
supply_outline_color = [Link]([Link]([Link], 75), title='Outline',
group='Visual Settings', inline='3')
demand_color = [Link]([Link](#0cda40, 21), title='Demand Zone',
group='Visual Settings', inline='4')
demand_outline_color = [Link]([Link]([Link], 75), title='Outline',
group='Visual Settings', inline='4')
bos_label_color = [Link]([Link](15, 14, 14, 3), title='BOS', group='Visual
Settings', inline='10')
poi_label_color = [Link]([Link](19, 18, 18, 7), title='POI', group='Visual
Settings', inline='10')
swing_type_color = [Link]([Link], title='Price Action Label',
group='Visual Settings', inline='10')
zigzag_color = [Link]([Link](#000000, 0), title='Zig Zag', group='Visual
Settings', inline='10')
// END SETTINGS
// FUNCTIONS Starts from here
// FUNCTION TO ADD NEW AND REMOVE LAST IN ARRAY
f_array_add_pop(array, new_value_to_add) =>
[Link](array, new_value_to_add)
[Link](array)
// FUNCTION SWING H & L LABELS
f_sh_sl_labels(array, swing_type) =>
var string label_text = na
if swing_type == 1
if [Link](array, 0) >= [Link](array, 1)
label_text := 'HH'
else
label_text := 'LH'
[Link](bar_index - swing_length, [Link](array, 0), text=label_text,
style=label.style_label_down, textcolor=[Link],
color=[Link](swing_type_color, 100))
else if swing_type == -1
if [Link](array, 0) >= [Link](array, 1)
label_text := 'HL'
else
label_text := 'LL'
[Link](bar_index - swing_length, [Link](array, 0), text=label_text,
style=label.style_label_up, textcolor=[Link],
color=[Link](swing_type_color, 100))
// FUNCTION MAKE SURE SUPPLY ISN'T OVERLAPPING
f_check_overlapping(new_poi, box_array, atr) =>
atr_threshold = atr * 2
okay_to_draw = true
for i = 0 to [Link](box_array) - 1
top = box.get_top([Link](box_array, i))
bottom = box.get_bottom([Link](box_array, i))
poi = (top + bottom) / 2
upper_boundary = poi + atr_threshold
lower_boundary = poi - atr_threshold
if new_poi >= lower_boundary and new_poi <= upper_boundary
okay_to_draw := false
break
else
okay_to_draw := true
okay_to_draw
// FUNCTION TO DRAW SUPPLY OR DEMAND ZONE
f_supply_demand(value_array, bn_array, box_array, label_array, box_type, atr) =>
atr_buffer = atr * (box_width / 10)
box_left = [Link](bn_array, 0)
box_right = bar_index
var float box_top = 0.00
var float box_bottom = 0.00
var float poi = 0.00
if box_type == 1
box_top := [Link](value_array, 0)
box_bottom := box_top - atr_buffer
poi := (box_top + box_bottom) / 2
else if box_type == -1
box_bottom := [Link](value_array, 0)
box_top := box_bottom + atr_buffer
poi := (box_top + box_bottom) / 2
okay_to_draw = f_check_overlapping(poi, box_array, atr)
// delete oldest box, and then create a new box and add it to the array
if box_type == 1 and okay_to_draw
[Link]([Link](box_array, [Link](box_array) - 1))
f_array_add_pop(box_array, [Link](left=box_left, top=box_top,
right=box_right, bottom=box_bottom,
border_color=supply_outline_color,bgcolor=supply_color, extend=[Link],
text='S u p p l y Z o n e', text_halign=text.align_center,
text_valign=text.align_center, text_color=[Link], text_size=[Link],
xloc=xloc.bar_index))
[Link]([Link](label_array, [Link](label_array) - 1))
f_array_add_pop(label_array, [Link](left=box_left, top=poi,
right=box_right, bottom=poi, border_color=[Link](#0f0f0f,
79),bgcolor=[Link](poi_label_color, 90), extend=[Link], text='Resistance',
text_halign=text.align_center, text_valign=text.align_bottom,
text_color=[Link], text_size=[Link], xloc=xloc.bar_index))
else if box_type == -1 and okay_to_draw
[Link]([Link](box_array, [Link](box_array) - 1))
f_array_add_pop(box_array, [Link](left=box_left, top=box_top,
right=box_right, bottom=box_bottom, border_color=demand_outline_color,
bgcolor=demand_color, extend=[Link], text='D e m a n d Z o n e',
text_halign=text.align_center, text_valign=text.align_top, text_color=[Link],
text_size=[Link], xloc=xloc.bar_index))
[Link]([Link](label_array, [Link](label_array) - 1))
f_array_add_pop(label_array, [Link](left=box_left, top=poi,
right=box_right, bottom=poi, border_color=[Link](#0f0f0f, 79),
bgcolor=[Link](poi_label_color, 90), extend=[Link], text='Support',
text_halign=text.align_left, text_valign=text.align_top, text_color=[Link],
text_size=[Link], xloc=xloc.bar_index))
// FUNCTION TO CHANGE SUPPLY/DEMAND TO A BOS IF BROKEN
f_sd_to_bos(box_array, bos_array, label_array, zone_type) =>
if zone_type == 1
for i = 0 to [Link](box_array) - 1
level_to_break = box.get_top([Link](box_array, i))
if close >= level_to_break
copied_box = [Link]([Link](box_array, i))
f_array_add_pop(bos_array, copied_box)
mid = (box.get_top([Link](box_array, i)) +
box.get_bottom([Link](box_array, i))) / 2
box.set_top([Link](bos_array, 0), mid)
box.set_bottom([Link](bos_array, 0), mid)
box.set_extend([Link](bos_array, 0), [Link])
box.set_right([Link](bos_array, 0), bar_index)
// Update the box text with date and time
formatted_datetime = [Link](dayofmonth) + "-" +
[Link](month) + "-" + [Link](year) + " " + [Link](hour) + ":" +
[Link](minute) + ":" + [Link](second)
box.set_text([Link](bos_array, 0), 'Supply-Zone Br\n' +
formatted_datetime)
box.set_text_color([Link](bos_array, 0), [Link])
box.set_text_size([Link](bos_array, 0), [Link])
[Link]([Link](box_array, i))
[Link]([Link](label_array, i))
if zone_type == -1
for i = 0 to [Link](box_array) - 1
level_to_break = box.get_bottom([Link](box_array, i))
if close <= level_to_break
copied_box = [Link]([Link](box_array, i))
f_array_add_pop(bos_array, copied_box)
mid = (box.get_top([Link](box_array, i)) +
box.get_bottom([Link](box_array, i))) / 2
box.set_top([Link](bos_array, 0), mid)
box.set_bottom([Link](bos_array, 0), mid)
box.set_extend([Link](bos_array, 0), [Link])
box.set_right([Link](bos_array, 0), bar_index)
// Update the box text with date and time
formatted_datetime = [Link](year) + "-" + [Link](month)
+ "-" + [Link](dayofmonth) + " " + [Link](hour) + ":" +
[Link](minute) + ":" + [Link](second)
box.set_text([Link](bos_array, 0), 'Demand-Zone Brn\n' +
formatted_datetime)
box.set_text_color([Link](bos_array, 0), [Link])
box.set_text_size([Link](bos_array, 0), [Link])
box.set_text_halign([Link](bos_array, 0), text.align_center)
box.set_text_valign([Link](bos_array, 0), text.align_center)
[Link]([Link](box_array, i))
[Link]([Link](label_array, i))
// FUNCTION MANAGE CURRENT BOXES BY CHANGING ENDPOINT
f_extend_box_endpoint(box_array) =>
for i = 0 to [Link](box_array) - 1
box.set_right([Link](box_array, i), bar_index + 100)
// OB code ends here
// swing high aand Low calculation
// CALCULATE ATR
atr = [Link](50)
// CALCULATE SWING HIGHS & SWING LOWS
swing_high = [Link](high, swing_length, swing_length)
swing_low = [Link](low, swing_length, swing_length)
// ARRAYS FOR SWING H/L & BN
var swing_high_values = array.new_float(5, 0.00)
var swing_low_values = array.new_float(5, 0.00)
var swing_high_bns = array.new_int(5, 0)
var swing_low_bns = array.new_int(5, 0)
// ARRAYS FOR SUPPLY / DEMAND
var current_supply_box = array.new_box(history_of_demand_to_keep, na)
var current_demand_box = array.new_box(history_of_demand_to_keep, na)
// ARRAYS FOR SUPPLY / DEMAND POI LABELS
var current_supply_poi = array.new_box(history_of_demand_to_keep, na)
var current_demand_poi = array.new_box(history_of_demand_to_keep, na)
// ARRAYS FOR BOS
var supply_bos = array.new_box(5, na)
var demand_bos = array.new_box(5, na)
// END CALCULATIONS
// NEW SWING HIGH
if not na(swing_high)
// MANAGE SWING HIGH VALUES
f_array_add_pop(swing_high_values, swing_high)
f_array_add_pop(swing_high_bns, bar_index[swing_length])
if show_price_action_labels
f_sh_sl_labels(swing_high_values, 1)
f_supply_demand(swing_high_values, swing_high_bns, current_supply_box,
current_supply_poi, 1, atr)
// NEW SWING LOW
else if not na(swing_low)
// MANAGE SWING LOW VALUES
f_array_add_pop(swing_low_values, swing_low)
f_array_add_pop(swing_low_bns, bar_index[swing_length])
if show_price_action_labels
f_sh_sl_labels(swing_low_values, -1)
f_supply_demand(swing_low_values, swing_low_bns, current_demand_box,
current_demand_poi, -1, atr)
f_sd_to_bos(current_supply_box, supply_bos, current_supply_poi, 1)
f_sd_to_bos(current_demand_box, demand_bos, current_demand_poi, -1)
f_extend_box_endpoint(current_supply_box)
f_extend_box_endpoint(current_demand_box)
// Indicator logic for Black Candle and other features
// ...
//indicator("Black CANDLE")
var bool highClose = false
var bool lowClose = false
var bool bullishPinBar = false
var bool bearishPinBar = false
var bool ectopicPinBar = false
var bool Redcandle = false
var bool Greencandle = false
var bool ectopicBar = false
useCustomTimeframeInput = [Link](false, "Use custom timeframe")
lowerTimeframeInput = [Link]("[Link](chartTimeframe)",
"Volume Timeframe")
closeRange = [Link](0.35, title="Close Range", minval=0.05, maxval=0.75,
step=0.05)
barRange = (open - close)
if barRange < 0
Redcandle := true
else
Greencandle := true
// Find Ectopic candle
upAndDownVolume() =>
posVol = 0.0
negVol = 0.0
switch
close > open => posVol += volume
close < open => negVol -= volume
close >= close[1] => posVol += volume
close < close[1] => negVol -= volume
[posVol, negVol]
lowerTimeframe = switch
useCustomTimeframeInput => lowerTimeframeInput
[Link] => "1"
[Link] => "5"
=> "60"
[upVolumeArray, downVolumeArray] = request.security_lower_tf([Link],
lowerTimeframe, upAndDownVolume())
upVolume = [Link](upVolumeArray)
downVolume = [Link](downVolumeArray)
delta = upVolume + downVolume
ectopicBar := (Redcandle and ([Link](upVolume * 1.5) < [Link](downVolume))) or
(Greencandle and ([Link](downVolume * 1.5) < [Link](upVolume)))
ectopicBarColor = ectopicBar ? [Link](0, 0, 0) : na
barcolor(ectopicBarColor, title="BLACK Candle")
// Reset the variables
highClose := false
lowClose := false
bullishPinBar := false
bearishPinBar := false
ectopicPinBar := false
ectopicBar := false
Redcandle := false
Greencandle := false
// Market Structure Break
settings = "Settings"
zigzag_len = [Link](9, "Zig Zag Length", group=settings)
show_zigzag = [Link](true, "Show Zig Zag", group=settings)
fib_factor = [Link](0.33, "Fib Factor for breakout confirmation", 0, 1, 0.01,
group=settings)
text_size = [Link]([Link], "Text Size", [[Link], [Link],
[Link], [Link], [Link]], group=settings)
delete_boxes = [Link](true, "Delete Old/Broken Boxes", group=settings)
bu_ob_inline_color = "Bu-OB Colors"
be_ob_inline_color = "Be-OB Colors"
bu_bb_inline_color = "Bu-BB Colors"
be_bb_inline_color = "Be-BB Colors"
// Bu-OB Display Settings
bu_ob_display_settings = "Bu-OB Display Settings"
bu_ob_color = [Link](#ffffff00, "Color", group=bu_ob_display_settings,
inline=bu_ob_inline_color)
bu_ob_border_color = [Link](#ffffff00, "Border Color",
group=bu_ob_display_settings, inline=bu_ob_inline_color)
bu_ob_text_color = [Link](#ffffff00, "Text Color",
group=bu_ob_display_settings, inline=bu_ob_inline_color)
// Be-OB Display Settings
be_ob_display_settings = "Be-OB Display Settings"
be_ob_color = [Link](#ffffff00, "Color", group=be_ob_display_settings,
inline=be_ob_inline_color)
be_ob_border_color = [Link](#ffffff00, "Border Color",
group=be_ob_display_settings, inline=be_ob_inline_color)
be_ob_text_color = [Link](#ffffff00, "Text Color",
group=be_ob_display_settings, inline=be_ob_inline_color)
// Bu-BB & Bu-MB Display Settings
bu_bb_display_settings = "Bu-BB & Bu-MB Display Settings"
bu_bb_color = [Link](#ffffff00, "Color", group=bu_bb_display_settings,
inline=bu_bb_inline_color)
bu_bb_border_color = [Link](#ffffff00, "Border Color",
group=bu_bb_display_settings, inline=bu_bb_inline_color)
bu_bb_text_color = [Link](#ffffff00, "Text Color",
group=bu_bb_display_settings, inline=bu_bb_inline_color)
// Be-BB & Be-MB Display Settings
be_bb_display_settings = "Be-BB & Be-MB Display Settings"
be_bb_color = [Link](#ffffff00, "Color", group=be_bb_display_settings,
inline=be_bb_inline_color)
be_bb_border_color = [Link](#ffffff00, "Border Color",
group=be_bb_display_settings, inline=be_bb_inline_color)
be_bb_text_color = [Link](#FFFFFF00, "Text Color",
group=be_bb_display_settings, inline=be_bb_inline_color)
var float[] high_points_arr = array.new_float(5)
var int[] high_index_arr = array.new_int(5)
var float[] low_points_arr = array.new_float(5)
var int[] low_index_arr = array.new_int(5)
var box[] bu_ob_boxes = array.new_box(5)
var box[] be_ob_boxes = array.new_box(5)
var box[] bu_bb_boxes = array.new_box(5)
var box[] be_bb_boxes = array.new_box(5)
to_up = high >= [Link](zigzag_len)
to_down = low <= [Link](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 = [Link](to_up[1])
low_val = [Link](nz(last_trend_up_since > 0 ? last_trend_up_since : 1, 1))
low_index = bar_index - [Link](low_val == low)
last_trend_down_since = [Link](to_down[1])
high_val = [Link](nz(last_trend_down_since > 0 ? last_trend_down_since : 1, 1))
high_index = bar_index - [Link](high_val == high)
if [Link](trend) != 0
if trend == 1
[Link](low_points_arr, low_val)
[Link](low_index_arr, low_index)
if trend == -1
[Link](high_points_arr, high_val)
[Link](high_index_arr, high_index)
f_get_high(ind) =>
[[Link](high_points_arr, [Link](high_points_arr) - 1 - ind),
[Link](high_index_arr, [Link](high_index_arr) - 1 - ind)]
f_get_low(ind) =>
[[Link](low_points_arr, [Link](low_points_arr) - 1 - ind),
[Link](low_index_arr, [Link](low_index_arr) - 1 - ind)]
f_delete_box(box_arr) =>
if delete_boxes
[Link]([Link](box_arr))
else
[Link](box_arr)
0
[h0, h0i] = f_get_high(0)
[h1, h1i] = f_get_high(1)
[l0, l0i] = f_get_low(0)
[l1, l1i] = f_get_low(1)
if [Link](trend) != 0 and show_zigzag
if trend == 1
[Link](h0i, h0, l0i, l0)
if trend == -1
[Link](l0i, l0, h0i, h0)
market = 1
market := nz(market[1], 1)
// market := market == 1 and close < l0 and low < l0 - [Link](h0 - l0) *
fib_factor ? -1 : market == -1 and close > h0 and high > h0 + [Link](h0 - l0) *
fib_factor ? 1 : market
last_l0 = [Link]([Link](market) != 0, l0, 0)
last_h0 = [Link]([Link](market) != 0, h0, 0)
market := last_l0 == l0 or last_h0 == h0 ? market : market == 1 and l0 < l1 and l0
< l1 - [Link](h0 - l1) * fib_factor ? -1 : market == -1 and h0 > h1 and h0 > h1 +
[Link](h1 - l0) * fib_factor ? 1 : 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]
bu_ob_since = bar_index - bu_ob_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_ob_since = bar_index - be_ob_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]
be_bb_since = bar_index - be_bb_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_bb_since = bar_index - bu_bb_index
if [Link](market) != 0
if market == 1
[Link](h1i, h1, h0i, h1, color=[Link](7, 246, 7), width=3)
[Link](int([Link](h1i, l0i)), h1, "BUY ALERT",
color=[Link]([Link], 100), style=label.style_label_down,
textcolor=[Link], size=[Link])
bu_ob = [Link](bu_ob_index, high[bu_ob_since], bar_index + 10,
low[bu_ob_since], bgcolor=bu_ob_color, border_color=bu_ob_border_color, text="Bu-
OB", text_color=bu_ob_text_color, text_halign=text.align_right,
text_size=text_size)
bu_bb = [Link](bu_bb_index, high[bu_bb_since], bar_index + 10,
low[bu_bb_since], bgcolor=bu_bb_color, border_color=bu_bb_border_color, text=l0 <
l1 ? "Bu-BB" : "Bu-MB", text_color=bu_bb_text_color, text_halign=text.align_right,
text_size=text_size)
[Link](bu_ob_boxes, bu_ob)
[Link](bu_bb_boxes, bu_bb)
if market == -1
[Link](l1i, l1, l0i, l1, color=[Link], width=3)
[Link](int([Link](l1i, h0i)), l1, "SELL ALERT",
color=[Link]([Link], 100), style=label.style_label_up,
textcolor=[Link], size=[Link])
be_ob = [Link](be_ob_index, high[be_ob_since], bar_index + 10,
low[be_ob_since], bgcolor=be_ob_color, border_color=be_ob_border_color, text="Be-
OB", text_color=be_ob_text_color, text_halign=text.align_right,
text_size=text_size)
be_bb = [Link](be_bb_index, high[be_bb_since], bar_index + 10,
low[be_bb_since], bgcolor=be_bb_color, border_color=be_bb_border_color, text=h0 >
h1 ? "Be-BB" : "Be-MB", text_color=be_bb_text_color, text_halign=text.align_right,
text_size=text_size)
[Link](be_ob_boxes, be_ob)
[Link](be_bb_boxes, be_bb)
// Monitor the boxes for price conditions
for bull_ob in bu_ob_boxes
bottom = box.get_bottom(bull_ob)
top = box.get_top(bull_ob)
if close < bottom
f_delete_box(bu_ob_boxes)
else if close < top
alert("Price in the BU-OB zone")
else
box.set_right(bull_ob, bar_index + 10)
for bear_ob in be_ob_boxes
top = box.get_top(bear_ob)
bottom = box.get_bottom(bear_ob)
if close > top
f_delete_box(be_ob_boxes)
if close > bottom
alert("Price in the BE-OB zone")
else
box.set_right(bear_ob, bar_index + 10)
for bear_bb in be_bb_boxes
top = box.get_top(bear_bb)
bottom = box.get_bottom(bear_bb)
if close > top
f_delete_box(be_bb_boxes)
else if close > bottom
alert("Price in the BE-BB zone")
else
box.set_right(bear_bb, bar_index + 10)
for bull_bb in bu_bb_boxes
bottom = box.get_bottom(bull_bb)
top = box.get_top(bull_bb)
if close < bottom
f_delete_box(bu_bb_boxes)
else if close < top
alert("Price in the BU-BB zone")
else
box.set_right(bull_bb, bar_index + 10)
alertcondition([Link](market) != 0, "MSB", "MSB")
// COBRA EMA calculation
COBRA = [Link](14, title="COBRA", minval=1)
source = close
mg = 0.0
// Calculate the EMA value only once
emaValue = [Link](source, COBRA)
mg := na(mg[1]) ? emaValue : mg[1] + (source - mg[1]) / (COBRA *
[Link](source/mg[1], 4))
// Input options for color
line_color = input([Link](76, 76, 85), title="Line Color")
line_width = [Link](1, title="Line Width")
plot(mg, title="COBRA", color=line_color, linewidth=line_width)
// Pamban zone and day break and table
// Check the time of the last session's candle closing at 3:25
lastSessionTime = timestamp(year(timenow), month(timenow), dayofmonth(timenow), 15,
25)
// Get the high and low prices of the candle at 3:25 of the last trading session
highPrice = [Link]([Link], "D", high[1],
lookahead=barmerge.lookahead_on)
lowPrice = [Link]([Link], "D", low[1],
lookahead=barmerge.lookahead_on)
// If the current time is before 3:25 of the last trading session
//if (time < lastSessionTime and time > lastSessionTime - 1000 * 60 * 5)
// Draw a box using the high and low prices
// [Link](left=lastSessionTime, top=highPrice, right=lastSessionTime + 1000 *
60 * 5, bottom=lowPrice, border_color=[Link](15, 16, 17, 14), border_width=2,
bgcolor=[Link](#020c14, 90))
///////////('OB LEO')
// Colors
// colors = [Link](title='Color Scheme', defval='BRIGHT', options=['DARK',
'BRIGHT'])
periods = input(5, 'Relevant Periods to identify OB')
threshold = [Link](0.0, 'Min. Percent move to identify OB', step=0.1)
usewicks = input(false, 'Use whole range [High/Low] for OB marking?')
showbull = input(true, 'Show latest Bullish Channel?')
showbear = input(true, 'Show latest Bearish Channel?')
info_pan = input(false, 'Show Latest OB Panel?')
ob_period = periods + 1
absmove = [Link](close[ob_period] - close[1]) / close[ob_period] * 100
relmove = absmove >= threshold
bullcolor = [Link]
bearcolor = [Link]
// Bullish Order Block
bullishOB = close[ob_period] < open[ob_period]
int upcandles = 0
for i = 1 to periods by 1
upcandles += (close[i] > open[i] ? 1 : 0)
OB_bull = bullishOB and upcandles == periods and relmove
OB_bull_high = OB_bull ? usewicks ? high[ob_period] : open[ob_period] : na
OB_bull_low = OB_bull ? low[ob_period] : na
OB_bull_avg = (OB_bull_high + OB_bull_low) / 2
// Bearish Order Block
bearishOB = close[ob_period] > open[ob_period]
int downcandles = 0
for i = 1 to periods by 1
downcandles += (close[i] < open[i] ? 1 : 0)
OB_bear = bearishOB and downcandles == periods and relmove
OB_bear_high = OB_bear ? high[ob_period] : na
OB_bear_low = OB_bear ? usewicks ? low[ob_period] : open[ob_period] : na
OB_bear_avg = (OB_bear_low + OB_bear_high) / 2
// Plot Bullish Order Block
plotshape(OB_bull, title='DELAYED BUY ALERT', style=[Link],
color=bullcolor, textcolor=[Link], location=[Link], offset=-
ob_period, text='BUY', force_overlay = true)
bull1 = plot(OB_bull_high, title='Bullish OB High', style=plot.style_linebr,
color=bullcolor, offset=-ob_period, linewidth=3)
bull2 = plot(OB_bull_low, title='Bullish OB Low', style=plot.style_linebr,
color=bullcolor, offset=-ob_period, linewidth=3)
// Plot Bearish Order Block
plotshape(OB_bear, title='DELAYED SELL ALERT', style=[Link],
color=bearcolor, textcolor=[Link], location=[Link], offset=-
ob_period, text='SELL', force_overlay = true)
bear1 = plot(OB_bear_low, title='Bearish OB Low', style=plot.style_linebr,
color=bearcolor, offset=-ob_period, linewidth=3)
bear2 = plot(OB_bear_high, title='Bearish OB High', style=plot.style_linebr,
color=bearcolor, offset=-ob_period, linewidth=3)
// Line Variables
var line linebull1 = na
var line linebull2 = na
var line linebull3 = na
var line linebear1 = na
var line linebear2 = na
var line linebear3 = na
// Drawing Bullish Lines
if OB_bull and showbull
[Link](linebull1)
linebull1 := [Link](x1=bar_index, y1=OB_bull_avg, x2=bar_index - 1,
y2=OB_bull_avg, extend=[Link], color=bullcolor, style=line.style_dashed,
width=1)
[Link](linebull2)
linebull2 := [Link](x1=bar_index, y1=OB_bull_high, x2=bar_index - 1,
y2=OB_bull_high, extend=[Link], color=bullcolor, style=line.style_dotted,
width=1)
[Link](linebull3)
linebull3 := [Link](x1=bar_index, y1=OB_bull_low, x2=bar_index - 1,
y2=OB_bull_low, extend=[Link], color=bullcolor, style=line.style_dotted,
width=1)
// Drawing Bearish Lines
if OB_bear and showbear
[Link](linebear1)
linebear1 := [Link](x1=bar_index, y1=OB_bear_avg, x2=bar_index - 1,
y2=OB_bear_avg, extend=[Link], color=bearcolor, style=line.style_dashed,
width=1)
[Link](linebear2)
linebear2 := [Link](x1=bar_index, y1=OB_bear_high, x2=bar_index - 1,
y2=OB_bear_high, extend=[Link], color=bearcolor, style=line.style_dotted,
width=1)
[Link](linebear3)
linebear3 := [Link](x1=bar_index, y1=OB_bear_low, x2=bar_index - 1,
y2=OB_bear_low, extend=[Link], color=bearcolor, style=line.style_dotted,
width=1)
// Alert Conditions
alertcondition(OB_bull, title='New Bullish OB detected', message='New Bullish OB
detected - This is NOT a BUY signal!')
alertcondition(OB_bear, title='New Bearish OB detected', message='New Bearish OB
detected - This is NOT a SELL signal!')
// Latest OB Values
var latest_bull_high = 0.0
var latest_bull_avg = 0.0
var latest_bull_low = 0.0
var latest_bear_high = 0.0
var latest_bear_avg = 0.0
var latest_bear_low = 0.0
if OB_bull_high > 0
latest_bull_high := OB_bull_high
if OB_bull_avg > 0
latest_bull_avg := OB_bull_avg
if OB_bull_low > 0
latest_bull_low := OB_bull_low
if OB_bear_high > 0
latest_bear_high := OB_bear_high
if OB_bear_avg > 0
latest_bear_avg := OB_bear_avg
if OB_bear_low > 0
latest_bear_low := OB_bear_low
//// IB Pamban zone and table ////
ib_session = [Link]("1525-1530", title="Calculation period for the initial
balance", group="Calculation period")
show_extra_levels = [Link](false, "Show extra levels (IBH x2 & IBL x2)",
group="Information")
show_intermediate_levels = [Link](true, "Show intermediate levels (50%)",
group="Information")
show_ib_calculation_area = [Link](true, "Initial balance calculation period
coloration", group="Information")
show_labels = [Link](true, "Show labels", group="Information")
fill_ib_areas = [Link](true, "Colour IB areas", group="Information")
only_current_levels = [Link](false, "Only display the current IB Levels",
group="Information")
only_current_zone = [Link](false, "Only display the current IB calculation
area", group="Information")
label_size = [Link]("normal", title="Label Size", options=["Auto", "Huge",
"normal","Large", "Small", "Tiny"], group="Drawings")
lvl_width = [Link](5, "Daily price level width", group="Drawings")
high_col = [Link]([Link](175, 12, 148), "Initial balance high levels
color", group="Drawings")
low_col = [Link]([Link](175, 12, 148), "Initial balance low levels color",
group="Drawings")
middle_col = [Link](#ffa726, "50% initial balance color", group="Drawings")
extend_level = [Link]("Right", title="Extend current levels",
options=["Right", "Left", "Both", "None"], group="Drawings")
main_levels_style = [Link]("Solid", "Main levels line style",
options=["Solid", "Dashed", "Dotted"], group="Drawings")
ext_levels_style = [Link]("Solid", "Extended levels line style",
options=["Solid", "Dashed", "Dotted"], group="Drawings")
int_levels_style = [Link]("Solid", "Intermediate levels line style",
options=["Solid", "Dashed", "Dotted"], group="Drawings")
fill_ib_color = [Link](#b8851faa, "IB area background color",
group="Drawings")
ext = extend_level == "Right" ? [Link] : extend_level == "Left" ? [Link]
: extend_level == "Both" ? [Link] : [Link]
var delta_history = array.new_float(20)
inSession(sess) => na(time([Link], sess)) == false
get_line_style(s) =>
s == "Solid" ? line.style_solid : s == "Dotted" ? line.style_dotted :
line.style_dashed
get_levels(n) =>
h = high[1]
l = low[1]
for i = 1 to n
if low[i] < l
l := low[i]
if high[i] > h
h := high[i]
[h, l, (h + l) / 2]
var line ibh = na
var line ibl = na
var line ibm = na
var line ib_plus = na
var line ib_minus = na
var line ib_plus2 = na
var line ib_minus2 = na
var line ibm_plus = na
var line ibm_minus = na
var label labelh = na
var label labell = na
var label labelm = na
var label label_plus = na
var label label_minus = na
var label label_plus2 = na
var label label_minus2 = na
var label labelm_plus = na
var label labelm_minus = na
var box ib_area = na
labelSize = (label_size == "Huge") ? [Link] :(label_size == "Large") ?
[Link] :(label_size == "Small") ? [Link] :(label_size == "Tiny") ?
[Link] :(label_size == "Auto") ? [Link] : [Link]
var offset = 0
ins = inSession(ib_session)
bgcolor(show_ib_calculation_area and ins ? #673ab730 : na, title="IB calculation
zone")
var float ib_delta = na
var float h=na
var float l=na
var float m=na
if ins
offset += 1
if ins[1] and not ins
[h, l, m] = get_levels(offset)
ib_delta := h - l
if [Link](delta_history) >= 10
[Link](delta_history)
[Link](delta_history, ib_delta)
line.set_extend(ibh, [Link])
line.set_extend(ibl, [Link])
if show_intermediate_levels
line.set_extend(ibm, [Link])
if show_extra_levels
line.set_extend(ib_plus, [Link])
line.set_extend(ib_minus, [Link])
line.set_extend(ib_plus2, [Link])
line.set_extend(ib_minus2, [Link])
if show_intermediate_levels
line.set_extend(ibm_plus, [Link])
line.set_extend(ibm_minus, [Link])
if show_labels
if only_current_levels
[Link](labelh)
[Link](labell)
[Link](labelm)
[Link](label_plus)
[Link](label_minus)
[Link](label_plus2)
[Link](label_minus2)
[Link](labelm_plus)
[Link](labelm_minus)
labelh := [Link](bar_index[offset], h, text="PAMBAN ZONE HIGH: " +
[Link](h), style=label.style_none, textcolor=[Link])
labell := [Link](bar_index[offset], l, text="PAMBAN ZONE LOW: " +
[Link](l), style=label.style_none, textcolor=[Link])
if show_extra_levels
label_plus := [Link](bar_index[offset], h + ib_delta, text="IBH x2 - " +
[Link](h + ib_delta), style=label.style_none, textcolor=[Link])
label_minus := [Link](bar_index[offset], l - ib_delta, text="IBL x2: " +
[Link](l - ib_delta), style=label.style_none, textcolor=[Link])
label_plus2 := [Link](bar_index[offset], h + (ib_delta * 2), text="IBH x3 -
" + [Link](h + (ib_delta * 2)), style=label.style_none,
textcolor=[Link])
label_minus2 := [Link](bar_index[offset], l - (ib_delta * 2), text="IBL x3:
" + [Link](l - (ib_delta * 2)), style=label.style_none,
textcolor=[Link])
if fill_ib_areas
if only_current_zone
[Link](ib_area)
ib_area := [Link](bar_index[offset], h, bar_index, l,
bgcolor=fill_ib_color, border_color=#00000000)
if only_current_levels
[Link](ibh)
[Link](ibl)
[Link](ibm)
[Link](ib_plus)
[Link](ib_minus)
[Link](ib_plus2)
[Link](ib_minus2)
[Link](ibm_plus)
[Link](ibm_minus)
ibh := [Link](bar_index[offset], h, bar_index, h, color=high_col, extend=ext,
width=lvl_width, style=get_line_style(main_levels_style))
ibl := [Link](bar_index[offset], l, bar_index, l, color=low_col, extend=ext,
width=lvl_width, style=get_line_style(main_levels_style))
if show_intermediate_levels
ibm := [Link](bar_index[offset], m, bar_index, m, color=middle_col,
style=get_line_style(int_levels_style), extend=ext, width=lvl_width)
if show_extra_levels
ib_plus := [Link](bar_index[offset], h + ib_delta, bar_index, h + ib_delta,
color=high_col, style=get_line_style(ext_levels_style), extend=ext,
width=lvl_width)
ib_minus := [Link](bar_index[offset], l - ib_delta, bar_index, l - ib_delta,
color=low_col, style=get_line_style(ext_levels_style), extend=ext, width=lvl_width)
ib_plus2 := [Link](bar_index[offset], h + (ib_delta * 2), bar_index, h +
(ib_delta * 2), color=high_col, style=get_line_style(ext_levels_style), extend=ext,
width=lvl_width)
ib_minus2 := [Link](bar_index[offset], l - (ib_delta * 2), bar_index, l -
(ib_delta * 2), color=low_col, style=get_line_style(ext_levels_style), extend=ext,
width=lvl_width)
if show_intermediate_levels
ibm_plus := [Link](bar_index[offset], h + (ib_delta / 2), bar_index, h +
(ib_delta / 2), color=middle_col, style=get_line_style(int_levels_style),
extend=ext, width=lvl_width)
ibm_minus := [Link](bar_index[offset], l - (ib_delta / 2), bar_index, l -
(ib_delta / 2), color=middle_col, style=get_line_style(int_levels_style),
extend=ext, width=lvl_width)
offset := 0
if (not ins) and (not ins[1])
line.set_x2(ibh, bar_index)
line.set_x2(ibl, bar_index)
if show_intermediate_levels
line.set_x2(ibm, bar_index)
if show_extra_levels
line.set_x2(ib_plus, bar_index)
line.set_x2(ib_minus, bar_index)
line.set_x2(ib_plus2, bar_index)
line.set_x2(ib_minus2, bar_index)
if show_intermediate_levels
line.set_x2(ibm_plus, bar_index)
line.set_x2(ibm_minus, bar_index)
// Analytics Table
var table ib_analytics = [Link](position.bottom_left, 2, 6)
ib_sentiment() =>
h = [Link](delta_history)
l = [Link](delta_history)
a = [Link](delta_history)
h_comp = ib_delta > h ? ib_delta - h : (ib_delta - h) * -1
l_comp = ib_delta > l ? ib_delta - l : (ib_delta - l) * -1
a_comp = ib_delta > a ? ib_delta - a : (ib_delta - a) * -1
(h_comp < l_comp and h_comp < a_comp) ? "Huge" : (l_comp < h_comp and l_comp <
a_comp) ? "Small" : "Medium"
show_delta_analytics = [Link](true, "Display IB delta analytics",
group="Information")
if show_delta_analytics
[Link](ib_analytics, 0, 2, "ZAK Algo V1.0", bgcolor=[Link],
text_color=[Link])
// ADR Calculations
OPEN = [Link]([Link], 'D', open, barmerge.gaps_off,
barmerge.lookahead_on)
dcol = [Link]
dayrange = (high - low)
r1 = [Link]([Link], 'D', dayrange)
r2 = [Link]([Link], 'D', dayrange[1])
r3 = [Link]([Link], 'D', dayrange[2])
r4 = [Link]([Link], 'D', dayrange[3])
r5 = [Link]([Link], 'D', dayrange[4])
r6 = [Link]([Link], 'D', dayrange[5])
r7 = [Link]([Link], 'D', dayrange[6])
r8 = [Link]([Link], 'D', dayrange[7])
r9 = [Link]([Link], 'D', dayrange[8])
r10 = [Link]([Link], 'D', dayrange[9])
adr_10 = (r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9 + r10) / 10
adr_9 = (r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 + r9) / 9
adr_8 = (r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8) / 8
adr_7 = (r1 + r2 + r3 + r4 + r5 + r6 + r7) / 7
adr_6 = (r1 + r2 + r3 + r4 + r5 + r6) / 6
adr_5 = (r1 + r2 + r3 + r4 + r5) / 5
adr_4 = (r1 + r2 + r3 + r4) / 4
adr_3 = (r1 + r2 + r3) / 3
adr_2 = (r1 + r2) / 2
adr_1 = r1
// Plot ADR
//adrhigh10 = plot((OPEN + (adr_10 / 2)), title="ADR High10",
style=plot.style_circles, color=[Link], linewidth=2)
//adrlow10 = plot((OPEN - (adr_10 / 2)), title="ADR LOW10",
style=plot.style_circles, color=[Link], linewidth=2)
//adrhigh5 = plot((OPEN + (adr_5 / 2)), title="ADR High5",
style=plot.style_circles, color=[Link], linewidth=2)
//adrlow5 = plot((OPEN - (adr_5 / 2)), title="ADR LOW5", style=plot.style_circles,
color=[Link], linewidth=2)
// Uncomment to fill areas if necessary
// fill(adrlow10, adrlow5, color=[Link])
// fill(adrhigh10, adrhigh5, color=[Link])
/////////////////////////// Purple Cloud
///////("RSI Trendlines Breakouts")
import HoanGhetti/SimpleTrendlines/3 as tl
g_trendlines = 'Trendline Settings', g_conditions = 'Conditions', g_styling =
'Styling', g_timeframe = 'Timeframe'
input_timeframe = [Link](defval = '', title = 'Timeframe', group =
g_timeframe)
input_pLen = [Link](defval = 4, title = 'Lookback Range', minval = 1, group
= g_trendlines, tooltip = 'How many bars to determine when a swing high/low is
detected.')
input_rLen = [Link](defval = 14, title = 'RSI Length' , minval = 1, group =
g_trendlines)
input_rSrc = [Link](defval = close, title = 'RSI Source', group =
g_trendlines)
input_repaint = [Link](defval = 'On', title = 'Repainting', group =
g_conditions, options = ['On', 'Off: Bar Confirmation'], tooltip = 'Bar
Confirmation: Generates alerts when candle closes. (1 Candle Later)')
input_rsiDiff = [Link](defval = 3, title = 'RSI Difference', group =
g_conditions, tooltip = 'The difference between the current RSI value and the
breakout value.\n\nHow much higher in value should the current RSI be compared to
the breakout value in order to detect a breakout?')
input_rsiCol = [Link](defval = [Link], title = 'RSI Color', group =
g_styling)
input_width = [Link](defval = 2, title = 'Line Width', minval = 1, group =
g_styling)
input_lblType = [Link](defval = 'Simple', title = 'Label Type', group =
g_styling, options = ['Full', 'Simple'])
input_lblSize = [Link](defval = [Link], title = 'Label Size', group =
g_styling, options = [[Link], [Link], [Link], [Link], [Link]])
input_pLowCol = [Link](defval = [Link], title = 'Pivot Low', inline =
'col', group = g_styling)
input_pHighCol = [Link](defval = #089981, title = 'Pivot High', inline =
'col', group = g_styling)
input_override = [Link](defval = false, title = 'Override Text Color', group =
g_styling, inline = 'override')
input_overCol = [Link](defval = [Link], title = ' ', group = g_styling,
inline = 'override')
lblText = switch input_lblType
'Simple' => 'Br'
'Full' => 'Break'
repaint = switch input_repaint
'On' => false
'Off: Bar Confirmation' => true
rsi_v = [Link](input_rSrc, input_rLen)
rsi1 = input_timeframe == '' ? rsi_v : [Link]([Link],
input_timeframe, rsi_v, lookahead = barmerge.lookahead_on)
ppl = fixnan([Link](rsi1, 1, input_pLen))
pph = fixnan([Link](rsi1, 1, input_pLen))
pivot(float pType) =>
pivot = pType == ppl ? ppl : pph
xAxis = [Link]([Link](pivot), bar_index, 0) -
[Link]([Link](pivot), bar_index, 1)
prevPivot = [Link]([Link](pivot), pivot, 1)
pivotCond = [Link](pivot) and (pType == ppl ? pivot > prevPivot : pivot <
prevPivot)
pData = [Link](x_axis = xAxis, offset = input_pLen, strictMode = true,
strictType = pType ==ppl ? 0 : 1)
[Link](pivotCond, prevPivot, pivot, rsi1)
pData
breakout([Link] this, float pType) =>
var bool hasCrossed = false
if [Link]([Link].get_y1())
hasCrossed := false
[Link](not hasCrossed)
condType = (pType == ppl ? rsi1 < [Link].get_y2() - input_rsiDiff
: rsi1 > [Link].get_y2() + input_rsiDiff) and not hasCrossed
condition = repaint ? condType : condType and [Link]
if condition
hasCrossed := true
//[Link].set_xy2([Link].get_x2(),
[Link].get_y2())
//[Link].set_xy2(na, na)
//[Link]()
//[Link](
// bar_index,
// [Link].get_y2(),
// text = lblText, color = pType == ppl ? [Link](input_pLowCol,
50) : [Link](input_pHighCol, 50),
// size = input_lblSize, style = pType == ppl ?
label.style_label_lower_left : label.style_label_upper_left,
// textcolor = pType == ppl ? (input_override ? input_overCol :
input_pLowCol) : input_override ? input_overCol : input_pHighCol)
hasCrossed
method style([Link] this, color col) =>
[Link].set_color(col)
[Link].set_width(input_width)
[Link].set_color(col)
[Link].set_width(input_width)
[Link].set_style(line.style_dashed)
plData = pivot(ppl)
phData = pivot(pph)
[Link](input_pLowCol)
[Link](input_pHighCol)
cu = breakout(plData, ppl)
co = breakout(phData, pph)
//hline(70, title = 'Overbought', color = input_pHighCol, linestyle =
hline.style_dotted)
//hline(30, title = 'Oversold', color = input_pLowCol, linestyle =
hline.style_dotted)
//plot(rsi1, title = 'Relative Strength Index', linewidth = 2, color =
input_rsiCol)
//alertcondition([Link]([Link].get_y1()), 'New Pivot Low
Trendline')
plotshape([Link](cu) and cu, title = 'Pivot Low Breakout', text = "DN",
textcolor = [Link], location = [Link], force_overlay = true)
//([Link]([Link].get_y1()), 'New Pivot High Trendline')
plotshape([Link](co) and co, title = 'Pivot High Breakout', text = "UP",
textcolor = [Link], location = [Link], force_overlay = true)
/////////("RSI Chart Bars")
csrc = close, clen = [Link](14, minval=1, title="Length")
up = [Link]([Link]([Link](csrc), 0), clen)
down = [Link]([Link]([Link](csrc), 0), clen)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
//coloring method below
csrc1 = close, clen1 = [Link](55, minval=1, title="UpLevel")
csrc2 = close, clen2 = [Link](45, minval=1, title="DownLevel")
isup() => rsi > clen1
isdown() => rsi < clen2
barcolor(isup() ? [Link] : isdown() ? [Link] : na )
//////////////////