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)
ارتداد من القاع فلتر ارتداد من القاع مع ملاحظة انه يعمل كتنبيه في القائمة
Bottom bounce filter, note that it works as an alert in the menu
EV/FCFThis script in the 6 version of Pine brings you the most accurate multiple of "fundamental valuation" in my opinion. EV/FCF gives you a real metric of how profitable is the company in this exact moment and also if the company is overvaluated or undervaluated.
Confluence AutoEntry (1m/5m/15m) for Alertatron//@version=5
indicator("Confluence AutoEntry (1m/5m/15m) for Alertatron", overlay=true, max_lines_count=500, max_labels_count=500)
// =========================
// 参数
// =========================
tf1 = input.timeframe("1", "周期-1")
tf2 = input.timeframe("5", "周期-2")
tf3 = input.timeframe("15", "周期-3")
ema1 = input.int(10, "EMA1")
ema2 = input.int(30, "EMA2")
ema3 = input.int(60, "EMA3")
rLen = input.int(14, "RSI 长度")
thr1 = input.int(60, "阈值-周期1 (0~100)", minval=0, maxval=100)
thr2 = input.int(60, "阈值-周期2 (0~100)", minval=0, maxval=100)
thr3 = input.int(60, "阈值-周期3 (0~100)", minval=0, maxval=100)
// 下单资金(USDT)
usdtPerTrade = input.float(500, "每次下单金额(USDT)", step=5)
// 下单类型(市价/限价)
orderType = input.string("market", "下单类型", options= , tooltip="market=市价;limit=限价(使用 entry 作为限价)")
// 两步延续触发
useTwoStep = input.bool(true, "启用两步延续触发", tooltip="收盘仅“武装”,下一根或后续“延续突破”才真正发单;关闭=收盘即发一次信号")
bufferPct = input.float(0.08, "延续触发缓冲(%)", step=0.01, tooltip="突破需要超过武装价的百分比")
armBars = input.int(1, "武装有效bar数", minval=1, tooltip="超时未触发则自动取消武装")
// 可选:在 JSON 中附带 token
attachToken = input.bool(false, "在 JSON 中附带 token 字段")
longToken = input.string("", "多头 token(可留空)")
shortToken = input.string("", "空头 token(可留空)")
// 图形显示
showShapes = input.bool(true, "图表显示三角/武装/触发标记")
showTriggerLabel = input.bool(true, "触发时显示【入场/TP/SL/Qty】标签")
// 「平衡」展示用 TP/SL 百分比(仅用于标签展示,不发到 Alertatron)
tpPct = input.float(2.0, "展示用:TP百分比(%)")
slPct = input.float(1.0, "展示用:SL百分比(%)")
// =========================
// 工具函数
// =========================
f_score(tf) =>
_c = request.security(syminfo.tickerid, tf, close, barmerge.gaps_off, barmerge.lookahead_off)
_e1 = request.security(syminfo.tickerid, tf, ta.ema(close, ema1), barmerge.gaps_off, barmerge.lookahead_off)
_e2 = request.security(syminfo.tickerid, tf, ta.ema(close, ema2), barmerge.gaps_off, barmerge.lookahead_off)
_e3 = request.security(syminfo.tickerid, tf, ta.ema(close, ema3), barmerge.gaps_off, barmerge.lookahead_off)
_r = request.security(syminfo.tickerid, tf, ta.rsi(close, rLen), barmerge.gaps_off, barmerge.lookahead_off)
_m = request.security(syminfo.tickerid, tf, ta.sma(ta.change(close), 5), barmerge.gaps_off, barmerge.lookahead_off)
_ok1 = _c > _e1 ? 1 : 0
_ok2 = _e1 >= _e2 ? 1 : 0
_ok3 = _e2 >= _e3 ? 1 : 0
_ok4 = _r > 50 ? 1 : 0
_ok5 = _m >= 0 ? 1 : 0
(_ok1 + _ok2 + _ok3 + _ok4 + _ok5) / 5.0 * 100.0
// 价格按最小跳动取整
tickRound(x) =>
syminfo.mintick > 0 ? math.round(x / syminfo.mintick) * syminfo.mintick : x
// 数字 -> 价格串
sPrice(x) =>
str.tostring(x, format.mintick)
// 小数点四舍五入(用于数量展示)
roundN(x, n) =>
_f = math.pow(10.0, n)
math.round(x * _f) / _f
sQty(x) =>
str.tostring(roundN(x, 6))
// 去掉交易所前缀和 .P 后缀,得到 BASEQUOTE(如 ETHUSDC)
cleanSymbol() =>
_s = syminfo.ticker
_arr = str.split(_s, ":")
_last = array.get(_arr, array.size(_arr) - 1)
str.replace_all(_last, ".P", "")
// =========================
// 多周期评分 -> 一致方向
// =========================
score1 = f_score(tf1)
score2 = f_score(tf2)
score3 = f_score(tf3)
dir1 = score1 >= thr1 ? 1 : -1
dir2 = score2 >= thr2 ? 1 : -1
dir3 = score3 >= thr3 ? 1 : -1
conf_long = dir1 == 1 and dir2 == 1 and dir3 == 1
conf_short = dir1 == -1 and dir2 == -1 and dir3 == -1
// =========================
// 两步法:收盘“武装” + 下一根/后续“延续触发”
// =========================
var bool armLong = false
var float armLongPx = na
var int armLongUntil = na
var bool armShort = false
var float armShortPx = na
var int armShortUntil = na
if barstate.isconfirmed
if conf_long
armLong := true
armLongPx := close
armLongUntil := bar_index + armBars
if conf_short
armShort := true
armShortPx := close
armShortUntil := bar_index + armBars
longTrigPrice = armLong ? armLongPx * (1 + bufferPct/100.0) : na
shortTrigPrice = armShort ? armShortPx * (1 - bufferPct/100.0) : na
triggerLong = useTwoStep ? (armLong and high >= longTrigPrice) : (barstate.isconfirmed and conf_long)
triggerShort = useTwoStep ? (armShort and low <= shortTrigPrice) : (barstate.isconfirmed and conf_short)
// 触发后立刻卸载武装;超时未触发亦卸载
if triggerLong
armLong := false
if triggerShort
armShort := false
if bar_index > armLongUntil
armLong := false
if bar_index > armShortUntil
armShort := false
// =========================
// 发单用价位(在触发时会被使用)
// =========================
float entryL = tickRound(useTwoStep ? longTrigPrice : close)
float entryS = tickRound(useTwoStep ? shortTrigPrice : close)
float tpL = tickRound(entryL * (1 + tpPct/100.0))
float slL = tickRound(entryL * (1 - slPct/100.0))
float tpS = tickRound(entryS * (1 - tpPct/100.0))
float slS = tickRound(entryS * (1 + slPct/100.0))
// —— 展示标签直接使用上面算好的 entryL/entryS/tpL/slL/tpS/slS
if showTriggerLabel and barstate.isconfirmed
if triggerLong
_txt = "LONG Entry: " + sPrice(entryL) + " TP: " + sPrice(tpL) + " SL: " + sPrice(slL) + " EstQty: " + sQty(usdtPerTrade/entryL)
label.new(bar_index, low, text=_txt, style=label.style_label_up, textcolor=color.white, color=color.new(color.lime, 0))
if triggerShort
_txt = "SHORT Entry: " + sPrice(entryS) + " TP: " + sPrice(tpS) + " SL: " + sPrice(slS) + " EstQty: " + sQty(usdtPerTrade/entryS)
label.new(bar_index, high, text=_txt, style=label.style_label_down, textcolor=color.white, color=color.new(color.red, 0))
// ============ 构造 JSON(按方向用不同 signal 名,所有数值写入) ============
buildMsg(_side, _entry, _tp, _sl) =>
_sig = _side == "buy" ? "open_long" : "open_short"
_token = attachToken ? ',"token":"' + (_side == "buy" ? longToken : shortToken) + '"' : ""
_msg = '{"signal":"' + _sig + '"'
_msg := _msg + ',"side":"' + _side + '"'
_msg := _msg + ',"symbol":"' + cleanSymbol() + '"'
_msg := _msg + ',"order_type":"market"'
_msg := _msg + ',"usdt_per_trade":' + str.tostring(usdtPerTrade)
_msg := _msg + ',"entry":' + sPrice(_entry)
_msg := _msg + ',"tp":' + sPrice(_tp)
_msg := _msg + ',"sl":' + sPrice(_sl)
_msg := _msg + _token + "}"
_msg
msgLong = buildMsg("buy", entryL, tpL, slL)
msgShort = buildMsg("sell", entryS, tpS, slS)
// =========================
// 报警 & 发单(在 TradingView 里选择 Any alert() function call;Webhook 填机器人 URL;Message 留空)
// =========================
alertcondition(triggerLong, title="多仓开仓(…)", message="LONG")
alertcondition(triggerShort, title="空仓开仓(…)", message="SHORT")
if barstate.isconfirmed
if triggerLong
alert(message = msgLong, freq = alert.freq_once_per_bar_close)
if triggerShort
alert(message = msgShort, freq = alert.freq_once_per_bar_close)
// =========================
// 可视化:形态+触发线
// =========================
plotshape(showShapes and conf_long and barstate.isconfirmed, title="收盘-多武装", style=shape.triangleup, color=color.new(color.green, 0), size=size.tiny, text="ARM L", location=location.belowbar)
plotshape(showShapes and conf_short and barstate.isconfirmed, title="收盘-空武装", style=shape.triangledown, color=color.new(color.red, 0), size=size.tiny, text="ARM S", location=location.abovebar)
plotshape(showShapes and triggerLong, title="触发-开多", style=shape.labelup, color=color.new(color.lime, 0), text="▶ LONG", location=location.belowbar, size=size.tiny)
plotshape(showShapes and triggerShort, title="触发-开空", style=shape.labeldown, color=color.new(color.maroon,0), text="▶ SHORT", location=location.abovebar, size=size.tiny)
plot(useTwoStep and armLong ? armLongPx : na, "武装价-L", color=color.new(color.green, 70), style=plot.style_circles, linewidth=1)
plot(useTwoStep and armShort ? armShortPx : na, "武装价-S", color=color.new(color.red, 70), style=plot.style_circles, linewidth=1)
plot(useTwoStep ? longTrigPrice : na, "触发线-L", color=color.new(color.lime, 0), style=plot.style_linebr, linewidth=1)
plot(useTwoStep ? shortTrigPrice : na, "触发线-S", color=color.new(color.maroon, 0), style=plot.style_linebr, linewidth=1)
// =========================
// 可视化:触发时弹出【入场/TP/SL/Qty】标签(仅展示用)
// =========================
if showTriggerLabel and barstate.isconfirmed
if triggerLong
_qtyL = usdtPerTrade > 0 and entryL > 0 ? (usdtPerTrade / entryL) : na
_txtL = "LONG Entry: " + sPrice(entryL) + " TP: " + sPrice(tpL) + " SL: " + sPrice(slL) + " EstQty: " + sQty(_qtyL)
label.new(bar_index, low, text=_txtL, style=label.style_label_up, textcolor=color.white, color=color.new(color.lime, 0))
if triggerShort
_qtyS = usdtPerTrade > 0 and entryS > 0 ? (usdtPerTrade / entryS) : na
_txtS = "SHORT Entry: " + sPrice(entryS) + " TP: " + sPrice(tpS) + " SL: " + sPrice(slS) + " EstQty: " + sQty(_qtyS)
label.new(bar_index, high, text=_txtS, style=label.style_label_down, textcolor=color.white, color=color.new(color.red, 0))
Macros Kill Zones Fusionadas (:20 - :40) / :50 - :10)//@version=6
indicator("Macros Kill Zones Fusionadas (:20 - :40) / :50 - :10)", overlay=true, max_lines_count=500, max_labels_count=500, max_boxes_count=500)
// =======================
// === CONFIGURACIÓN ===
showLines = input.bool(true, "Mostrar líneas verticales")
showShading = input.bool(false, "Sombreado opcional")
shadeColor = input.color(color.new(color.gray, 85), "Color sombreado")
lineColor = color.new(color.gray, 50)
lineWidth = input.int(1, "Grosor líneas", 1, 3)
lookbackBars = input.int(200, "Lookback", 20, 2000)
// Calcular extremos del gráfico
ht = ta.highest(high, lookbackBars)
lt = ta.lowest(low, lookbackBars)
yTop = ht * 1.02
yBot = lt * 0.98
// Hora local en minutos
local_min = hour * 60 + minute
// =======================
// === MACROS ACTIVAS POR DEFECTO ===
m0 = input.bool(false,"12:20am a 12:40am")
m1 = input.bool(false,"1:20am a 1:40am")
m2 = input.bool(true, "2:20am a 2:40am")
m3 = input.bool(true, "3:20am a 3:40am")
m4 = input.bool(true, "4:20am a 4:40am")
m5 = input.bool(false,"5:20am a 5:40am")
m6 = input.bool(false,"6:20am a 6:40am")
m7 = input.bool(true, "7:20am a 7:40am")
m8 = input.bool(true, "8:20am a 8:40am")
m9 = input.bool(true, "9:20am a 9:40am")
m10 = input.bool(true, "10:20am a 10:40am")
m11 = input.bool(false,"11:20am a 11:40am")
m12 = input.bool(false,"12:20pm a 12:40pm")
m13 = input.bool(false,"1:20pm a 1:40pm")
m14 = input.bool(false,"2:20pm a 2:40pm")
m15 = input.bool(false,"3:20pm a 3:40pm")
m16 = input.bool(false,"4:20pm a 4:40pm")
m17 = input.bool(false,"5:20pm a 5:40pm")
m18 = input.bool(false,"6:20pm a 6:40pm")
m19 = input.bool(false,"7:20pm a 7:40pm")
m20 = input.bool(false,"8:20pm a 8:40pm")
m21 = input.bool(false,"9:20pm a 9:40pm")
m22 = input.bool(false,"10:20pm a 10:40pm")
m23 = input.bool(false,"11:20pm a 11:40pm")
// =======================
// === FUNCIÓN DE DIBUJO AJUSTADA ===
f_drawLines(on, startHour) =>
startMin = startHour * 60 + 20
endMin = startHour * 60 + 40
inRange = local_min >= startMin and local_min <= endMin // incluir minuto :40
if on and showLines
if local_min == startMin or local_min == endMin // dibujar línea exacta inicio y fin
line.new(bar_index, yTop, bar_index, yBot, xloc=xloc.bar_index, color=lineColor, width=lineWidth)
inRange
// =======================
// === CHEQUEO DE MACROS ACTIVAS ===
in_any_macro = f_drawLines(m0,0) or f_drawLines(m1,1) or f_drawLines(m2,2) or f_drawLines(m3,3) or
f_drawLines(m4,4) or f_drawLines(m5,5) or f_drawLines(m6,6) or f_drawLines(m7,7) or
f_drawLines(m8,8) or f_drawLines(m9,9) or f_drawLines(m10,10) or f_drawLines(m11,11) or
f_drawLines(m12,12) or f_drawLines(m13,13) or f_drawLines(m14,14) or f_drawLines(m15,15) or
f_drawLines(m16,16) or f_drawLines(m17,17) or f_drawLines(m18,18) or f_drawLines(m19,19) or
f_drawLines(m20,20) or f_drawLines(m21,21) or f_drawLines(m22,22) or f_drawLines(m23,23)
// =======================
// === SOMBREADO OPCIONAL ===
bgcolor(showShading and in_any_macro ? shadeColor : na)
// =======================
// === INDICADOR 2: Macro :50 - :10 ===
// =======================
//#region
var line EXT = array.new_line()
var label LBL = array.new_label()
oneDayMS = 86400000
oneBarMS = time_close - time
noColor = color.new(#ffffff, 100)
// Ajuste de línea sobre vela
one = ta.highest(timeframe.in_seconds("15") / timeframe.in_seconds(timeframe.period)) + syminfo.mintick * 10
y_btm_Line1 = one
y_top_Line1 = one + syminfo.mintick * 5
//#region
_macroC = input.color(color.new(color.gray, 60), title="Macro Color", inline='main')
_mode = input.string("On Chart", title="", inline='main', options= )
_showL = input.bool(true, title="Macro Label?", inline='sh')
_mTxt = input.bool(true, title="Show Time?", inline='sh')
_extt = input.bool(false, title="Macro Projections?", inline='sh')
_bgm = input.color(color.new(#4caf50, 70), title="Macro Color", inline='bc')
//#endregion
//#region
time_isMacro(int H_start, int M_start, int H_end, int M_end) =>
h = hour(time, "America/New_York")
m = minute(time, "America/New_York")
h == H_start ? (H_start != H_end ? m >= M_start : m >= M_start and m < M_end) : (h > H_start ? (h == H_end ? m < M_end : h < H_end) : false)
_controlMacroLine(line _lines, label _lbl, bool _time) =>
if _time
_lbl.last().set_x(math.round(math.avg(_lines.get(_lines.size() - 2).get_x1(), time)))
if high > _lines.last().get_y2() - syminfo.mintick * 10
_lines.get(_lines.size() - 2).set_y2(high + (syminfo.mintick * 10))
_lines.last().set_y1(high + (syminfo.mintick * 10))
_lines.last().set_y2(high + (syminfo.mintick * 10))
LBL.last().set_y(high + (syminfo.mintick * 10))
if na(_lines.last().get_x2()) or _lines.last().get_x2() == time
_lines.last().set_x2(time + oneBarMS)
method memoryCleanLine(line A) =>
if A.size() > 300
for i = 0 to 3
A.shift().delete()
method memoryCleanLabel(label A) =>
if A.size() > 100
A.shift().delete()
macroOC(line LINES, bool _time, string _kzTime, bool _friday) =>
dly = _friday ? oneDayMS * 3 : oneDayMS
_txt = _mTxt ? _kzTime : ""
if not _time and _time
_vline1 = line.new(time, y_btm_Line1, time, y_top_Line1, xloc=xloc.bar_time, color=_macroC, width=1)
LINES.push(_vline1)
_hline = line.new(time, y_top_Line1, time + oneBarMS, y_top_Line1, xloc=xloc.bar_time, color=_macroC, width=1)
LINES.push(_hline)
if _extt
EXT.push(line.new(time, high, time, _vline1.get_y2(), xloc=xloc.bar_time, color=_macroC, style=line.style_dotted))
if _mode == "On Chart"
LBL.push(label.new(time,
LINES.get(LINES.size() - 2).get_y2(),
_showL ? _txt : "",
xloc=xloc.bar_time,
style=label.style_label_down,
color=noColor,
textcolor=_macroC,
size=size.small))
if _time and not _time and LINES.size() > 0
_vline2 = line.new(time, y_btm_Line1, time, y_top_Line1, xloc=xloc.bar_time, color=_macroC, width=1)
LBL.last().set_x(math.round(math.avg(LINES.get(LINES.size() - 2).get_x1(), time)))
if y_top_Line1 > LINES.get(LINES.size() - 2).get_y2()
LINES.get(LINES.size() - 2).set_y2(y_top_Line1)
LINES.last().set_y1(y_top_Line1)
LINES.last().set_y2(y_top_Line1)
LBL.last().set_y(y_top_Line1)
else if y_top_Line1 < LINES.get(LINES.size() - 2).get_y2()
_vline2.set_y2(LINES.get(LINES.size() - 2).get_y2())
if _extt
EXT.push(line.new(time, high, time, _vline2.get_y2(), xloc=xloc.bar_time, color=_macroC, style=line.style_dotted))
LINES.push(_vline2)
if LINES.size() > 0 and LBL.size() > 0
_controlMacroLine(LINES, LBL, _time)
//#endregion
//#region
// Declaración de los 24 intervalos cronológicos
var line _LINES1 = array.new_line()
var line _LINES2 = array.new_line()
var line _LINES3 = array.new_line()
var line _LINES4 = array.new_line()
var line _LINES5 = array.new_line()
var line _LINES6 = array.new_line()
var line _LINES7 = array.new_line()
var line _LINES8 = array.new_line()
var line _LINES9 = array.new_line()
var line _LINES10 = array.new_line()
var line _LINES11 = array.new_line()
var line _LINES12 = array.new_line()
var line _LINES13 = array.new_line()
var line _LINES14 = array.new_line()
var line _LINES15 = array.new_line()
var line _LINES16 = array.new_line()
var line _LINES17 = array.new_line()
var line _LINES18 = array.new_line()
var line _LINES19 = array.new_line()
var line _LINES20 = array.new_line()
var line _LINES21 = array.new_line()
var line _LINES22 = array.new_line()
var line _LINES23 = array.new_line()
var line _LINES24 = array.new_line()
// Inputs de activación
show1 = input.bool(false, title="00:50 - 01:10")
show2 = input.bool(false, title="01:50 - 02:10")
show3 = input.bool(true, title="02:50 - 03:10")
show4 = input.bool(true, title="03:50 - 04:10")
show5 = input.bool(false, title="04:50 - 05:10")
show6 = input.bool(false, title="05:50 - 06:10")
show7 = input.bool(false, title="06:50 - 07:10")
show8 = input.bool(true, title="07:50 - 08:10")
show9 = input.bool(true, title="08:50 - 09:10")
show10 = input.bool(true, title="09:50 - 10:10")
show11 = input.bool(false, title="10:50 - 11:10")
show12 = input.bool(false, title="11:50 - 12:10")
show13 = input.bool(false, title="12:50 - 13:10")
show14 = input.bool(false, title="13:50 - 14:10")
show15 = input.bool(false, title="14:50 - 15:10")
show16 = input.bool(false, title="15:50 - 16:10")
show17 = input.bool(false, title="16:50 - 17:10")
show18 = input.bool(false, title="17:50 - 18:10")
show19 = input.bool(false, title="18:50 - 19:10")
show20 = input.bool(false, title="19:50 - 20:10")
show21 = input.bool(false, title="20:50 - 21:10")
show22 = input.bool(false, title="21:50 - 22:10")
show23 = input.bool(false, title="22:50 - 23:10")
show24 = input.bool(false, title="23:50 - 00:10")
// Tiempos
time1 = time_isMacro(0,50,1,10)
time2 = time_isMacro(1,50,2,10)
time3 = time_isMacro(2,50,3,10)
time4 = time_isMacro(3,50,4,10)
time5 = time_isMacro(4,50,5,10)
time6 = time_isMacro(5,50,6,10)
time7 = time_isMacro(6,50,7,10)
time8 = time_isMacro(7,50,8,10)
time9 = time_isMacro(8,50,9,10)
time10 = time_isMacro(9,50,10,10)
time11 = time_isMacro(10,50,11,10)
time12 = time_isMacro(11,50,12,10)
time13 = time_isMacro(12,50,13,10)
time14 = time_isMacro(13,50,14,10)
time15 = time_isMacro(14,50,15,10)
time16 = time_isMacro(15,50,16,10)
time17 = time_isMacro(16,50,17,10)
time18 = time_isMacro(17,50,18,10)
time19 = time_isMacro(18,50,19,10)
time20 = time_isMacro(19,50,20,10)
time21 = time_isMacro(20,50,21,10)
time22 = time_isMacro(21,50,22,10)
time23 = time_isMacro(22,50,23,10)
time24 = time_isMacro(23,50,0,10)
//#region
plotMacro(_show, _LINES, _time, _lbl) =>
if _show
macroOC(_LINES, _time, _lbl, dayofweek(time) == dayofweek.friday and syminfo.type != 'crypto')
plotMacro(show1, _LINES1, time1, "00:50 - 01:10")
plotMacro(show2, _LINES2, time2, "01:50 - 02:10")
plotMacro(show3, _LINES3, time3, "02:50 - 03:10")
plotMacro(show4, _LINES4, time4, "03:50 - 04:10")
plotMacro(show5, _LINES5, time5, "04:50 - 05:10")
plotMacro(show6, _LINES6, time6, "05:50 - 06:10")
plotMacro(show7, _LINES7, time7, "06:50 - 07:10")
plotMacro(show8, _LINES8, time8, "07:50 - 08:10")
plotMacro(show9, _LINES9, time9, "08:50 - 09:10")
plotMacro(show10, _LINES10, time10, "09:50 - 10:10")
plotMacro(show11, _LINES11, time11, "10:50 - 11:10")
plotMacro(show12, _LINES12, time12, "11:50 - 12:10")
plotMacro(show13, _LINES13, time13, "12:50 - 13:10")
plotMacro(show14, _LINES14, time14, "13:50 - 14:10")
plotMacro(show15, _LINES15, time15, "14:50 - 15:10")
plotMacro(show16, _LINES16, time16, "15:50 - 16:10")
plotMacro(show17, _LINES17, time17, "16:50 - 17:10")
plotMacro(show18, _LINES18, time18, "17:50 - 18:10")
plotMacro(show19, _LINES19, time19, "18:50 - 19:10")
plotMacro(show20, _LINES20, time20, "19:50 - 20:10")
plotMacro(show21, _LINES21, time21, "20:50 - 21:10")
plotMacro(show22, _LINES22, time22, "21:50 - 22:10")
plotMacro(show23, _LINES23, time23, "22:50 - 23:10")
plotMacro(show24, _LINES24, time24, "23:50 - 00:10")
//#endregion
//#region
_LINES1.memoryCleanLine()
_LINES2.memoryCleanLine()
_LINES3.memoryCleanLine()
_LINES4.memoryCleanLine()
_LINES5.memoryCleanLine()
_LINES6.memoryCleanLine()
_LINES7.memoryCleanLine()
_LINES8.memoryCleanLine()
_LINES9.memoryCleanLine()
_LINES10.memoryCleanLine()
_LINES11.memoryCleanLine()
_LINES12.memoryCleanLine()
_LINES13.memoryCleanLine()
_LINES14.memoryCleanLine()
_LINES15.memoryCleanLine()
_LINES16.memoryCleanLine()
_LINES17.memoryCleanLine()
_LINES18.memoryCleanLine()
_LINES19.memoryCleanLine()
_LINES20.memoryCleanLine()
_LINES21.memoryCleanLine()
_LINES22.memoryCleanLine()
_LINES23.memoryCleanLine()
_LINES24.memoryCleanLine()
EXT.memoryCleanLine()
LBL.memoryCleanLabel()
//#endregion
ATRThis script displays the Average True Range (ATR) value and the ATR as a percentage of the current closing price directly on the main chart as a clean table, with no lines or plots. It allows users to easily monitor both absolute volatility and its relative magnitude, making comparisons across different assets intuitive. The display position is customizable, offering flexibility for personal chart layouts. Ideal for traders seeking quick volatility insights, risk management guidance, or portfolio-wide comparisons.
Quantum Portfolio vs NASDAQ (Base: May 2, 2021)This custom Pine Script indicator tracks and compares the cumulative performance of a multi-asset “Quantum Portfolio” against the NASDAQ 100 benchmark, rebased to a common starting point on May 2, 2021.
Both series are normalized to a base value of 100 on that date, allowing direct visual comparison of percentage growth or decline over time.
Thematic Portfolio: Quantum Computing & Core TechThis indicator tracks the aggregated performance of a curated thematic portfolio representing the Quantum Computing & Core Technology sector.
It combines leading equities and ETFs with predefined weights to reflect a diversified exposure across quantum hardware, AI infrastructure, and semiconductor backbones.
Composition:
Stocks: Rigetti (RGTI), IonQ (IONQ), D-Wave (QBTS), Palantir (PLTR), Intel (INTC), Arqit (ARQQ)
ETFs: BUG, QTUM, SOXX, IHAK
Methodology:
Each component’s normalized performance is weighted according to its strategic importance within the theme (R&D intensity, infrastructure leverage, and hardware dependence). The indicator dynamically aggregates the weighted series to visualize the cumulative return of the quantum computing ecosystem versus traditional benchmarks.
Intended use:
Compare thematic returns vs. S&P 500 or NASDAQ
Identify macro inflection points in the quantum tech narrative
Backtest thematic exposure strategies or structure twin-win / delta-one certificates
Note: This script is for analytical and educational purposes only and does not constitute financial advice.
Simple Moving AveragesIn Pine Script v6, the standard method for plotting indicators is still the plot function, and it should be recognized. However, if you are getting an "Undeclared identifier 'plot'" error, double-check these points:
Make sure your script is still using indicator() (not study()) at the top.
The script must not use indentation or syntax errors that break context.
Confirm Pine Script version is set correctly with //@version=6.
Here is a fully corrected Pine Script v6 template for your moving averages scenario using
Flux AI PullBack System (Hybrid Pro)Flux AI PullBack System (Hybrid Pro)
//Session-Aware | Adaptive Confluence | Grace Confirm Logic//
Overview:
The Flux AI PullBack System (Hybrid Pro v5) is an adaptive, session-aware pullback indicator designed to identify high-probability continuation setups within trending markets. It automatically adjusts between “Classic” and “Enhanced” logic modes based on volatility, volume, and ATR slope, allowing it to perform seamlessly across different market sessions (Asian, London, and New York).
Core Features:
Hybrid Auto Mode — Dynamically switches between Classic (fast-moving) and Enhanced (strict) modes.
Session-Aware Context — Optimized for intraday trading in ES, NQ, and SPY.
Grace Confirmation Logic — Validates pullbacks with a follow-through condition to reduce noise.
Adaptive EMA Zone (38/62) — Highlights pullback areas with dynamic aqua fill and transparency linked to trend strength.
Noise Suppression Filter — Prevents false pullbacks during EMA crossovers or unstable transitions.
Weighted Confluence Model — Combines trend, ATR, volume, and swing structure for confirmation strength.
Pine v6 Compliant Alerts — Constant-string safe, ready for webhooks and automation.
Visual Elements:
Aqua EMA Zone: Displays the “breathing” pullback band (tightens during volatility spikes).
PB↑ / PB↓ Markers: Confirmed pullbacks with subtle transparency and fixed label size.
Bar Highlights: Yellow for pullbacks; ice-blue for confirmed continuation.
Use Cases
Perfect for:
Intraday trend traders
0DTE SPX / ES scalpers
Futures traders (NQ, MNQ, MES)
Algorithmic strategy builders using webhooks
Recommended Timeframes:
1–15 minute charts (scalping / intraday)
Higher timeframes for swing confirmations.
Attribution:
This open-source script was inspired by Chris Moody’s “CM Slingshot System” and JustUncleL’s Pullback Tools, but it was built from scratch using AI-assisted code refinement (ChatGPT).
All logic and enhancements are original, not derived from proprietary software.
License: MIT (Open Source)
© 2025 Ken Anderson — You may modify, use, or redistribute with credit.
Keywords:
Pullback, Reversal, AI Trading, EMA Zone, Session Aware, Futures Trading, SPX, ES, NQ, ATR Filter, Volume Confirmation, Flux System, Pine Script v6, Non-Repainting, Adaptive Trading Indicator.
FVG_Liquidity_SignalFVGs: classic 3-bar gaps (bullish when low > high , bearish when high < low ). Zones are drawn and auto-pruned.
Liquidity sweep: price takes out the last swing low/high (pivot) and then reclaims it on the close.
Signals:
BUY when we get a bull sweep and the bar taps a recent bull FVG and closes back above its upper edge.
SELL is the mirror image.
SL/TP guides: SL at swept swing; TP = RR × risk (visual only).
FVG Donchian Channel strategy30min FVG + Donchian Channel strategy
buy sell by 30min fvg
and stoploss , take profit by Donchian Channel
Run the strategy on the 1min timeframe!
Mercury Retrograde — Daily boxes & bottom % (stable v6)水星逆行のアノマリー検証。対象は日経225の過去5年の値動き。水星逆行開始時の終値と水星逆行終了時の終値を比較。上昇率・下落率に応じて色分け。
Verification of Mercury Retrograde Anomalies. Subject: Nikkei 225 price movements over the past five years. Comparing closing prices at the start and end of Mercury retrograde periods. Color-coded based on percentage increase/decrease.
Bullish & Bearish Reversal Pattern with Sequential Bars20 Bollinger Bands and custom Stochasti_MTM Setup
Both long and short reversal signals.
Triple EMA (5, 8, 13) + Confirmed Alerts with SoundThis indicator uses three Exponential Moving Averages (EMA 5, 8, and 13) to generate buy and sell signals when the EMAs are properly aligned and not touching. Signals are confirmed on candle close and can trigger customizable sound alerts directly from the TradingView alert panel.
3C FractalsIts based on Williams Fractals indicator, but instead of using 5 candles to mark the fractals, it uses only 3.
Momentum Breakout Filter + ATR ZonesMomentum Breakout Filter + ATR Zones - User Guide
What This Indicator Does
This indicator helps you with your MACD + volume momentum strategy by:
Filtering out fake breakouts - Shows ⚠️ warnings when breakouts lack confirmation
Showing clear entry signals - 🚀 LONG and 🔻 SHORT labels when all conditions align
Automatic stop loss & profit targets - Based on ATR (Average True Range)
Visual trend confirmation - Background color + EMA alignment
Signal Types
🚀 LONG Entry Signal (Green Label)
Appears when ALL conditions met:
✅ MACD crosses above signal line
✅ Volume > 1.5× average
✅ Price > EMA 9 > EMA 21 > EMA 200 (bullish trend)
✅ Price closes above recent 20-bar high
🔻 SHORT Entry Signal (Red Label)
Appears when ALL conditions met:
✅ MACD crosses below signal line
✅ Volume > 1.5× average
✅ Price < EMA 9 < EMA 21 < EMA 200 (bearish trend)
✅ Price closes below recent 20-bar low
⚠️ FAKE Breakout Warning (Orange Label)
Appears when price breaks high/low BUT lacks confirmation:
❌ Low volume (below 1.5× average), OR
❌ Wick break only (didn't close through level), OR
❌ MACD not aligned with direction
Hover over the warning label to see what's missing!
ATR Stop Loss & Targets
When you get a signal, colored lines automatically appear:
Long Position
Red solid line = Stop Loss (Entry - 1.5×ATR)
Green dashed lines = Profit Targets:
Target 1: Entry + 2×ATR
Target 2: Entry + 3×ATR
Target 3: Entry + 4×ATR
Short Position
Red solid line = Stop Loss (Entry + 1.5×ATR)
Green dashed lines = Profit Targets:
Target 1: Entry - 2×ATR
Target 2: Entry - 3×ATR
Target 3: Entry - 4×ATR
The lines move with each bar until you exit the position.
Chart Elements
Moving Averages
Blue line = EMA 9 (fast)
Orange line = EMA 21 (medium)
White line = EMA 200 (trend filter)
Volume
Yellow bars = High volume (above threshold)
Gray bars = Normal volume
Background Color
Light green = Bullish trend (all EMAs aligned up)
Light red = Bearish trend (all EMAs aligned down)
No color = Neutral/mixed
MACD (Bottom Pane)
Green/Red columns = MACD Histogram
Blue line = MACD Line
Orange line = Signal Line
Info Dashboard (Bottom Right)
ItemWhat It ShowsVolumeCurrent volume vs average (✓ HIGH or ✗ Low)MACDDirection (BULLISH or BEARISH)TrendEMA alignment (BULL, BEAR, or NEUTRAL)ATRCurrent ATR value in dollarsPositionCurrent position (LONG, SHORT, or NONE)R:RRisk-to-Reward ratio (shows when in position)
How To Use It
Basic Workflow
Wait for setup
Watch for MACD to approach signal line
Volume should be building
Price should be near EMA structure
Get confirmation
Wait for 🚀 LONG or 🔻 SHORT label
Check dashboard shows "✓ HIGH" volume
Verify trend is aligned (green or red background)
Enter the trade
Enter when signal appears
Note your stop loss (red line)
Note your targets (green dashed lines)
Manage the trade
Exit at first target for partial profit
Move stop to breakeven
Trail remaining position
What To Avoid
❌ Don't trade when you see:
⚠️ FAKE labels (wait for confirmation)
Neutral background (no clear trend)
"✗ Low" volume in dashboard
MACD and Trend not aligned
Settings You Can Adjust
Volume Sensitivity
High Volume Threshold: Default 1.5×
Increase to 2.0× for cleaner signals (fewer trades)
Decrease to 1.2× for more signals (more trades)
Fake Breakout Filters
You can toggle these ON/OFF:
Volume Confirmation: Requires high volume
Close Through: Requires candle close, not just wick
MACD Alignment: Requires MACD direction match
Tip: Turn all three ON for highest quality signals
ATR Stop/Target Multipliers
Default settings (conservative):
Stop Loss: 1.5×ATR
Target 1: 2×ATR (1.33:1 R:R)
Target 2: 3×ATR (2:1 R:R)
Target 3: 4×ATR (2.67:1 R:R)
Aggressive traders might use:
Stop Loss: 1.0×ATR
Target 1: 2×ATR (2:1 R:R)
Target 2: 4×ATR (4:1 R:R)
Conservative traders might use:
Stop Loss: 2.0×ATR
Target 1: 3×ATR (1.5:1 R:R)
Target 2: 5×ATR (2.5:1 R:R)
Example Trade Scenarios
Scenario 1: Perfect Long Setup ✅
Stock consolidating near EMA 21
MACD curling up toward signal line
Volume bar turns yellow (high volume)
🚀 LONG label appears
Red stop line and green target lines appear
Result: High probability trade
Scenario 2: Fake Breakout Avoided ✅
Price breaks above resistance
Volume is normal (gray bar)
⚠️ FAKE label appears (hover shows "Low volume")
No entry signal
Price falls back below breakout level
Result: Avoided losing trade
Scenario 3: Premature Entry ❌
MACD crosses up
Volume is high
BUT trend is NEUTRAL (no background color)
No signal appears (trend filter blocks it)
Result: Avoided choppy/sideways market
Quick Reference
Entry Checklist
🚀 or 🔻 label on chart
Dashboard shows "✓ HIGH" volume
Dashboard shows aligned MACD + Trend
Colored background (green or red)
ATR lines visible
No ⚠️ FAKE warning
Exit Strategy
Target 1 (2×ATR): Take 50% profit, move stop to breakeven
Target 2 (3×ATR): Take 25% profit, trail stop
Target 3 (4×ATR): Take remaining profit or trail aggressively
Stop Loss: Exit entire position if hit
Alerts
Set up these alerts:
Long Entry: Fires when 🚀 LONG signal appears
Short Entry: Fires when 🔻 SHORT signal appears
Fake Breakout Warning: Fires when ⚠️ appears (optional)
Tips for Success
Use on 5-minute charts for day trading momentum plays
Only trade high volume stocks ($5-20 range works best)
Wait for full confirmation - don't jump early
Respect the stop loss - it's calculated based on volatility
Scale out at targets - don't hold for home runs
Avoid trading first 15 minutes - let market settle
Best during 10am-11am and 2pm-3pm - peak momentum times
Common Questions
Q: Why didn't I get a signal even though MACD crossed?
A: All conditions must be met - check dashboard for what's missing (likely volume or trend alignment)
Q: Can I use this on any timeframe?
A: Yes, but it's designed for 5-15 minute charts. On daily charts, adjust ATR multipliers higher.
Q: The stop loss seems too tight, can I widen it?
A: Yes, increase "Stop Loss (×ATR)" from 1.5 to 2.0 or 2.5 in settings.
Q: I keep seeing FAKE warnings but price keeps going - what gives?
A: The filter is conservative. You can disable some filters in settings, but expect more false signals.
Q: Can I use this for swing trading?
A: Yes, but use larger timeframes (1H or 4H) and adjust ATR multipliers up (3× for stops, 6-9× for targets).






















