Professional Documents
Culture Documents
Trading Hub 3 Signals GainzAlgo Pro Volume Profile Maps LA
Trading Hub 3 Signals GainzAlgo Pro Volume Profile Maps LA
bull1ish_engulfing = close[1] < open[1] and close > open and close > open[1]
rsi_below = rsi < rsi_index_param
decrease_over = close < close[candle_delta_length_param]
bear1ish_engulfing = close[1] > open[1] and close < open and close < open[1]
rsi_above = rsi > 100 - rsi_index_param
increase_over = close > close[candle_delta_length_param]
last_signal := 'buy'
if bear1 and (disable_repeating_signals_param ? (last_signal != 'sell' ? true : na)
: true)
if label_style == 'text bubble'
label.new(bear1 ? bar_index : na, high, 'SELL', color=sell_label_color,
style=label.style_label_down, textcolor=label_text_color, size=label_size)
else if label_style == 'triangle'
label.new(bear1 ? bar_index : na, high, 'SELL', yloc=yloc.abovebar,
color=sell_label_color, style=label.style_triangledown, textcolor=TRANSPARENT,
size=label_size)
else if label_style == 'arrow'
label.new(bear1 ? bar_index : na, high, 'SELL', yloc=yloc.abovebar,
color=sell_label_color, style=label.style_arrowdown, textcolor=TRANSPARENT,
size=label_size)
last_signal := 'sell'
//drawing options
showPOI = input.bool(true, "Show POI", group="POI settings")
poi_type = input.string ("---",title='POI type', group="POI settings",
options=["---", "Mother Bar"])
mergeRatio = input.float(defval=0, minval=0, maxval=0.5, step=0.02, title="Merge
Ratio", group="POI settings" )
maxBarHistory = input.int(2000, title="Max IPA age", group="POI settings")
//line babel
var label idm_label = na
var line idm_line = na
var label choch_label = na
var line choch_line = na
var label bos_label = na
var line bos_line = na
var line pdh_line = na
var label pdh_label = na
var line pdl_line = na
var label pdl_label = na
var line mid_line = na
var label mid_label = na
//high low
var puHigh = high
var puLow = low
var L = low
var H = high
var idmLow = low
var idmHigh = high
var lastH = high
var lastL = low
var H_lastH = high
var L_lastHH = low
var H_lastLL = high
var L_lastL = low
var motherHigh = high[1]
var motherLow = low[1]
var puUp = high
var puDn = low
//bar indexes
var int motherBar = time[1]
var int puBar = na
var int puHBar = na
var int puLBar = na
var int idmLBar = na
var int idmHBar = na
var int HBar = time
var int LBar = time
var int lastHBar = time
var int lastLBar = time
var int puUpbar = na
var int puDnbar = na
//structure confirm
var bool mnStrc = na
var bool prevMnStrc = na
var bool isPrevBos = na
var bool findIDM = false
var bool isBosUp = false
var bool isBosDn = false
var bool isCocUp = true
var bool isCocDn = true
//poi
var bool isSweepOBS = false
var int current_OBS = na
var float high_MOBS = na
var float low_MOBS = na
//Array
var arrTopBotBar = array.new_int(1, time)
var arrTop = array.new_float(1, high)
var arrBot = array.new_float(1, low)
//color
color transp = color.new(color.gray,100)
//Caculate
curTf = timeframe.in_seconds(timeframe.period)
dayTf = timeframe.in_seconds("1D")
i_loop = 2*dayTf/curTf
[pdh, pdl] = request.security(syminfo.tickerid, 'D', [high[1], low[1]])
len = curTf*1000
//#endregion
barcolor(ba_color1, -1)
getTextLabel(float current, float last, string same, string diff) => current > last
? same : diff
updateTopBotValue() =>
array.push(arrTop, high)
array.push(arrBot, low)
array.push(arrTopBotBar, time)
updateLastHLValue() =>
array.push(arrLastH,lastH)
array.push(arrLastHBar,lastHBar)
array.push(arrLastL,lastL)
array.push(arrLastLBar,lastLBar)
updateIdmHigh() =>
array.push(arrIdmHigh,puHigh)
array.push(arrIdmHBar,puHBar)
updateIdmLow() =>
array.push(arrIdmLow,puLow)
array.push(arrIdmLBar,puLBar)
getNLastValue(arr, n) =>
if array.size(arr) > n - 1
array.get(arr, array.size(arr) - n)
removeNLastLabel(arr, n) =>
if array.size(arr) > n - 1
label.delete(array.get(arr, array.size(arr) - n))
removeNLastLine(arr, n) =>
if array.size(arr) > n - 1
line.delete(array.get(arr, array.size(arr) - n))
removeLastLabel(arr, n) =>
if array.size(arr) > n - 1
for i = 1 to n
label.delete(array.get(arr, array.size(arr) - i))
removeLastLine(arr, n) =>
if array.size(arr) > n - 1
for i = 1 to n
line.delete(array.get(arr, array.size(arr) - i))
fixStrcAfterBos() =>
removeLastLabel(arrBCLabel, 1)
removeLastLine(arrBCLine, 1)
removeLastLabel(arrIdmLabel, 1)
removeLastLine(arrIdmLine, 1)
removeLastLabel(arrHLLabel, 2)
removeLastLabel(arrHLCircle, 2)
fixStrcAfterChoch() =>
removeLastLabel(arrBCLabel, 2)
removeLastLine(arrBCLine, 2)
removeNLastLabel(arrHLLabel, 2)
removeNLastLabel(arrHLLabel, 3)
removeNLastLabel(arrHLCircle, 2)
removeNLastLabel(arrHLCircle, 3)
removeNLastLabel(arrIdmLabel, 2)
removeNLastLine(arrIdmLine, 2)
TP(H, L) =>
target = isCocUp ? high + math.abs(H - L) : low - math.abs(H - L)
target := target < 0 ? 0 : target
if showTP
line.new(bar_index, isCocUp ? high : low, bar_index, target, color =
colorTP, style = line.style_arrow_right)
zone = getNLastValue(zoneArray, 1)
//Merge zone
if _top >= topZone and _bot <= botZone or rangeTop or rangeBot
_top := math.max(_top,topZone)
_bot := math.min(_bot,botZone)
_left := leftZone
removeZone(zoneArray, zone)
if not isb[1]
if not isSupply and low[1] < low[2] and low[1] < low and close > high[1]
and low[1] < topZone and low[1] > botZone
scobUp
else if isSupply and high[1] > high[2] and high[1] > high and close <
low[1] and high[1] < topZone and high[1] > botZone
scobDn
else
na
//#endregion
top1 = getNLastValue(arrTop, 2)
bot1 = getNLastValue(arrBot, 2)
topBotBar1 = getNLastValue(arrTopBotBar, 2)
//#endregion
//#endregion
updateTopBotValue()
puHigh := high
puLow := low
puHBar := time
puLBar := time
mnStrc := na
if high > H
updateIdmLow()
updateTopBotValue()
puHigh := high
puHBar := time
prevMnStrc := na
mnStrc := true
if low < L
updateIdmHigh()
updateTopBotValue()
puLow := low
puLBar := time
prevMnStrc := na
mnStrc := false
//#endregion
if low <= L
L := low
LBar := time
H_lastLL := high
idmHigh := getNLastValue(arrIdmHigh, 1)
idmHBar := getNLastValue(arrIdmHBar, 1)
//#endregion
//#endregion
if showPOI
if not isSweepOBS
high_MOBS := high[3]
low_MOBS := low[3]
current_OBS := time[3]
if high_MOBS > high[4] and high_MOBS > high[2]
isSweepOBS := true
else
if low_MOBS > high[1]
handleZone(supplyZone, current_OBS, high_MOBS, low_MOBS, colorSupply)
isSweepOBS := false
else
if poi_type == "Mother Bar" and isb[2]
high_MOBS := math.max(high_MOBS,motherHigh[2])
low_MOBS := math.min(low_MOBS,motherLow[2])
current_OBS := math.min(current_OBS,motherBar)
else
high_MOBS := high[2]
low_MOBS := low[2]
current_OBS := time[2]
if not isSweepOBD
low_MOBD := low[3]
high_MOBD := high[3]
current_OBD := time[3]
if low_MOBD < low[4] and low_MOBD < low[2]
isSweepOBD := true
else
if high_MOBD < low[1]
handleZone(demandZone, current_OBD, high_MOBD, low_MOBD, colorDemand)
isSweepOBD := false
else
if poi_type == "Mother Bar" and isb[2]
high_MOBD := math.max(high_MOBD,motherHigh[2])
low_MOBD := math.min(low_MOBD,motherLow[2])
current_OBD := math.min(current_OBD,motherBar)
else
high_MOBD := high[2]
low_MOBD := low[2]
current_OBD := time[2]
//#endregion
//#Alerts
if (isBosUp)
alert("Bullish BoS structure has been confirmed",
alert.freq_once_per_bar_close)
if (isBosDn)
alert("Bearish BoS structure has been confirmed",
alert.freq_once_per_bar_close)
if (findIDM)
alert("IDM structure has been confirmed", alert.freq_once_per_bar_close)
if (showSw)
alert("High/Low Sweep structure detected", alert.freq_once_per_bar_close)
if (showTP)
alert("Target Profit structure detected", alert.freq_once_per_bar_close)
if (showCircleHL)
alert("Circle HL is marked on the chart",alert.freq_once_per_bar_close)
//------------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------{
sp1 =' ' , sp2 =
' '
src = input.source( close , 'source'
)
mtV = input.bool ( false , sp2 + 'Volume * currency'
//------------------------------------------------------------------------------
// Methods
//-----------------------------------------------------------------------------{
method set (line ln, int x, float y, int o) =>
ln .set_xy1 (math.max(0, bar_index + o ), y)
ln .set_xy2 (math.max(0, bar_index + o - nz(x)), y)
//------------------------------------------------------------------------------
// Variables
//-----------------------------------------------------------------------------{
var originalMap = map.new <float, float>() //
key: close, value: volume
var lines = array.new < line >() //
array of lines
var boxes = array.new < box >() //
array of boxes
var tab = table.new(position.top_right, 2, 7, chart.bg_color,
chart.bg_color, 1, chart.bg_color, 1)
//------------------------------------------------------------------------------
// Execution
//-----------------------------------------------------------------------------{
n = bar_index
barsBack := math.min (barsBack , last_bar_index) //
minimum of ['Amount of bars' - total available bars]
mxLines2 = math.round(maxLines / 2)
if barstate.isfirst
for i = 0 to math.min(500, maxLines ) //
fill line array till "maxLines" or "500" reached
lines.unshift(line.new(na, na, na, na, width=2))
for i = 0 to math.min(500, math.max(0, maxLines - 500)) //
fill box array till "maxLines" or "500" reached (only after line array is filled)
boxes.unshift(box .new(na, na, na, na, border_width=1))
if last_bar_index - n == barsBack
line.new(n, close, n, close+ syminfo.mintick, extend=extend.both)
if barstate.islast
maxVol = 0.
for ln in lines
ln.set_color(cReg) //
set colour of all lines to default
for bx in boxes
bx.set_border_color(color.new(cReg, 70)) //
set colour of all boxes to default
if originalMap.size() > 1
copyK = originalMap.keys().copy() //
make a copy of the keys -> array
copyK.sort() //
sort (ascending)
idx = copyK.binary_search_leftmost(src) //
look for position of 'current' src in copyK
szL = idx, szR = copyK.size() -1 - idx //
check how many left (lower) and right (higher) of idx (size: left - idx - right)
sml = math.min(szL, szR) //
smallest side
if szR == sml
szL := math.min(maxLines - math.min(mxLines2, szR), szL) //
if R side has 'unused' lines -> give them to L side
szR := math.min(mxLines2, szR)
else
szL := math.min(mxLines2, szL)
szR := math.min(maxLines - math.min(mxLines2, szL), szR) //
if L side has 'unused' lines -> give them to R side
w = width / maxVol //
make sure lines don't exceed 'max width Volume Profile'
aMaxI = array.from(0 , 0 ) //
index of largest and second largest volume
aMaxV = array.from(0., 0.) //
value of largest and second largest volume
for i = 0 to keys.size()-1
clo = keys.get(i)
vol = vals.get(i)
if vol > max //
when largest volume is found -> set index so line can be coloured later
max := vol
aMaxI.inOut( i )
aMaxV.inOut(vol)
else if vol > aMaxV.get(1) //
when second largest volume is found -> set index so line can be coloured later
aMaxI.set(1, i )
aMaxV.set(1,vol)
if i < 500
lines.get(i ).set(math.round(vol * w), clo, offset) //
update 'lines' array
else
boxes.get(i - 500).set(math.round(vol * w), clo, offset) //
update 'boxes' array (line array is full -> box array)
// if originalMap.contains(price)
// originalMap.put(price, originalMap.get(price) + volume)
// copyK = originalMap.keys().copy()
// copyK.sort()
// idx = copyK.binary_search_leftmost(src)
//------------------------------------------------------------------------------
// Table
//-----------------------------------------------------------------------------{
if sTab
tab.cell(0, 0, text='size originalMap' ,
text_font_family=font.family_monospace, text_color=chart.fg_color, height=2)
tab.cell(1, 0, text=str.tostring(originalMap.size()) ,
text_font_family=font.family_monospace, text_color=chart.fg_color, height=2)
tab.cell(0, 1, text= '# higher' ,
text_font_family=font.family_monospace, text_color=chart.fg_color, height=2)
tab.cell(1, 1, text=str.tostring(originalMap.size() - idx),
text_font_family=font.family_monospace, text_color=chart.fg_color, height=2)
tab.cell(0, 2, text= 'index "close"' ,
text_font_family=font.family_monospace, text_color=chart.fg_color, height=2)
tab.cell(1, 2, text=str.tostring( idx ) ,
text_font_family=font.family_monospace, text_color=chart.fg_color, height=2)
tab.cell(0, 3, text= ' ' ,
text_font_family=font.family_monospace, text_color=chart.fg_color, height=2)
tab.cell(0, 4, text= 'size newMap' ,
text_font_family=font.family_monospace, text_color=chart.fg_color, height=2)
tab.cell(1, 4, text=str.tostring( newMap.size() ) ,
text_font_family=font.family_monospace, text_color=chart.fg_color, height=2)
tab.cell(0, 5, text= '# higher' ,
text_font_family=font.family_monospace, text_color=chart.fg_color, height=2)
tab.cell(1, 5, text=str.tostring( szR ) ,
text_font_family=font.family_monospace, text_color=chart.fg_color, height=2)
tab.cell(0, 6, text= '# lower' ,
text_font_family=font.family_monospace, text_color=chart.fg_color, height=2)
tab.cell(1, 6, text=str.tostring( szL ) ,
text_font_family=font.family_monospace, text_color=chart.fg_color, height=2)
//-----------------------------------------------------------------------------}