EMA & Golden Cross
EMA & Golden Cross
EMA & Golden Cross
inRange(cond) =>
bars = ta.barssince(cond==true)
rangeLower <= bars and bars <= rangeUpper
//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low
//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low
//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High
xxx = input.bool(false,"──────────────────")
hdiv = input.bool(true,"Hidden Bullish Div")
hb = hdiv? hiddenBullCond : false
var check = 10
if hb or bullCond
check := 10
if gc
check:=check-1
a = 20/(ta.highest(ma1/ma2-1,100)-ta.lowest(ma1/ma2-1,100))
plot(((ma1/ma2)-1)*a+50,"ma1",color=color.red)
// Input:
var int n = input.int(10, title="Fractal Periods", minval=2)
//
for i = 1 to n
upflagDown := upflagDown and (osc[n-i] < osc[n])
upflagUp0 := upflagUp0 and (osc[n+i] < osc[n])
upflagUp1 := upflagUp1 and (osc[n+1] <= osc[n] and osc[n+i + 1] < osc[n])
upflagUp2 := upflagUp2 and (osc[n+1] <= osc[n] and osc[n+2] <= osc[n] and
osc[n+i + 2] < osc[n])
upflagUp3 := upflagUp3 and (osc[n+1] <= osc[n] and osc[n+2] <= osc[n] and
osc[n+3] <= osc[n] and osc[n+i + 3] < osc[n])
upflagUp4 := upflagUp4 and (osc[n+1] <= osc[n] and osc[n+2] <= osc[n] and
osc[n+3] <= osc[n] and osc[n+4] <= osc[n] and osc[n+i + 4] < osc[n])
flagUp = upflagUp0 or upflagUp1 or upflagUp2 or upflagUp3 or upflagUp4
for i = 1 to n
downflagDown := downflagDown and (osc[n-i] > osc[n])
downflagUp0 := downflagUp0 and (osc[n+i] > osc[n])
downflagUp1 := downflagUp1 and (osc[n+1] >= osc[n] and osc[n+i + 1] > osc[n])
downflagUp2 := downflagUp2 and (osc[n+1] >= osc[n] and osc[n+2] >= osc[n] and
osc[n+i + 2] > osc[n])
downflagUp3 := downflagUp3 and (osc[n+1] >= osc[n] and osc[n+2] >= osc[n] and
osc[n+3] >= osc[n] and osc[n+i + 3] > osc[n])
downflagUp4 := downflagUp4 and (osc[n+1] >= osc[n] and osc[n+2] >= osc[n] and
osc[n+3] >= osc[n] and osc[n+4] >= osc[n] and osc[n+i + 4] > osc[n])
flagDown = downflagUp0 or downflagUp1 or downflagUp2 or downflagUp3 or downflagUp4
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * *
// Auto trendlines
// Input:
var string GROUP_ATL = "Auto trendlines"
var int LINE_WIDTH1 = 1, var string LINE_WIDTH1_STR = "Width 1"
var int LINE_WIDTH2 = 2, var string LINE_WIDTH2_STR = "Width 2"
//
// Recent fractals.
var float recent_dn1 = osc, var int i_recent_dn1 = bar_index
var float recent_up1 = osc, var int i_recent_up1 = bar_index
var float recent_dn2 = osc, var int i_recent_dn2 = bar_index
var float recent_up2 = osc, var int i_recent_up2 = bar_index
// @function : Clean up
// @param arr : either arr_ln_up/arr_ln_dn should be passed into it.
// @returns void : To delete excess lines and assign new color to historical lines.
cleanup(line[] arr) =>
if array.size(arr) > 1
line.set_color(array.get(arr, 1), ln_col_prev)
line.set_width(array.get(arr, 1), lnwidth_prev)
while array.size(arr) > math.floor(max_tl/2)
line.delete(array.pop(arr))
if upfract
recent_up2:=recent_up1
i_recent_up2:=i_recent_up1
recent_up1:=osc[n+1]
i_recent_up1 := bar_index-n-1
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * *
// Finding crosses
// Linear extrapolation
// Solving for price at current x (bar_index), given two pairs of fractals with x
values < bar_index.
float m_dn = get_slope(i_recent_dn1, recent_dn1, i_recent_dn2, recent_dn2)
float y_dn = (m_dn * bar_index) + recent_dn1 - (m_dn * i_recent_dn1)