BJ Key Levels
BJ Key Levels
// =================================
// PLEASE SUPPORT THE TEAM
// =================================
//
// If this project has been helpful, consider making a donation:
// Biance UID: 263856481
// Telegram: https://t.me/enigmawaytrading
// =================================
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © Bjorgum
//@version=5
indicator ('Bjorgum Key Levels', 'Bj Key Levels', overlay= true,
max_boxes_count= 500, max_labels_count= 500, max_lines_count=500)
import Bjorgum/BjCandlePatterns/2 as bj
// ================================== //
// ------------> Tips <-------------- //
// ================================== //
repaintTip = "Wait for candles end before detecting patterns. False will
show potential patterns forming before they are confirmed."
labelsTip = "Show a label for detected candle patterns"
sBoxTip = "Show a box around detected candle patterns"
dTip = "Detect Doji candle patterns"
beTip = "Detect Engulfing patterns"
hsTip = "Detect Hammers and Shooting Star patterns"
dgTip = "Detect Dragonfly Doji and Gravestone Doji patterns"
twTip = "Detect Tweezer Top and Tweezer Bottom patterns"
stTip = "Detect Spinning Top patterns"
pcTip = "Detect Piercing and Dark Cloud Cover patterns"
bhTip = "Detect Harami candle patterns"
lsTip = "Detect Long Upper Shadow and Long Lower Shadow patterns"
// ================================== //
// ---------> User Input <----------- //
// ================================== //
// ================================== //
// -----> Immutable Constants <------ //
// ================================== //
sync = bar_index
labUp = label.style_label_up
labDn = label.style_label_down
confirmed = barstate.isconfirmed
extrap = extend ? extend.right : extend.none
_haBody() =>
haClose = (open + high + low + close) / 4
haOpen = float(na)
haOpen := na(haOpen[1]) ? (open + close) / 2 :
(nz(haOpen[1]) + nz(haClose[1])) / 2
[haOpen, haClose]
_extend(_x) =>
for i = 0 to array.size (_x)-1
box.set_right (array.get (_x, i), sync)
_delLab(_x) =>
if array.size(_x) > 0
label.delete (array.pop (_x))
_delLine(_x) =>
if array.size(_x) > 0
line.delete (array.pop (_x))
_getBox(_x,_i) =>
_box = array.get (_x,_i)
_t = box.get_top (_box)
_b = box.get_bottom (_box)
[_t, _b]
_align(_x,_y) =>
for i = 0 to array.size (_x) -1
[_T, _B] = _getBox (_y, 0)
[_t, _b] = _getBox (_x, i)
if _T > _b and _T < _t or
_B < _t and _B > _b or
_T > _t and _B < _b or
_B > _b and _T < _t
box.set_top (array.get (_y, 0), _t)
box.set_bottom (array.get (_y, 0), _b)
_detect(_x,_y) =>
int _i = 0
bool _found = false
bool _isBull = na
while (not _found and _i < array.size (_x) )
[t_, b_] = _getBox (_x,_i)
if low < t_ and high > b_
_isBull := array.get (_y,_i)
_found := true
_i += 1
[_found, _isBull]
_falseBreak(_l) =>
bool _d = false
bool _u = false
for i = 1 to lookback
if _l[i] < _l and _l[i+1] >= _l and _l[1] < _l
_d := true
if _l[i] > _l and _l[i+1] <= _l and _l[1] > _l
_u := true
[_d, _u]
_numLevel(_x,_y) =>
int _above = 0
int _fill = 0
for i = 0 to array.size (_x)-1
_isBull = array.get (_x,i)
if _isBull
_above += 1
if not na(_isBull)
_fill += 1
for i = 0 to array.size (_y)-1
_isBull = array.get (_y,i)
if _isBull
_above += 1
if not na(_isBull)
_fill += 1
[_above, _fill]
_check(_src,_l) =>
bool _check = false
for i = 0 to _l
if _src[i]
_check := true
_check
// ================================== //
// ----> Variable Calculations <----- //
// ================================== //
HH = pivot_high+ band
HL = pivot_high- band
LH = pivot_low+ band
LL = pivot_low- band
// ================================== //
// --------> Logical Order <--------- //
// ================================== //
if alignZones
_align (pivotHigh, pivotHigh)
_align (pivotHigh, pivotLows)
_align (pivotLows, pivotLows)
_align (pivotLows, pivotHigh)
_extend (pivotHigh)
_extend (pivotLows)
// ================================== //
// ----> Conditional Parameters <---- //
// ================================== //
bullCheck = not resBreak and not resBreak[1] and (fh or fl) and close >
open and (hb or lb)
bearCheck = not supBreak and not supBreak[1] and (fh or fl) and close <
open and not (hb or lb)
highrange = reflect-offset
lowsrange = offset
// ================================== //
// -----> Pattern Recognition <------ //
// ================================== //
// ================================== //
// ------> Graphical Display <------- //
// ================================== //
bj.dLab (dw and labels, labNeutCol, textNeutCol), _wrap (dw and sBox,
boxes, 1, patNeutBo, patNeutBg)
bj.bewLab (bew and labels, labBullCol, textBullCol), _wrap (bew and sBox,
boxes, 2, patBullBo, patBullBg)
bj.hLab (h and labels, labBullCol, textBullCol), _wrap (h and sBox,
boxes, 1, patBullBo, patBullBg)
bj.ddLab (dd and labels, labBullCol, textBullCol), _wrap (dd and sBox,
boxes, 1, patBullBo, patBullBg)
bj.tbLab (tb and labels, labBullCol, textBullCol), _wrap (tb and sBox,
boxes, 2, patBullBo, patBullBg)
bj.stwLab (stw and labels, labNeutCol, textNeutCol), _wrap (stw and sBox,
boxes, 1, patBullBo, patNeutBg)
bj.pLab (p and labels, labBullCol, textBullCol), _wrap (p and sBox,
boxes, 2, patBullBo, patBullBg)
bj.hwLab (bhw and labels, labBullCol, textBullCol), _wrap (bhw and sBox,
boxes, 2, patBullBo, patBullBg)
bj.llsLab (ll and labels, labBullCol, textBullCol), _wrap (ll and sBox,
boxes, 1, patBullBo, patBullBg)
bj.dLab (db and labels, labNeutCol, textNeutCol), _wrap (db and sBox,
boxes, 1, patNeutBo, patNeutBg)
bj.bebLab (beb and labels, labBearCol, textBearCol), _wrap (beb and sBox,
boxes, 2, patBearBo, patBearBg)
bj.ssLab (ss and labels, labBearCol, textBearCol), _wrap (ss and sBox,
boxes, 1, patBearBo, patBearBg)
bj.gdLab (gd and labels, labBearCol, textBearCol), _wrap (gd and sBox,
boxes, 1, patBearBo, patBearBg)
bj.ttLab (tt and labels, labBearCol, textBearCol), _wrap (tt and sBox,
boxes, 2, patBearBo, patBearBg)
bj.stbLab (stb and labels, labNeutCol, textNeutCol), _wrap (stb and sBox,
boxes, 1, patBearBo, patBearBg)
bj.dccLab (dcc and labels, labBearCol, textBearCol), _wrap (dcc and sBox,
boxes, 2, patBearBo, patBearBg)
bj.hbLab (bhb and labels, labBearCol, textBearCol), _wrap (bhb and sBox,
boxes, 2, patBearBo, patBearBg)
bj.lusLab (lu and labels, labBearCol, textBearCol), _wrap (lu and sBox,
boxes, 1, patBearBo, patBearBg)
// ================================== //
// -----> Alert Functionality <------ //
// ================================== //
// ____ __ _ ____
// ( __)( ( \( \
// ) _) / / ) D (
// (____)\_)__)(____/