//@version=5
indicator("YingYang Algo", overlay=true, max_labels_count = 500)
// Input parameters for Supertrend
factor = input.float(3.0, "Supertrend Factor", step=0.1)
atrPeriod = input.int(1, "Supertrend ATR Period", minval=1)
// Input parameters for Moving Average
maPeriod = input.int(27, "Sensitivity", minval=1)
maType = input.string("SMA", "Moving Average Type", options=["SMA", "EMA"])
// Calculate ATR and basic upper/lower bands for Supertrend
atr = ta.atr(atrPeriod)
hl2 = (high + low) / 2
upperBand = hl2 + factor * atr
lowerBand = hl2 - factor * atr
// Initialize Supertrend variables
var float supertrend = na
var int trend = 1 // 1 for uptrend, -1 for downtrend
// Supertrend calculation
if barstate.isfirst
supertrend := lowerBand
else
if close > supertrend[1]
trend := 1
else if close < supertrend[1]
trend := -1
else
trend := trend[1]
if trend == 1
supertrend := math.max(lowerBand, supertrend[1])
else
supertrend := math.min(upperBand, supertrend[1])
// Calculate Moving Average of Supertrend
ma = maType == "SMA" ? ta.sma(supertrend, maPeriod) : ta.ema(supertrend, maPeriod)
// Generate reversal signals based on crossover
longSignal = ta.crossover(supertrend, ma)
shortSignal = ta.crossunder(supertrend, ma)
// Plot Supertrend
plot(supertrend, color=color.blue, linewidth=2, title="Supertrend")
y1 = low - (ta.atr(30) * 0.5)
y2 = high + (ta.atr(30) * 0.5)
if (longSignal)
label.new(bar_index , y1, '▲', color=color.new(#018208,10),
style=label.style_label_up, textcolor=color.white, size=size.normal)
if (shortSignal)
label.new(bar_index , y2, '▼', color=color.new(#d12208,10),
style=label.style_label_down, textcolor=color.white, size=size.normal)
// Bar Coloring
// Trend Follower
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
smoothrng = ta.ema(avrng, wper) * m
smoothrng
smrng = smoothrng(close, 22, 6)
rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r
: x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
rngfilt
filt = rngfilt(close, smrng)
//
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
upward = 0.0
upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 :
nz(downward[1])
filtcolor = upward > 0 ? color.new(#30ff30, 50) : downward > 0 ? color.new(#dc0000,
50) : color.new(#56328f, 0)
trailType = 'modified'
ATRPeriod = 13
ATRFactor = 4
smoothing = 8
norm_o = request.security(ticker.new(syminfo.prefix, syminfo.ticker),
timeframe.period, open)
norm_h = request.security(ticker.new(syminfo.prefix, syminfo.ticker),
timeframe.period, high)
norm_l = request.security(ticker.new(syminfo.prefix, syminfo.ticker),
timeframe.period, low)
norm_c = request.security(ticker.new(syminfo.prefix, syminfo.ticker),
timeframe.period, close)
//}
// Bar Coloring
//{
// Wilders ma //
Wild_ma(_src, _malength) =>
_wild = 0.0
_wild := nz(_wild[1]) + (_src - nz(_wild[1])) / _malength
_wild
/////////// TRUE RANGE CALCULATIONS /////////////////
HiLo = math.min(norm_h - norm_l, 1.5 * nz(ta.sma(norm_h - norm_l, ATRPeriod)))
HRef = norm_l <= norm_h[1] ? norm_h - norm_c[1] : norm_h - norm_c[1] - 0.5 *
(norm_l - norm_h[1])
LRef = norm_h >= norm_l[1] ? norm_c[1] - norm_l : norm_c[1] - norm_l - 0.5 *
(norm_l[1] - norm_h)
trueRange = trailType == 'modified' ? math.max(HiLo, HRef, LRef) : math.max(norm_h
- norm_l, math.abs(norm_h - norm_c[1]), math.abs(norm_l - norm_c[1]))
//}
/////////// TRADE LOGIC ////////////////////////
//{
loss = ATRFactor * Wild_ma(trueRange, ATRPeriod)
Up = norm_c - loss
Dn = norm_c + loss
TrendUp = Up
TrendDown = Dn
Trend = 1
TrendUp := norm_c[1] > TrendUp[1] ? math.max(Up, TrendUp[1]) : Up
TrendDown := norm_c[1] < TrendDown[1] ? math.min(Dn, TrendDown[1]) : Dn
Trend := norm_c > TrendDown[1] ? 1 : norm_c < TrendUp[1] ? -1 : nz(Trend[1], 1)
trail = Trend == 1 ? TrendUp : TrendDown
ex = 0.0
ex := ta.crossover(Trend, 0) ? norm_h : ta.crossunder(Trend, 0) ? norm_l : Trend ==
1 ? math.max(ex[1], norm_h) : Trend == -1 ? math.min(ex[1], norm_l) : ex[1]
//}
// //////// PLOT TP and SL /////////////
////// FIBONACCI LEVELS ///////////
//{
state = Trend == 1 ? 'long' : 'short'
barcolorfunction = upward > 0 and state == 'long' ? #05df09 : downward > 0 and
state == 'short' ? #ea0402 : #673ab7
barcolor(barcolorfunction)
//
///// Delete This Part for removing countdown /////////
halvingDay = 124
halvingHour = 06
halvingMinute = 22
halvingStamp = timestamp('GMT', 2024, 12, 5, halvingHour, halvingMinute, 0)
secondsRaw = math.floor((halvingStamp - timenow) / 1000)
minutesRaw = math.floor(secondsRaw / 60)
hoursRaw = math.floor(minutesRaw / 60)
seconds = secondsRaw % 60
minutes = minutesRaw % 60
hours = hoursRaw % 24
days = math.floor(hoursRaw / 24)
f_format(_val) =>
(0 < _val and _val < 10 ? '0' : '') + str.tostring(_val, '##') + (_val == 0 ?
'0' : '')
labelText = 'To open www.algopoint.co ' + f_format(days) + ' days ' +
f_format(hours) + ' hours ' + f_format(minutes) + ' minutes \n\n'
lapos_x = timenow + math.round(ta.change(time) * 60)
labelllalala = ' but algopoint.mysellix.io is open until then. dont miss the free
and paid indicators.'
var label l = label.new(x=lapos_x, y=na, text='', textcolor=color.white,
style=label.style_label_up, xloc=xloc.bar_time, size=size.huge)
label.set_text(l, labelText + labelllalala)
label.set_xy(l, lapos_x, ta.highest(60))