BossExoticMAs
A next-generation moving average and smoothing library by TheStopLossBoss, featuring premium adaptive, exotic, and DSP-inspired filters — optimized for Pine Script® v6 and designed for Traders who demand precision and beauty.
> BossExoticMAs is a complete moving average and signal-processing toolkit built for Pine Script v6.
It combines the essential trend filters (SMA, EMA, WMA, etc.) with advanced, high-performance exotic types used by quants, algo designers, and adaptive systems.
Each function is precision-tuned for stability, speed, and visual clarity — perfect for building custom baselines, volatility filters, dynamic ribbons, or hybrid signal engines.
Includes built-in color gradient theming powered by the exclusive BossGradient —
//Key Features
✅ Full Moving Average Set
SMA, EMA, ZEMA, WMA, HMA, WWMA, SMMA
DEMA, TEMA, T3 (Tillson)
ALMA, KAMA, LSMA
VMA, VAMA, FRAMA
✅ Signal Filters
One-Euro Filter (Crispin/Casiez implementation)
ATR-bounded Range Filter
✅ Color Engine
lerpColor() safe blending using color.from_gradient
Thematic gradient palettes: STOPLOSS, VAPORWAVE, ROYAL FLAME, MATRIX FLOW
Exclusive: BOSS GRADIENT
✅ Helper Functions
Clamping, normalization, slope detection, tick delta
Slope-based dynamic color control via slopeThemeColor()
🧠 Usage Example
//@version=6
indicator("Boss Exotic MA Demo", overlay=true)
import TheStopLossBoss/BossExoticMAs/1 as boss
len = input.int(50, "Length")
atype = input.string("T3", "MA Type", options= )
t3factor = input.float(0.7, "T3 β", step=0.05)
smoothColor = boss.slopeThemeColor(close, "BOSS GRADIENT", 0.001)ma = boss.maSelect(close, len, atype, t3factor, 0.85, 14)
plot(ma, "Boss Exotic MA", color=smoothColor, linewidth=2)
---
🔑 Notes
Built exclusively for Pine Script® v6
Library designed for import use — all exports are prefixed cleanly (boss.functionName())
Some functions maintain internal state (var-based). Warnings are safe to ignore — adaptive design choice.
Each MA output is non-repainting and mathematically stable.
---
📜 Author
TheStopLossBoss
Designer of precision trading systems and custom adaptive algorithms.
Follow for exclusive releases, educational material, and full-stack trend solutions.
movingaverage, trend, adaptive, filter, volatility, smoothing, quant, technicalanalysis, bossgradient, t3, alma, frama, vma
Display
Obj_XABCD_HarmonicLibrary "Obj_XABCD_Harmonic"
Harmonic XABCD Pattern object and associated methods. Easily validate, draw, and get information about harmonic patterns. See example code at the end of the script for details.
init_params(pct_error, pct_asym, types, w_e, w_p, w_d)
Create a harmonic parameters object (used by xabcd_harmonic object for pattern validation and scoring).
Parameters:
pct_error (float) : Allowed % error of leg retracement ratio versus the defined harmonic ratio
pct_asym (float) : Allowed leg length/period asymmetry % (a leg is considered invalid if it is this % longer or shorter than the average length of the other legs)
types (array) : Array of pattern types to validate (1=Gartley, 2=Bat, 3=Butterfly, 4=Crab, 5=Shark, 6=Cypher)
w_e (float) : Weight of ratio % error (used in score calculation, dft = 1)
w_p (float) : Weight of PRZ confluence (used in score calculation, dft = 1)
w_d (float) : Weight of Point D / PRZ confluence (used in score calculation, dft = 1)
Returns: harmonic_params object instance. It is recommended to store and reuse this object for multiple xabcd_harmonic objects rather than creating new params objects unnecessarily.
init(x, a, b, c, d, params, tp, p)
Initialize an xabcd_harmonic object instance from a given set of points
If the pattern is valid, an xabcd_harmonic object instance is returned. If you want to specify your
own validation and scoring parameters, you can do so by passing a harmonic_params object (params).
Or, if you prefer to do your own validation, you can explicitly pass the harmonic pattern type (tp)
and validation will be skipped. You can also pass in an existing xabcd_harmonic instance if you wish
to re-initialize it (e.g. for re-validation and/or re-scoring).
Parameters:
x (point type from dlmysolutions/Pattern/1) : Point X
a (point type from dlmysolutions/Pattern/1) : Point A
b (point type from dlmysolutions/Pattern/1) : Point B
c (point type from dlmysolutions/Pattern/1) : Point C
d (point type from dlmysolutions/Pattern/1) : Point D
params (harmonic_params) : harmonic_params used to validate and score the pattern. Validation will be skipped if a type (tp) is explicitly passed in.
tp (int) : Pattern type
p (xabcd_harmonic) : xabcd_harmonic object instance to initialize (optional, for re-validation/re-scoring)
Returns: xabcd_harmonic object instance if a valid harmonic, else na
init(xX, xY, aX, aY, bX, bY, cX, cY, dX, dY, params, tp, p)
Initialize an xabcd_harmonic object instance from a given set of x and y coordinate values.
If the pattern is valid, an xabcd_harmonic object instance is returned. If you want to specify your
own validation and scoring parameters, you can do so by passing a harmonic_params object (params).
Or, if you prefer to do your own validation, you can explicitly pass the harmonic pattern type (tp)
and validation will be skipped. You can also pass in an existing xabcd_harmonic instance if you wish
to re-initialize it (e.g. for re-validation and/or re-scoring).
Parameters:
xX (int) : Point X bar index (required)
xY (float) : Point X price/level (required)
aX (int) : Point A bar index (required)
aY (float) : Point A price/level (required)
bX (int) : Point B bar index (required)
bY (float) : Point B price/level (required)
cX (int) : Point C bar index (required)
cY (float) : Point C price/level (required)
dX (int) : Point D bar index
dY (float) : Point D price/level
params (harmonic_params) : harmonic_params used to validate and score the pattern. Validation will be skipped if a type (tp) is explicitly passed in.
tp (int) : Pattern type
p (xabcd_harmonic) : xabcd_harmonic object instance to initialize (optional, for re-validation/re-scoring)
Returns: xabcd_harmonic object instance if a valid harmonic, else na
init(pattern, params, tp, p)
Initialize an xabcd_harmonic object instance from a given pattern
If the pattern is valid, an xabcd_harmonic object instance is returned. If you want to specify your
own validation and scoring parameters, you can do so by passing a harmonic_params object (params).
Or, if you prefer to do your own validation, you can explicitly pass the harmonic pattern type (tp)
and validation will be skipped. You can also pass in an existing xabcd_harmonic instance if you wish
to re-initialize it (e.g. for re-validation and/or re-scoring).
Parameters:
pattern (pattern type from dlmysolutions/Pattern/1) : Pattern
params (harmonic_params) : harmonic_params used to validate and score the pattern. Validation will be skipped if a type (tp) is explicitly passed in.
tp (int) : Pattern type
p (xabcd_harmonic) : xabcd_harmonic object instance to initialize (optional, for re-validation/re-scoring)
Returns: xabcd_harmonic object instance if a valid harmonic, else na
method get_name(p)
Get the pattern name
Namespace types: xabcd_harmonic
Parameters:
p (xabcd_harmonic) : Instance of xabcd_harmonic object
Returns: Pattern name (string)
method get_symbol(p)
Get the pattern symbol
Namespace types: xabcd_harmonic
Parameters:
p (xabcd_harmonic) : Instance of xabcd_harmonic object
Returns: Pattern symbol (1 byte string)
method get_pid(p)
Get the Pattern ID. Patterns of the same type with the same coordinates will have the same Pattern ID.
Namespace types: xabcd_harmonic
Parameters:
p (xabcd_harmonic) : Instance of xabcd_harmonic object
Returns: Pattern ID (string)
method set_target(p, target, target_lvl, calc_target)
Set value for a target. Use the calc_target parameter to automatically calculate the target for a specific harmonic ratio.
Namespace types: xabcd_harmonic
Parameters:
p (xabcd_harmonic) : Instance of xabcd_harmonic object
target (int) : Target (1 or 2)
target_lvl (float) : Target price/level (required if calc_target is not specified)
calc_target (string) : Target to auto calculate (required if target is not specified)
Options:
Returns: Target price/level (float)
method erase_pattern(p)
Erase the pattern
Namespace types: xabcd_harmonic
Parameters:
p (xabcd_harmonic) : Instance of xabcd_harmonic object
Returns: p
method draw_pattern(p, clr)
Draw the pattern
Namespace types: xabcd_harmonic
Parameters:
p (xabcd_harmonic) : Instance of xabcd_harmonic object
clr (color)
Returns: Pattern lines
method erase_label(p)
Erase the pattern label
Namespace types: xabcd_harmonic
Parameters:
p (xabcd_harmonic) : Instance of xabcd_harmonic object
Returns: p
method draw_label(p, clr, txt_clr, txt, tooltip)
Draw the pattern label. Default text is the pattern name.
Namespace types: xabcd_harmonic
Parameters:
p (xabcd_harmonic) : Instance of xabcd_harmonic object
clr (color) : Label color
txt_clr (color) : Text color
txt (string) : Label text
tooltip (string) : Tooltip text
Returns: Label
harmonic_params
Validation and scoring parameters for a Harmonic Pattern object (xabcd_harmonic)
Fields:
pct_error (series float) : Allowed % error of leg retracement ratio versus the defined harmonic ratio
pct_asym (series float)
types (array)
w_e (series float)
w_p (series float)
w_d (series float)
xabcd_harmonic
Harmonic Pattern object
Fields:
bull (series bool) : Bullish pattern flag
tp (series int)
x (point type from dlmysolutions/Pattern/1)
a (point type from dlmysolutions/Pattern/1)
b (point type from dlmysolutions/Pattern/1)
c (point type from dlmysolutions/Pattern/1)
d (point type from dlmysolutions/Pattern/1)
r_xb (series float)
re_xb (series float)
r_ac (series float)
re_ac (series float)
r_bd (series float)
re_bd (series float)
r_xd (series float)
re_xd (series float)
score (series float)
score_eAvg (series float)
score_prz (series float)
score_eD (series float)
prz_bN (series float)
prz_bF (series float)
prz_xN (series float)
prz_xF (series float)
t1Hit (series bool) : Target 1 flag
t1 (series float)
t2Hit (series bool)
t2 (series float)
sHit (series bool) : Stop flag
stop (series float) : Stop level
entry (series float) : Entry level
eHit (series bool)
e (point type from dlmysolutions/Pattern/1)
invalid_d (series bool)
pLines (array)
pLabel (series label)
pid (series string)
params (harmonic_params)
PatternLibrary "Pattern"
Pattern object definitions and functions. Easily draw and keep track of patterns, legs, and points.
Supported pattern types:
Type Leg validation # legs
"xabcd" Direction 3 or 4 (point D not required)
"zigzag" Direction >= 2
"free" None >= 2
Summary of exported types and associated methods/functions:
type point A point on the chart (x,y)
draw_label() Draw a point label
erase_label() Erase a point label
type leg A pattern leg (i.e. point A to point B)
leg_init() Initialize/instantiate a leg
draw() Draw a leg
erase() Erase a leg
leg_getLineTerms() Get the slope and y-intercept of a leg
leg_getPrice() Get price (Y) at a given bar index (X) within a leg
type pattern A pattern (set of at least 2 connected legs)
pattern_init() Initialize/instantiate a pattern
draw() Draw a pattern
erase() Erase a pattern
*See bottom of the script for example usage*
erase_label(this)
Delete the point label
Parameters:
this (point) : Point
Returns: Void
draw_label(this, position, clr, transp, txt_clr, txt, tooltip, size)
Draw the point label
Parameters:
this (point) : Point
position (string)
clr (color)
transp (float)
txt_clr (color)
txt (string)
tooltip (string)
size (string)
Returns: line
leg_init(a, b, prev, next, line)
Initialize a pattern leg
Parameters:
a (point) : Point A (required)
b (point) : Point B (required)
prev (leg) : Previous leg
next (leg) : Next leg
line (line) : Line
Returns: New instance of leg object
erase(this)
Delete the pattern leg
Parameters:
this (leg) : Leg
Returns: Void
erase(this)
Delete the pattern lines
Parameters:
this (pattern) : Pattern
Returns: Void
draw(this, clr, style, transp, width)
Draw the pattern leg
Parameters:
this (leg) : Leg
clr (color) : Color
style (string) : Style ("solid", "dotted", "dashed", "arrowleft", "arrowright")
transp (float) : Transparency
width (int) : Width
Returns: line
draw(this, clr, style, transp, width)
Draw the pattern
Parameters:
this (pattern) : Pattern
clr (color) : Color
style (string) : Style ("solid", "dotted", "dashed", "arrowleft", "arrowright")
transp (float) : Transparency
width (int) : Width
Returns: line
leg_getLineTerms(this)
Get the slope and y-intercept of a leg
Parameters:
this (leg) : Leg
Returns:
leg_getPrice(this, index)
Get the price (Y) at a given bar index (X) within the leg
Parameters:
this (leg) : Leg
index (int) : Bar index
Returns: Price (float)
pattern_init(legs, tp, name, subType, pid)
Initialize a pattern object from a given set of legs
Parameters:
legs (array) : Array of pattern legs (required)
tp (string) : Pattern type ("zigzag", "xabcd", or "free". dft = "free")
name (string) : Pattern name
subType (string) : Pattern subtype
pid (string) : Pattern Identifier string
Returns: New instance of pattern object, if one was successfully created
pattern_init(points, tp, name, subType, pid)
Initialize a pattern object from a given set of points
Parameters:
points (array)
tp (string) : Pattern type ("zigzag", "xabcd", or "free". dft = "free")
name (string) : Pattern name
subType (string) : Pattern subtype
pid (string) : Pattern Identifier string
Returns: New instance of pattern object, if one was successfully created
point
A point on the chart (x,y)
Fields:
x (series int) : Bar index (x coordinate)
y (series float)
label (series label)
leg
A pattern leg (point A to point B)
Fields:
a (point) : Point A
b (point)
deltaX (series int)
deltaY (series float)
prev (leg)
next (leg)
retrace (series float)
line (series line)
pattern
A pattern (set of at least 2 connected legs)
Fields:
legs (array)
type (series string)
subType (series string)
name (series string)
pid (series string)
DrawLibrary "Draw"
Draw patterns, lines, labels, shapes etc.
pat_colors(bull, buLn, beLn, ltxt)
Parameters:
bull (bool)
buLn (color)
beLn (color)
ltxt (color)
size(size)
Parameters:
size (string)
label_style(style)
Parameters:
style (string)
line_style(style)
Parameters:
style (string)
font_size(size)
Parameters:
size (string)
xabcd(xX, xY, aX, aY, bX, bY, cX, cY, dX, dY, iE, bull, bu, be)
Draw XABCD pattern
Parameters:
xX (int)
xY (float)
aX (int)
aY (float)
bX (int)
bY (float)
cX (int)
cY (float)
dX (int)
dY (float)
iE (float)
bull (bool)
bu (color)
be (color)
xabcd_inProgress(bull, type, tLimit, entry, stop, t1, t2, bcNt, bcFt, xaNt, xaFt, xX, xY, aY, bX, bY, cY, dX, dY, cBu, cBe, lTxt)
draw PRZ, entry, stop, targets, and projected reversal paths for XABCD pattern
Parameters:
bull (bool)
type (int)
tLimit (int)
entry (float)
stop (float)
t1 (float)
t2 (float)
bcNt (float)
bcFt (float)
xaNt (float)
xaFt (float)
xX (int)
xY (float)
aY (float)
bX (int)
bY (float)
cY (float)
dX (int)
dY (float)
cBu (color)
cBe (color)
lTxt (color)
xabcd_incInProgress(bull, type, tLimit, entry, xX, xY, aY, bX, bY, cX, cY, dY, cBu, cBe, lTxt)
Parameters:
bull (bool)
type (int)
tLimit (int)
entry (float)
xX (int)
xY (float)
aY (float)
bX (int)
bY (float)
cX (int)
cY (float)
dY (float)
cBu (color)
cBe (color)
lTxt (color)
xabcd_inProgress2(bull, tLimit, entry, stop, t1, t2, xadl, bcdl, xcdl, xX, xY, bX, bY, dX, dY, cBu, cBe, lTxt)
draw PRZ, entry, stop, targets, and projected reversal paths for XABCD pattern
Parameters:
bull (bool)
tLimit (int)
entry (float)
stop (float)
t1 (float)
t2 (float)
xadl (float)
bcdl (float)
xcdl (float)
xX (int)
xY (float)
bX (int)
bY (float)
dX (int)
dY (float)
cBu (color)
cBe (color)
lTxt (color)
eHitLbl(x, e, dX, dY, bull, lOnly)
Draw entry hit label
Parameters:
x (int)
e (float)
dX (int)
dY (float)
bull (bool)
lOnly (bool)
tHitLbl(x, tgt, eX, eY, bull)
Draw target hit label
Parameters:
x (int)
tgt (float)
eX (int)
eY (float)
bull (bool)
sHitLbl(x, s, eX, eY, bull)
Draw stop hit label
Parameters:
x (int)
s (float)
eX (int)
eY (float)
bull (bool)
level(y, x, type, length, extend, padding, b_style, colr, txt_color, txt, txt_loc, txt_size)
Draw a level (box)
Parameters:
y (float)
x (int)
type (int)
length (int)
extend (string)
padding (float)
b_style (string)
colr (color)
txt_color (color)
txt (string)
txt_loc (string)
txt_size (string)
incTtTxt(tp, name, xbr, xbre, acr, acre, bcN, bcF, xaN, xaF, score, e)
Parameters:
tp (int)
name (string)
xbr (float)
xbre (float)
acr (float)
acre (float)
bcN (float)
bcF (float)
xaN (float)
xaF (float)
score (float)
e (float)
TALibrary "TA"
General technical analysis functions
div_bull(pS, iS, cp_length_after, cp_length_before, pivot_length, lookback, lookback_pivs, no_broken, pW, iW, hidW, regW)
Test for bullish divergence
Parameters:
pS (float) : Price series (float)
iS (float) : Indicator series (float)
cp_length_after (simple int) : Bars after current (divergent) pivot low to be considered a valid pivot (optional int)
cp_length_before (simple int) : Bars before current (divergent) pivot low to be considered a valid pivot (optional int)
pivot_length (simple int) : Bars before and after prior pivot low to be considered valid pivot (optional int)
lookback (simple int) : Bars back to search for prior pivot low (optional int)
lookback_pivs (simple int) : Pivots back to search for prior pivot low (optional int)
no_broken (simple bool) : Flag to only consider divergence valid if the pivot-to-pivot trendline is unbroken (optional bool)
pW (simple float) : Weight of change in price, used in degree of divergence calculation (optional float)
iW (simple float) : Weight of change in indicator, used in degree of divergence calculation (optional float)
hidW (simple float) : Weight of hidden divergence, used in degree of divergence calculation (optional float)
regW (simple float) : Weight of regular divergence, used in degree of divergence calculation (optional float)
Returns:
flag = true if divergence exists (bool)
degree = degree (strength) of divergence (float)
type = 1 = regular, 2 = hidden (int)
lx1 = x coordinate 1 (int)
ly1 = y coordinate 1 (float)
lx2 = x coordinate 2 (int)
ly2 = y coordinate 2 (float)
div_bear(pS, iS, cp_length_after, cp_length_before, pivot_length, lookback, lookback_pivs, no_broken, pW, iW, hidW, regW)
Test for bearish divergence
Parameters:
pS (float) : Price series (float)
iS (float) : Indicator series (float)
cp_length_after (simple int) : Bars after current (divergent) pivot high to be considered a valid pivot (optional int)
cp_length_before (simple int) : Bars before current (divergent) pivot highto be considered a valid pivot (optional int)
pivot_length (simple int) : Bars before and after prior pivot high to be considered valid pivot (optional int)
lookback (simple int) : Bars back to search for prior pivot high (optional int)
lookback_pivs (simple int) : Pivots back to search for prior pivot high (optional int)
no_broken (simple bool) : Flag to only consider divergence valid if the pivot-to-pivot trendline is unbroken (optional bool)
pW (simple float) : Weight of change in price, used in degree of divergence calculation (optional float)
iW (simple float) : Weight of change in indicator, used in degree of divergence calculation (optional float)
hidW (simple float) : Weight of hidden divergence, used in degree of divergence calculation (optional float)
regW (simple float) : Weight of regular divergence, used in degree of divergence calculation (optional float)
Returns:
flag = true if divergence exists (bool)
degree = degree (strength) of divergence (float)
type = 1 = regular, 2 = hidden (int)
lx1 = x coordinate 1 (int)
ly1 = y coordinate 1 (float)
lx2 = x coordinate 2 (int)
ly2 = y coordinate 2 (float)
test_cd(cd, bc, xa, xc, ad, pErr, p_types)
Validate CD leg of XABCD
Parameters:
cd (float)
bc (float)
xa (float)
xc (float)
ad (float)
pErr (float)
p_types (array)
pat_xabcd_testSym(xax, abx, bcx, cdx, pAsym)
Validate ΔX symmetry of XABCD pattern
Parameters:
xax (int)
abx (int)
bcx (int)
cdx (int)
pAsym (float)
harmonic_xabcd_validate(xX, xY, aX, aY, bX, bY, cX, cY, dX, dY, pErr, pAsym, gart, bat, bfly, crab, shark, cyph)
Validate harmonic XABCD pattern
Parameters:
xX (int) : X coordinate of point X (int)
xY (float) : Y coordinate of point X (float)
aX (int) : X coordinate of point A (int)
aY (float) : Y coordinate of point A (float)
bX (int) : X coordinate of point B (int)
bY (float) : Y coordinate of point B (float)
cX (int) : X coordinate of point C (int)
cY (float) : Y coordinate of point C (float)
dX (int) : X coordinate of point D (int)
dY (float) : Y coordinate of point D (float)
pErr (float) : Acceptable percent error of leg ratios (does not apply to legs defined within a range) (float)
pAsym (float) : Acceptable percent asymmetry of leg ΔX (each leg tested against average ΔX of prior legs) (float)
gart (bool) : Flag to validate Gartley pattern (bool)
bat (bool) : Flag to validate Bat pattern (bool)
bfly (bool) : Flag to validate Butterfly pattern (bool)
crab (bool) : Flag to validate Crab pattern (bool)
shark (bool) : Flag to validate Shark pattern (bool)
cyph (bool) : Flag to validate Cypher pattern (bool)
Returns:
flag = true if valid harmonic
t1 = true if valid gartley
t2 = true if valid bat
t3 = true if valid butterfly
t4 = true if valid crab
t5 = true if valid shark
t6 = true if valid cypher
harmonic_xabcd_validateIncomplete(xX, xY, aX, aY, bX, bY, cX, cY, pErr, pAsym, gart, bat, bfly, crab, shark, cyph)
Validate the first 3 legs of a harmonic XABCD pattern
Parameters:
xX (int) : X coordinate of point X (int)
xY (float) : Y coordinate of point X (float)
aX (int) : X coordinate of point A (int)
aY (float) : Y coordinate of point A (float)
bX (int) : X coordinate of point B (int)
bY (float) : Y coordinate of point B (float)
cX (int) : X coordinate of point C (int)
cY (float) : Y coordinate of point C (float)
pErr (float) : Acceptable percent error of leg ratios (does not apply to legs defined within a range) (float)
pAsym (float) : Acceptable percent asymmetry of leg ΔX (each leg tested against average ΔX of prior legs) (float)
gart (bool) : Flag to validate Gartley pattern (bool)
bat (bool) : Flag to validate Bat pattern (bool)
bfly (bool) : Flag to validate Butterfly pattern (bool)
crab (bool) : Flag to validate Crab pattern (bool)
shark (bool) : Flag to validate Shark pattern (bool)
cyph (bool) : Flag to validate Cypher pattern (bool)
Returns:
flag = true if valid harmonic
t1 = true if valid gartley
t2 = true if valid bat
t3 = true if valid butterfly
t4 = true if valid crab
t5 = true if valid shark
t6 = true if valid cypher
harmonic_xabcd_prz(type, xY, aY, bY, cY)
Get the potential reversal zone (PRZ) levels of a harmonic XABCD pattern
Parameters:
type (int) : Harmonic pattern type (int - 1 = Gartley, 2 = Bat, 3 = Butterfly, 4 = Crab, 5 = Shark, 6 = Cypher)
xY (float) : Y coordinate of point X (float)
aY (float) : Y coordinate of point A (float)
bY (float) : Y coordinate of point B (float)
cY (float) : Y coordinate of point C (float)
Returns:
bc_u = nearest BC retracement/extension level (nearest to point C)
bc_l = farthest BC retracement/extension level (nearest to point C)
xa_u = nearest XA retracement/extension level (or the only XA level, if applicable)
xa_l = farthest XA retracement/extension level (or na if not applicable)
harmonic_xabcd_przClosest(l1, l2, l3, l4)
Get the confluent PRZ levels (i.e. the two closest PRZ levels)
Order of arguments does not matter
Parameters:
l1 (float) : level 1 (float)
l2 (float) : level 2 (float)
l3 (float) : level 3 (float)
l4 (float) : level 4 (optional, float)
Returns:
lL = lower confluent PRZ level
lH = higher confluent PRZ level
harmonic_xabcd_przRange(l1, l2, l3, l4)
Get upper and lower PRZ levels
Parameters:
l1 (float)
l2 (float)
l3 (float)
l4 (float)
harmonic_xabcd_eD(cpl1, cpl2, xY, aY, dY)
Measure closeness of D to either of the two closest PRZ levels, relative to height of the XA leg
Parameters:
cpl1 (float)
cpl2 (float)
xY (float)
aY (float)
dY (float)
harmonic_xabcd_przScore(xY, aY, l1, l2, l3, l4)
Measure the closeness of the two closest PRZ levels, relative to the height of the XA leg
Parameters:
xY (float)
aY (float)
l1 (float)
l2 (float)
l3 (float)
l4 (float)
harmonic_xabcd_rAndE(type, l, l1, l2)
Get the ratio of two pattern legs, and the percent error from the theoretical harmonic ratio
Order of arguments does not matter
Parameters:
type (int) : Harmonic pattern type (int - 1 = Gartley, 2 = Bat, 3 = Butterfly, 4 = Crab)
l (string) : Leg ID ("xab", "abc", "bcd", or "xad") (string)
l1 (float) : Line 1 height (float)
l2 (float) : Line 2 height (float)
Returns:
harmonic_xabcd_eAvg(xbre, acre, bdre, xdre, xcdre)
Get the avg retracement ratio % error
Parameters:
xbre (float)
acre (float)
bdre (float)
xdre (float)
xcdre (float)
pat_xabcd_asym(xX, aX, bX, cX, dX)
Get the avg asymmetry %
Parameters:
xX (int)
aX (int)
bX (int)
cX (int)
dX (int)
harmonic_xabcd_entry(t, tp, xY, aY, bY, cY, dY, e_afterC, e_lvlc, e_afterD, e_lvldPct)
Get potential entry levels for a harmonic XABCD pattern
Parameters:
t (bool)
tp (int)
xY (float)
aY (float)
bY (float)
cY (float)
dY (float)
e_afterC (bool)
e_lvlc (string)
e_afterD (bool)
e_lvldPct (float)
xabcd_entryHit(t, afterC, afterD, dX, e_afterC, e_afterD, dValBars)
Determine if entry level was reached. Assumes pattern is active/not timed out.
Parameters:
t (bool)
afterC (float)
afterD (float)
dX (int)
e_afterC (bool)
e_afterD (bool)
dValBars (int)
pat_xabcd_validate(xX, xY, aX, aY, bX, bY, cX, cY, dX, dY, xab, abc, bcd, xad, xcd, pErr, pAsym)
Validate custom XABCD pattern
Parameters:
xX (int) : X coordinate of point X (int)
xY (float) : Y coordinate of point X (float)
aX (int) : X coordinate of point A (int)
aY (float) : Y coordinate of point A (float)
bX (int) : X coordinate of point B (int)
bY (float) : Y coordinate of point B (float)
cX (int) : X coordinate of point C (int)
cY (float) : Y coordinate of point C (float)
dX (int) : X coordinate of point D (int)
dY (float) : Y coordinate of point D (float)
xab (float)
abc (float)
bcd (float)
xad (float)
xcd (float)
pErr (float) : Acceptable percent error of leg ratios (does not apply to legs defined within a range) (float)
pAsym (float) : Acceptable percent asymmetry of leg ΔX (each leg tested against average ΔX of prior legs) (float)
Returns: TRUE if pattern is valid
pat_xabcd_validateIncomplete(xX, xY, aX, aY, bX, bY, cX, cY, xab, abc, pErr, pAsym)
Validate the first 3 legs of a custom XABCD pattern
Parameters:
xX (int) : X coordinate of point X (int)
xY (float) : Y coordinate of point X (float)
aX (int) : X coordinate of point A (int)
aY (float) : Y coordinate of point A (float)
bX (int) : X coordinate of point B (int)
bY (float) : Y coordinate of point B (float)
cX (int) : X coordinate of point C (int)
cY (float) : Y coordinate of point C (float)
xab (float)
abc (float)
pErr (float) : Acceptable percent error of leg ratios (does not apply to legs defined within a range) (float)
pAsym (float) : Acceptable percent asymmetry of leg ΔX (each leg tested against average ΔX of prior legs) (float)
Returns: TRUE if first 3 legs are valid
pat_xabcd_prz(xY, aY, bY, cY, xad, bcd, xcd)
Get the potential reversal zone (PRZ) levels of a custom XABCD pattern
Parameters:
xY (float) : Y coordinate of point X (float)
aY (float) : Y coordinate of point A (float)
bY (float) : Y coordinate of point B (float)
cY (float) : Y coordinate of point C (float)
xad (float)
bcd (float)
xcd (float)
Returns:
pat_xabcd_avgDev(xX, xY, aX, aY, bX, bY, cX, cY, dX, dY)
Get the average deviation of an XABCD pattern
Parameters:
xX (int)
xY (float)
aX (int)
aY (float)
bX (int)
bY (float)
cX (int)
cY (float)
dX (int)
dY (float)
harmonic_xabcd_score(tp, xX, xY, aX, aY, bX, bY, cX, cY, dX, dY)
Get score values for a pattern
Parameters:
tp (int)
xX (int)
xY (float)
aX (int)
aY (float)
bX (int)
bY (float)
cX (int)
cY (float)
dX (int)
dY (float)
harmonic_xabcd_scoreTot(asym, eavg, przscore, eD, tp, w_a, w_e, w_p, w_d)
Get total weighted score value for a pattern
Parameters:
asym (float)
eavg (float)
przscore (float)
eD (float)
tp (int)
w_a (float)
w_e (float)
w_p (float)
w_d (float)
harmonic_xabcd_targets(xY, aY, bY, cY, dY, tgt1, tgt2, tgt3)
Get target level
Parameters:
xY (float)
aY (float)
bY (float)
cY (float)
dY (float)
tgt1 (string)
tgt2 (string)
tgt3 (string)
harmonic_xabcd_stop(stop, stopPct, bull, xY, dY, upper, lower, t1, eY)
Get stop level
Parameters:
stop (string)
stopPct (float)
bull (bool)
xY (float)
dY (float)
upper (float)
lower (float)
t1 (float)
eY (float)
harmonic_xabcd_fibDispTxt(tp)
Get fib ratio display text
Parameters:
tp (int)
harmonic_xabcd_symbol(tp)
Get pattern symbol
Parameters:
tp (int)
pat_xabcd(x_is_low, pivot_length, source, conf_length, incomplete)
Determine if an XABCD pattern has just completed (i.e. point D is on the previous bar)
Parameters:
x_is_low (bool) : Flag to determine if point X is a low pivot, i.e. bullish pattern (bool, dft = true)
pivot_length (int) : Number of bars before and after a valid pivot (int, dft = 5)
source (float) : Source series (float, dft = na, will use high and low series)
conf_length (int) : Number of trailing bars after pivot point D to confirm a valid pattern (int, dft = 1)
incomplete (bool) : Flag to return an incomplete XABC pattern (bool, dft = false)
Returns:
flag = true if valid XABCD pattern completed on previous bar
xx = X coordinate of point X (int)
xy = Y coordinate of point X (float)
ax = X coordinate of point A (int)
ay = Y coordinate of point A (float)
bx = X coordinate of point B (int)
by = Y coordinate of point B (float)
cx = X coordinate of point C (int)
cy = Y coordinate of point C (float)
dx = X coordinate of point D (int)
dy = Y coordinate of point D (float)
pat_xabcdIncomplete(x_is_low, pivot_length, source, conf_length)
Determine if an XABCD pattern is in progress (point C was just confirmed)
Parameters:
x_is_low (bool) : Flag to determine if point X is a low pivot, i.e. bullish M pattern (bool, dft = true)
pivot_length (int) : Number of bars before and after a valid pivot (int, dft = 5)
source (float) : Source series (float, dft = na, will use high and low series)
conf_length (int) : Number of trailing bars after pivot point D to confirm a valid pattern (int, dft = 1)
Returns:
flag = true if valid XABC pattern completed on bar_index
xx = X coordinate of point X (int)
xy = Y coordinate of point X (float)
ax = X coordinate of point A (int)
ay = Y coordinate of point A (float)
bx = X coordinate of point B (int)
by = Y coordinate of point B (float)
cx = X coordinate of point C (int)
cy = Y coordinate of point C (float)
dx = X coordinate of point D (int)
dy = Y coordinate of point D (float)
success(eX, stop, t1, t2)
Determine if trade is successful
Parameters:
eX (int) : Entry bar index (int)
stop (float) : Stop level (float)
t1 (float) : Target 1 level (float)
t2 (float) : Target 2 level (float)
Returns:
tradeClosed(eX, eY, stop, t1h, t2h, t1, t2)
Determine if Target or Stop was hit on the current bar
Parameters:
eX (int)
eY (float)
stop (float)
t1h (bool)
t2h (bool)
t1 (float)
t2 (float)
TrigLibrary "Trig"
Trigonometric functions
rt_get_angleAlpha(a, b, c, deg)
Get angle α of a right triangle, given the lengths of its sides
Parameters:
a (float) : length of leg a (float)
b (float) : length of leg b (float)
c (float) : length of hypotenuse (float)
deg (simple bool) : flag to return angle in degrees (bool - default = false)
Returns: angle α in radians (or degrees if deg == true)
rt_get_angleAlphaFromLine(x1, y1, x2, y2, l, deg)
Get angle α of a right triangle formed by the given line
Parameters:
x1 (int) : x coordinate 1 (int - optional, required if argument l is not specified)
y1 (float) : y coordinate 1 (float - optional, required if argument l is not specified)
x2 (int) : x coordinate 2 (int - optional, required if argument l is not specified)
y2 (float) : y coordinate 2 (float - optional, required if argument l is not specified)
l (line) : line object (line - optional, required if x1, y1, x2, and y2 agruments are not specified)
deg (simple bool) : flag to return angle in degrees (bool - default = false)
Returns: angle α in radians (or degrees if deg == true)
rt_get_angleBeta(a, b, c, deg)
Get angle β of a right triangle, given the lengths of its sides
Parameters:
a (float) : length of leg a (float)
b (float) : length of leg b (float)
c (float) : length of hypotenuse (float)
deg (simple bool) : flag to return angle in degrees (bool - default = false)
Returns: angle β in radians (or degrees if deg == true)
rt_get_angleBetaFromLine(x1, y1, x2, y2, l, deg)
Get angle β of a right triangle formed by the given line
Parameters:
x1 (int) : x coordinate 1 (int - optional, required if argument l is not specified)
y1 (float) : y coordinate 1 (float - optional, required if argument l is not specified)
x2 (int) : x coordinate 2 (int - optional, required if argument l is not specified)
y2 (float) : y coordinate 2 (float - optional, required if argument l is not specified)
l (line) : line object (line - optional, required if x1, y1, x2, and y2 agruments are not specified)
deg (simple bool) : flag to return angle in degrees (bool - default = false)
Returns: angle β in radians (or degrees if deg == true)
AlgebraLibrary "Algebra"
line_fromXy(x1, y1, x2, y2)
Get line slope and y-intercept from coordinates
Parameters:
x1 (int) : x coordinate 1 (int - bar index)
y1 (float) : y coordinate 1 (float - price/value)
x2 (int) : x coordinate 2 (int - bar index)
y2 (float) : y coordinate 2 (float - price/value)
Returns: of line
line_getPrice(x, slope, yInt)
Get price at X coordinate, given line slope and y-intercept
Parameters:
x (int) : x coordinate to solve for y (int - bar index)
slope (float) : slope of line (float)
yInt (float) : y-intercept of line (float)
Returns: y (price/value)
line_getPrice_fromXy(x, x1, y1, x2, y2)
Get price at X coordinate, given two points on a line
Parameters:
x (int) : x coordinate to solve for y (int - bar index)
x1 (int) : x coordinate 1 (int - bar index)
y1 (float) : y coordinate 1 (float - price/value)
x2 (int) : x coordinate 2 (int - bar index)
y2 (float) : y coordinate 2 (float - price/value)
Returns: y (price/value)
line_getRtSides(x1, y1, x2, y2, l)
Get length of sides of a right triangle formed by a given line
Parameters:
x1 (int) : x coordinate 1 (int - optional, required if argument l is not specified)
y1 (float) : y coordinate 1 (float - optional, required if argument l is not specified)
x2 (int) : x coordinate 2 (int - optional, required if argument l is not specified)
y2 (float) : y coordinate 2 (float - optional, required if argument l is not specified)
l (line) : line object (line - optional, required if x1, y1, x2, y2 agruments are not specified)
Returns:
line_length(x1, y1, x2, y2, l)
Get length of line, given a line object or two sets of coordinates
Parameters:
x1 (int) : x coordinate 1 (int - optional, required if argument l is not specified)
y1 (float) : y coordinate 1 (float - optional, required if argument l is not specified)
x2 (int) : x coordinate 2 (int - optional, required if argument l is not specified)
y2 (float) : y coordinate 2 (float - optional, required if argument l is not specified)
l (line) : line object (line - optional, required if x1, y1, x2, y2 agruments are not specified)
Returns: length of line (float)
FibonacciLibrary "Fibonacci"
General Fibonacci functions. Get fib numbers, ratios, etc.
fib_derived(f, precision)
Get the precise Fibonacci ratio, to the specified number of decimal places
Parameters:
f (float) : Fibonacci ratio (string, in form #.###)
precision (simple int) : Number of decimal places (optional int, dft = 16, max = 32)
Returns: Precise Fibonacci ratio (float)
* Deprecated (use fib_precise() instead), but keeping it here for science / experimenting with derivations
fib_precise(f, precision)
Get the precise Fibonacci ratio, to the specified number of decimal places
Parameters:
f (float) : Fibonacci ratio (string, in form #.###)
precision (simple int) : Number of decimal places (optional int, dft = 16, max = 16)
Returns: Precise Fibonacci ratio (float)
fib_from_string(r)
Get fib ratio value from string
Parameters:
r (string) : Fib ratio string (e.g. ".618")
Returns: Fibonacci ratio value (float)
fib_n(n)
Calculate the Nth number in the Fibonacci sequence
Parameters:
n (int) : Index/number in sequence (int)
Returns: Fibonacci number (int)
UtilitiesLibrary "Utilities"
General utilities
print_series(s, skip_na, position, show_index, from_index, to_index)
Print series values
Parameters:
s (string) : Series (string)
skip_na (simple bool) : Flag to skip na values (optional bool, dft = false)
position (simple string) : Position to print the Table (optional string, dft = position.bottom_center)
show_index (simple bool) : Flag to show series indices (optional bool, dft = true)
from_index (int) : First index to print (optional int, dft = 0)
to_index (int) : Last index to print (optional int, dft = last_bar_index)
Returns: Table object, if series was printed
print(v, position, at_index)
Print value
Parameters:
v (string) : Value (string)
position (simple string) : Position to print the Table (optional string, dft = position.bottom_center)
at_index (int) : Index at which to print (optional int, dft = bar_index)
Returns: Table object, if value was printed
print(v, position, at_index)
Print value
Parameters:
v (int) : Value (int)
position (simple string) : Position to print the Table (optional string, dft = position.bottom_center)
at_index (int) : Index at which to print (optional int, dft = bar_index)
Returns: Table object, if value was printed
print(v, position, at_index)
Print value
Parameters:
v (float) : Value (float)
position (simple string) : Position to print the Table (optional string, dft = position.bottom_center)
at_index (int) : Index at which to print (optional int, dft = bar_index)
Returns: Table object, if value was printed
print(v, position, at_index)
Print value
Parameters:
v (bool) : Value (bool)
position (simple string) : Position to print the Table (optional string, dft = position.bottom_center)
at_index (int) : Index at which to print (optional int, dft = bar_index)
Returns: Table object, if value was printed
boolToIntArr(a)
return array of offsets (int) of true values
Parameters:
a (array)
intToBoolArr(a, n)
Parameters:
a (array)
n (int)
mt_elliott_coreLibrary "mt_elliott_core"
ewo(maFastLen, maSlowLen, smoothLen)
Parameters:
maFastLen (simple int)
maSlowLen (simple int)
smoothLen (simple int)
mt_phase_num(_len, _minGap)
Parameters:
_len (simple int)
_minGap (simple float)
mt_color_from_phase(_len, _minGap)
Parameters:
_len (simple int)
_minGap (simple float)
mt_phase_progress_pct(_len, _minGap)
Parameters:
_len (simple int)
_minGap (simple float)
anchor_p1_close(len, minGap)
Parameters:
len (simple int)
minGap (simple float)
anchor_p1_pivot(len, minGap)
Parameters:
len (simple int)
minGap (simple float)
row_group_from_ewo(ewoValue, atrValue, strongPct, neutralPct)
Parameters:
ewoValue (float)
atrValue (float)
strongPct (simple float)
neutralPct (simple float)
wave_event_pivot_aligned(ewoSeries, left, right, divTolPct, minBarsGap)
Parameters:
ewoSeries (float)
left (simple int)
right (simple int)
divTolPct (simple float)
minBarsGap (simple int)
phx_liq_tlLibrary "phx_liq_tl"
new_state()
update(st, len, cup, cdn, space, proximity_pct, shs)
Parameters:
st (LTState)
len (int)
cup (color)
cdn (color)
space (float)
proximity_pct (float)
shs (bool)
LTState
Fields:
upln (array)
dnln (array)
upBroken (series bool)
dnBroken (series bool)
phx_kroLibrary "phx_kro"
compute(src, bandwidth, bbwidth, sdLook, sdMult, obos_mult)
Parameters:
src (float)
bandwidth (int)
bbwidth (float)
sdLook (int)
sdMult (float)
obos_mult (float)
start_flags(src, bandwidth, bbwidth)
Parameters:
src (float)
bandwidth (int)
bbwidth (float)
KROFeed
Fields:
Wave (series float)
is_green (series bool)
is_red (series bool)
band_width (series float)
band_width_sma (series float)
band_width_std (series float)
is_hyper_wide (series bool)
wave_sma (series float)
wave_std (series float)
wave_ob_threshold (series float)
wave_os_threshold (series float)
is_overbought (series bool)
is_oversold (series bool)
is_oversold_confirmed (series bool)
is_overbought_confirmed (series bool)
enhanced_os_confirmed (series bool)
enhanced_ob_confirmed (series bool)
triple_green_transition (series bool)
triple_red_transition (series bool)
startwave_bull (series bool)
startwave_bear (series bool)
phx_fvgfvg generator 4h and current time frame
library to import fvg from 4h with midle line and proximity support and resistance
JK_Traders_Reality_LibLibrary "JK_Traders_Reality_Lib"
This library contains common elements used in Traders Reality scripts
calcPvsra(pvsraVolume, pvsraHigh, pvsraLow, pvsraClose, pvsraOpen, redVectorColor, greenVectorColor, violetVectorColor, blueVectorColor, darkGreyCandleColor, lightGrayCandleColor)
calculate the pvsra candle color and return the color as well as an alert if a vector candle has apperared.
Situation "Climax"
Bars with volume >= 200% of the average volume of the 10 previous chart TFs, or bars
where the product of candle spread x candle volume is >= the highest for the 10 previous
chart time TFs.
Default Colors: Bull bars are green and bear bars are red.
Situation "Volume Rising Above Average"
Bars with volume >= 150% of the average volume of the 10 previous chart TFs.
Default Colors: Bull bars are blue and bear are violet.
Parameters:
pvsraVolume (float) : the instrument volume series (obtained from request.sequrity)
pvsraHigh (float) : the instrument high series (obtained from request.sequrity)
pvsraLow (float) : the instrument low series (obtained from request.sequrity)
pvsraClose (float) : the instrument close series (obtained from request.sequrity)
pvsraOpen (float) : the instrument open series (obtained from request.sequrity)
redVectorColor (simple color) : red vector candle color
greenVectorColor (simple color) : green vector candle color
violetVectorColor (simple color) : violet/pink vector candle color
blueVectorColor (simple color) : blue vector candle color
darkGreyCandleColor (simple color) : regular volume candle down candle color - not a vector
lightGrayCandleColor (simple color) : regular volume candle up candle color - not a vector
@return
adr(length, barsBack)
Parameters:
length (simple int) : how many elements of the series to calculate on
barsBack (simple int) : starting possition for the length calculation - current bar or some other value eg last bar
@return adr the adr for the specified lenght
adrHigh(adr, fromDo)
Calculate the ADR high given an ADR
Parameters:
adr (float) : the adr
fromDo (simple bool) : boolean flag, if false calculate traditional adr from high low of today, if true calcualte from exchange midnight
@return adrHigh the position of the adr high in price
adrLow(adr, fromDo)
Parameters:
adr (float) : the adr
fromDo (simple bool) : boolean flag, if false calculate traditional adr from high low of today, if true calcualte from exchange midnight
@return adrLow the position of the adr low in price
splitSessionString(sessXTime)
given a session in the format 0000-0100:23456 split out the hours and minutes
Parameters:
sessXTime (simple string) : the session time string usually in the format 0000-0100:23456
@return
calcSessionStartEnd(sessXTime, gmt)
calculate the start and end timestamps of the session
Parameters:
sessXTime (simple string) : the session time string usually in the format 0000-0100:23456
gmt (simple string) : the gmt offset string usually in the format GMT+1 or GMT+2 etc
@return
drawOpenRange(sessXTime, sessXcol, showOrX, gmt)
draw open range for a session
Parameters:
sessXTime (simple string) : session string in the format 0000-0100:23456
sessXcol (simple color) : the color to be used for the opening range box shading
showOrX (simple bool) : boolean flag to toggle displaying the opening range
gmt (simple string) : the gmt offset string usually in the format GMT+1 or GMT+2 etc
@return void
drawSessionHiLo(sessXTime, showRectangleX, showLabelX, sessXcolLabel, sessXLabel, gmt, sessionLineStyle)
Parameters:
sessXTime (simple string) : session string in the format 0000-0100:23456
showRectangleX (simple bool)
showLabelX (simple bool)
sessXcolLabel (simple color) : the color to be used for the hi/low lines and label
sessXLabel (simple string) : the session label text
gmt (simple string) : the gmt offset string usually in the format GMT+1 or GMT+2 etc
sessionLineStyle (simple string) : the line stile for the session high low lines
@return void
calcDst()
calculate market session dst on/off flags
@return indicating if DST is on or off for a particular region
timestampPreviousDayOfWeek(previousDayOfWeek, hourOfDay, gmtOffset, oneWeekMillis)
Timestamp any of the 6 previous days in the week (such as last Wednesday at 21 hours GMT)
Parameters:
previousDayOfWeek (simple string) : Monday or Satruday
hourOfDay (simple int) : the hour of the day when psy calc is to start
gmtOffset (simple string) : the gmt offset string usually in the format GMT+1 or GMT+2 etc
oneWeekMillis (simple int) : the amount if time for a week in milliseconds
@return the timestamp of the psy level calculation start time
getdayOpen()
get the daily open - basically exchange midnight
@return the daily open value which is float price
newBar(res)
new_bar: check if we're on a new bar within the session in a given resolution
Parameters:
res (simple string) : the desired resolution
@return true/false is a new bar for the session has started
toPips(val)
to_pips Convert value to pips
Parameters:
val (float) : the value to convert to pips
@return the value in pips
rLabel(ry, rtext, rstyle, rcolor, valid, labelXOffset)
a function that draws a right aligned lable for a series during the current bar
Parameters:
ry (float) : series float the y coordinate of the lable
rtext (simple string) : the text of the label
rstyle (simple string) : the style for the lable
rcolor (simple color) : the color for the label
valid (simple bool) : a boolean flag that allows for turning on or off a lable
labelXOffset (int) : how much to offset the label from the current position
rLabelOffset(ry, rtext, rstyle, rcolor, valid, labelOffset)
a function that draws a right aligned lable for a series during the current bar
Parameters:
ry (float) : series float the y coordinate of the lable
rtext (string) : the text of the label
rstyle (simple string) : the style for the lable
rcolor (simple color) : the color for the label
valid (simple bool) : a boolean flag that allows for turning on or off a lable
labelOffset (int)
rLabelLastBar(ry, rtext, rstyle, rcolor, valid, labelXOffset)
a function that draws a right aligned lable for a series only on the last bar
Parameters:
ry (float) : series float the y coordinate of the lable
rtext (string) : the text of the label
rstyle (simple string) : the style for the lable
rcolor (simple color) : the color for the label
valid (simple bool) : a boolean flag that allows for turning on or off a lable
labelXOffset (int) : how much to offset the label from the current position
drawLine(xSeries, res, tag, xColor, xStyle, xWidth, xExtend, isLabelValid, xLabelOffset, validTimeFrame)
a function that draws a line and a label for a series
Parameters:
xSeries (float) : series float the y coordinate of the line/label
res (simple string) : the desired resolution controlling when a new line will start
tag (simple string) : the text for the lable
xColor (simple color) : the color for the label
xStyle (simple string) : the style for the line
xWidth (simple int) : the width of the line
xExtend (simple string) : extend the line
isLabelValid (simple bool) : a boolean flag that allows for turning on or off a label
xLabelOffset (int)
validTimeFrame (simple bool) : a boolean flag that allows for turning on or off a line drawn
drawLineDO(xSeries, res, tag, xColor, xStyle, xWidth, xExtend, isLabelValid, xLabelOffset, validTimeFrame)
a function that draws a line and a label for the daily open series
Parameters:
xSeries (float) : series float the y coordinate of the line/label
res (simple string) : the desired resolution controlling when a new line will start
tag (simple string) : the text for the lable
xColor (simple color) : the color for the label
xStyle (simple string) : the style for the line
xWidth (simple int) : the width of the line
xExtend (simple string) : extend the line
isLabelValid (simple bool) : a boolean flag that allows for turning on or off a label
xLabelOffset (int)
validTimeFrame (simple bool) : a boolean flag that allows for turning on or off a line drawn
drawPivot(pivotLevel, res, tag, pivotColor, pivotLabelColor, pivotStyle, pivotWidth, pivotExtend, isLabelValid, validTimeFrame, levelStart, pivotLabelXOffset)
draw a pivot line - the line starts one day into the past
Parameters:
pivotLevel (float) : series of the pivot point
res (simple string) : the desired resolution
tag (simple string) : the text to appear
pivotColor (simple color) : the color of the line
pivotLabelColor (simple color) : the color of the label
pivotStyle (simple string) : the line style
pivotWidth (simple int) : the line width
pivotExtend (simple string) : extend the line
isLabelValid (simple bool) : boolean param allows to turn label on and off
validTimeFrame (simple bool) : only draw the line and label at a valid timeframe
levelStart (int) : basically when to start drawing the levels
pivotLabelXOffset (int) : how much to offset the label from its current postion
@return the pivot line series
getPvsraFlagByColor(pvsraColor, redVectorColor, greenVectorColor, violetVectorColor, blueVectorColor, lightGrayCandleColor)
convert the pvsra color to an internal code
Parameters:
pvsraColor (color) : the calculated pvsra color
redVectorColor (simple color) : the user defined red vector color
greenVectorColor (simple color) : the user defined green vector color
violetVectorColor (simple color) : the user defined violet vector color
blueVectorColor (simple color) : the user defined blue vector color
lightGrayCandleColor (simple color) : the user defined regular up candle color
@return pvsra internal code
updateZones(pvsra, direction, boxArr, maxlevels, pvsraHigh, pvsraLow, pvsraOpen, pvsraClose, transperancy, zoneupdatetype, zonecolor, zonetype, borderwidth, coloroverride, redVectorColor, greenVectorColor, violetVectorColor, blueVectorColor)
a function that draws the unrecovered vector candle zones
Parameters:
pvsra (int) : internal code
direction (simple int) : above or below the current pa
boxArr (array) : the array containing the boxes that need to be updated
maxlevels (simple int) : the maximum number of boxes to draw
pvsraHigh (float) : the pvsra high value series
pvsraLow (float) : the pvsra low value series
pvsraOpen (float) : the pvsra open value series
pvsraClose (float) : the pvsra close value series
transperancy (simple int) : the transparencfy of the vecor candle zones
zoneupdatetype (simple string) : the zone update type
zonecolor (simple color) : the zone color if overriden
zonetype (simple string) : the zone type
borderwidth (simple int) : the width of the border
coloroverride (simple bool) : if the color overriden
redVectorColor (simple color) : the user defined red vector color
greenVectorColor (simple color) : the user defined green vector color
violetVectorColor (simple color) : the user defined violet vector color
blueVectorColor (simple color) : the user defined blue vector color
cleanarr(arr)
clean an array from na values
Parameters:
arr (array) : the array to clean
@return if the array was cleaned
calcPsyLevels(oneWeekMillis, showPsylevels, psyType, sydDST)
calculate the psy levels
4 hour res based on how mt4 does it
mt4 code
int Li_4 = iBarShift(NULL, PERIOD_H4, iTime(NULL, PERIOD_W1, Li_0)) - 2 - Offset;
ObjectCreate("PsychHi", OBJ_TREND, 0, Time , iHigh(NULL, PERIOD_H4, iHighest(NULL, PERIOD_H4, MODE_HIGH, 2, Li_4)), iTime(NULL, PERIOD_W1, 0), iHigh(NULL, PERIOD_H4,
iHighest(NULL, PERIOD_H4, MODE_HIGH, 2, Li_4)));
so basically because the session is 8 hours and we are looking at a 4 hour resolution we only need to take the highest high an lowest low of 2 bars
we use the gmt offset to adjust the 0000-0800 session to Sydney open which is at 2100 during dst and at 2200 otherwize. (dst - spring foward, fall back)
keep in mind sydney is in the souther hemisphere so dst is oposite of when london and new york go into dst
Parameters:
oneWeekMillis (simple int) : a constant value
showPsylevels (simple bool) : should psy levels be calculated
psyType (simple string) : the type of Psylevels - crypto or forex
sydDST (bool) : is Sydney in DST
@return
adrHiLo(length, barsBack, fromDO)
Parameters:
length (simple int) : how many elements of the series to calculate on
barsBack (simple int) : starting possition for the length calculation - current bar or some other value eg last bar
fromDO (simple bool) : boolean flag, if false calculate traditional adr from high low of today, if true calcualte from exchange midnight
@return adr, adrLow and adrHigh - the adr, the position of the adr High and adr Low with respect to price
drawSessionHiloLite(sessXTime, showRectangleX, showLabelX, sessXcolLabel, sessXLabel, gmt, sessionLineStyle, sessXcol)
Parameters:
sessXTime (simple string) : session string in the format 0000-0100:23456
showRectangleX (simple bool)
showLabelX (simple bool)
sessXcolLabel (simple color) : the color to be used for the hi/low lines and label
sessXLabel (simple string) : the session label text
gmt (simple string) : the gmt offset string usually in the format GMT+1 or GMT+2 etc
sessionLineStyle (simple string) : the line stile for the session high low lines
sessXcol (simple color) : - the color for the box color that will color the session
@return void
msToHmsString(ms)
converts milliseconds into an hh:mm string. For example, 61000 ms to '0:01:01'
Parameters:
ms (int) : - the milliseconds to convert to hh:mm
@return string - the converted hh:mm string
countdownString(openToday, closeToday, showMarketsWeekends, oneDay)
that calculates how much time is left until the next session taking the session start and end times into account. Note this function does not work on intraday sessions.
Parameters:
openToday (int) : - timestamps of when the session opens in general - note its a series because the timestamp was created using the dst flag which is a series itself thus producing a timestamp series
closeToday (int) : - timestamp of when the session closes in general - note its a series because the timestamp was created using the dst flag which is a series itself thus producing a timestamp series
@return a countdown of when next the session opens or 'Open' if the session is open now
showMarketsWeekends (simple bool)
oneDay (simple int)
countdownStringSyd(sydOpenToday, sydCloseToday, showMarketsWeekends, oneDay)
that calculates how much time is left until the next session taking the session start and end times into account. special case of intraday sessions like sydney
Parameters:
sydOpenToday (int)
sydCloseToday (int)
showMarketsWeekends (simple bool)
oneDay (simple int)
GBB_lib_utilsLibrary "GBB_lib_utils"
gbb_moving_average_source(_source, _length, _ma_type)
gbb_moving_average_source
@description Calculates the moving average of a source series.
Parameters:
_source (float) : (series float)
_length (simple int) : (int)
_ma_type (string) : (string)
Returns: (series) Moving average series
gbb_tf_to_display(tf_minutes, tf_string)
gbb_tf_to_display
@description Converts minutes and TF string into a short standard label.
Parameters:
tf_minutes (float) : (float)
tf_string (string) : (string)
Returns: (string) Timeframe label (M1,H1,D1,...)
gbb_convert_bars(_bars)
gbb_convert_bars
@description Formats a number of bars into a duration (days, hours, minutes + bar count).
Parameters:
_bars (int) : (int)
Returns: (string)
gbb_goldorak_init(_tf5Levels_input)
gbb_goldorak_init
@description Builds a contextual message about the current timeframe and optional 5-level TF.
Parameters:
_tf5Levels_input (string) : (string) Alternative timeframe ("" = current timeframe).
Returns: (string, string, float)
GBB_lib_fiboLibrary "GBB_lib_fibo"
draw_fibo(high_point, low_point)
draw_fibo
/ @description Draws Fibonacci retracement lines between a high point and a low point.
/ @param high_point (float) Highest point of the move.
/ @param low_point (float) Lowest point of the move.
/ @returns (void) Draws lines on the chart.
Parameters:
high_point (float)
low_point (float)
GBB_lib_utilsLibrary "GBB_lib_utils"
gbb_tf_to_display(tf_minutes, tf_string)
gbb_tf_to_display
/ @description Converts minutes and TF string into a short standard label.
/ @param tf_minutes (float)
/ @param tf_string (string)
/ @returns (string) Timeframe label (M1,H1,D1,...)
Parameters:
tf_minutes (float)
tf_string (string)
gbb_convert_bars(_bars)
gbb_convert_bars
/ @description Formats a number of bars into a duration (days, hours, minutes + bar count).
/ @param _bars (int)
/ @returns (string)
Parameters:
_bars (int)
gbb_goldorak_init(_tf5Levels_input)
gbb_goldorak_init
/ @description Builds a contextual message about the current timeframe and optional 5-level TF.
/ @param _tf5Levels_input (string) Alternative timeframe ("" = current timeframe).
/ @returns (string, string, float)
Parameters:
_tf5Levels_input (string)
GGB_lib_fiboLibrary "GGB_lib_fibo"
draw_fibo(high_point, low_point)
draw_fibo
/ @description Draws Fibonacci retracement lines between a high point and a low point.
/ @param high_point (float) Highest point of the move.
/ @param low_point (float) Lowest point of the move.
/ @returns (void) Draws lines on the chart.
Parameters:
high_point (float)
low_point (float)
GGB_lib_utilsLibrary "GGB_lib_utils"
gbb_tf_to_display(tf_minutes, tf_string)
gbb_tf_to_display
/ @description Converts minutes and TF string into a short standard label.
/ @param tf_minutes (float)
/ @param tf_string (string)
/ @returns (string) Timeframe label (M1,H1,D1,...)
Parameters:
tf_minutes (float)
tf_string (string)
gbb_convert_bars(_bars)
gbb_convert_bars
/ @description Formats a number of bars into a duration (days, hours, minutes + bar count).
/ @param _bars (int)
/ @returns (string)
Parameters:
_bars (int)
gbb_goldorak_init(_tf5Levels_input)
gbb_goldorak_init
/ @description Builds a contextual message about the current timeframe and optional 5-level TF.
/ @param _tf5Levels_input (string) Alternative timeframe ("" = current timeframe).
/ @returns (string, string, float)
Parameters:
_tf5Levels_input (string)
TAUtilityLibLibrary "TAUtilityLib"
Technical Analysis Utility Library - Collection of functions for market analysis, smoothing, scaling, and structure detection
log_snapshot(label1, val1, label2, val2, label3, val3, label4, val4, label5, val5)
Creates formatted log snapshot with 5 labeled values
Parameters:
label1 (string)
val1 (float)
label2 (string)
val2 (float)
label3 (string)
val3 (float)
label4 (string)
val4 (float)
label5 (string)
val5 (float)
Returns: void (logs to console)
f_get_next_tf(tf, steps)
Gets next higher timeframe(s) from current
Parameters:
tf (string) : Current timeframe string
steps (string) : "1 TF Higher" for next TF, any other value for 2 TFs higher
Returns: Next timeframe string or na if at maximum
f_get_prev_tf(tf)
Gets previous lower timeframe from current
Parameters:
tf (string) : Current timeframe string
Returns: Previous timeframe string or na if at minimum
supersmoother(_src, _length)
Ehler's SuperSmoother - low-lag smoothing filter
Parameters:
_src (float) : Source series to smooth
_length (simple int) : Smoothing period
Returns: Smoothed series
butter_smooth(src, len)
Butterworth filter for ultra-smooth price filtering
Parameters:
src (float) : Source series
len (simple int) : Filter period
Returns: Butterworth smoothed series
f_dynamic_ema(source, dynamic_length)
Dynamic EMA with variable length
Parameters:
source (float) : Source series
dynamic_length (float) : Dynamic period (can vary bar to bar)
Returns: Dynamically adjusted EMA
dema(source, length)
Double Exponential Moving Average (DEMA)
Parameters:
source (float) : Source series
length (simple int) : Period for DEMA calculation
Returns: DEMA value
f_scale_percentile(primary_line, secondary_line, x)
Scales secondary line to match primary line using percentile ranges
Parameters:
primary_line (float) : Reference series for target scale
secondary_line (float) : Series to be scaled
x (int) : Lookback bars for percentile calculation
Returns: Scaled version of secondary_line
calculate_correlation_scaling(demamom_range, demamom_min, correlation_range, correlation_min)
Calculates scaling factors for correlation alignment
Parameters:
demamom_range (float) : Range of primary series
demamom_min (float) : Minimum of primary series
correlation_range (float) : Range of secondary series
correlation_min (float) : Minimum of secondary series
Returns: tuple for alignment
getBB(src, length, mult, chartlevel)
Calculates Bollinger Bands with chart level offset
Parameters:
src (float) : Source series
length (simple int) : MA period
mult (simple float) : Standard deviation multiplier
chartlevel (simple float) : Vertical offset for plotting
Returns: tuple
get_mrc(source, length, mult, mult2, gradsize)
Mean Reversion Channel with multiple bands and conditions
Parameters:
source (float) : Price source
length (simple int) : Channel period
mult (simple float) : First band multiplier
mult2 (simple float) : Second band multiplier
gradsize (simple float) : Gradient size for zone detection
Returns:
analyzeMarketStructure(highFractalBars, highFractalPrices, lowFractalBars, lowFractalPrices, trendDirection)
Analyzes market structure for ChoCH and BOS patterns
Parameters:
highFractalBars (array) : Array of high fractal bar indices
highFractalPrices (array) : Array of high fractal prices
lowFractalBars (array) : Array of low fractal bar indices
lowFractalPrices (array) : Array of low fractal prices
trendDirection (int) : Current trend (1=up, -1=down, 0=neutral)
Returns: - change signals and new trend direction
utilitiesLibrary for commonly used utilities, for visualizing rolling returns, correlations and sharpe
FibonacciRetracementHi all!
This library will help you draw Fibonacci retracement levels (zones). The code is from my indicator "Fibonacci retracement" (). You can see that description for more information about the behaviour and example of how to use this library. The code is almost the same with the addition of alerts. If the alert frequency is 'alert.freq_once_per_bar_close' alert messages will be concatenated and have a header saying how many messages it contains (if it's more than 1).
Hope this is of help!
Library "FibonacciRetracement"
ConcateAlerts(context)
Concatenates all alerts from the bar to one string (separated by new lines) and clears alert messages on the current bar.
Parameters:
context (Context)
AddAlert(context, message, unshiftInsteadOfPush)
Parameters:
context (Context)
message (string)
unshiftInsteadOfPush (bool)
Range(context, structure, settings)
Will return values if new levels/zones should be drawn.
Parameters:
context (Context) : The 'Context' for the Fibonacci retracement.
structure (Structure type from mickes/PriceAction/1) : The current 'Structure' from the 'MarketStructure' library.
settings (Settings) : The 'Settings' object for the 'Context'.
Returns: A tuple with the start and end pivot if new zones should be drawn, ' ' otherwise.
DrawAll(context, settings, start, end)
Draws lines and labels for the zone. It will also set the 'Price' value that will be used for absolute positions.
Parameters:
context (Context) : The 'Context' for the Fibonacci retracement.
settings (Settings) : The 'Settings' object for the 'Context'.
start (Pivot type from mickes/PriceAction/1)
end (Pivot type from mickes/PriceAction/1)
AlertActive(context, settings)
Will alert for all zones that are active. If multiple alert messages are added they will be concatenated (separated by a new line) with a header saying how many messages the alert contains.
Parameters:
context (Context) : The 'Context' for the Fibonacci retracement. This contains the zones that will be alerted if price (wick or close according to the settings) enters it.
settings (Settings) : The 'Settings' object for the 'Context'.
TrendlineSettings
Holds all the values for 'TrendlineSettings'.
Fields:
Enabled (series bool) : If the trendline should be visible or not.
Color (series color) : The color of the trendline.
Style (series string) : The style of the trendline (as a string).
GenericZonesSettings
Holds all the values for 'GenericZonesSettings', that will be applicable to all drawn objects.
Fields:
ExtendRight (series bool) : If all lines should extend to the right or not.
Style (series string) : The style of all drawn lines
Reverse (series bool) : If true, all lines will be reversed.
Prices (series bool) : If price levels should be shown or not.
Levels (series bool) : If levels should be shown or not.
LevelsValue (series string) : Either 'Value' or 'Percent'. Defined if value or percentage should be shown.
FontSize (series int) : The for size of the text in labels drawn.
LabelsPosition (series string) : Coul be 'Left', 'Rigth' or 'Adapt'. 'Adapt' will try to adapt the labels position to the prices.
ZoneSettings
Holds all the values for 'ZoneSettings'.
Fields:
Enabled (series bool) : If this zone is enabled or not.
Level (series float) : The level of the zone.
Color (series color) : The color that will be displayed.
Price (series float) : The price of the level. Will be set internally.
Settings
Holds all the values for 'Settings'.
Fields:
PivotLeftLength (series int) : The left length used to find pivots through the 'MarketStructure' library.
PivotRightLength (series int) : The right length used to find pivots through the 'MarketStructure' library.
Trendline (TrendlineSettings) : The settings for the 'Trendline' object.
GenericZonesSettings (GenericZonesSettings) : The setting applicable to all zones.
AlertFrequency (series string) : The frequency for the alerts. If 'alert.freq_once_per_bar_close', alert messages will be concatenated and have a header saying how many messages it contains (if it's more than 1).
AlertPrice (series string) : The price that has to enter a zone. Can be 'Close' (the closing price) or 'Wick' (the whole candle needs to be in the zone).
Zone1 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone2 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone3 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone4 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone5 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone6 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone7 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone8 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone9 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone10 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone11 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone12 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone13 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone14 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone15 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone16 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone17 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone18 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone19 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone20 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone21 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone22 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone23 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Zone24 (ZoneSettings) : The 'ZoneSettings' that represents this zone.
Context
Holds all the values for 'Context'.
Fields:
Lines (array) : All the drawn lines for the current 'Context'.
Labels (array) : All the drawn labels for the current 'Context'.
Boxes (array) : All the drawn boxes for the current 'Context'.
Alerts (array) : All the alert messages on the current tick.
Start (series int) : The start bar index of the current 'Context'.






















