// This source code is subject to the terms of the Mozilla Public License 2.
0 at
[Link]
// © Chartprime
//@version=5
indicator("Swing Ranges [ChartPrime]",overlay = true,max_boxes_count =
500,max_bars_back = 300)
color Offwhite = [Link](255, 255, 255, 71)
color _offwhite = [Link](255, 255, 255, 50)
color Red1 = [Link](255, 82, 82, 85)
color Red2 = [Link](243, 6, 6, 50)
color green = [Link](73, 241, 241, 85)
color green2 = [Link](73, 241, 241, 50)
color Black = [Link](7, 7, 7)
color Yellow = [Link](254, 229, 4)
int atrLen = 30
float mult = 0.3
float per = 5.0
var float prevHigh = na
var float prevLow = na
var int prevHighIndex = na
var int prevLowIndex = na
int sync = bar_index
int swingbars = [Link](20, 'Swing Length',
tooltip='Bar # for swings' )
int ATRPeriod = [Link](14, 'ATR Period' )
bool showHis = [Link](true,"Show Historical
Boxes")
bool showPOC = [Link](true,"Show VWAP
POC",inline = "!")
color POCcolor = [Link](#46ecf8,"",inline =
"!")
float pivHi = [Link](high, swingbars,
swingbars)
float pivLo = [Link](low, swingbars,
swingbars)
float atr = [Link](ATRPeriod)
float atrPercent = (atr/close) * 100
// --- {Arrays
var box [] LevelsBOX = array.new_box()
var label [] Levelslabel = array.new_label()
float [] Volume = array.new_float()
float [] TotalVolume = array.new_float()
float [] Greenvolume = array.new_float()
float [] redvolume = array.new_float()
float [] ATR = array.new_float()
float [] VWAP = array.new_float()
// -- }
//Piv levels
if not na(pivHi)
prevHigh := pivHi
prevHighIndex := sync - swingbars
if not na(pivLo)
prevLow := pivLo
prevLowIndex := sync - swingbars
DPlace(data,sign) =>
if sign == "+"
data + (data * 0.0015)
else if sign == "-"
data - (data * 0.0015)
dump = (pivLo - prevHigh) / prevHigh * 100
pump = (pivHi - prevLow) / prevLow * 100
perc = close * (per/100)
srdatr = [Link] (atrLen) * mult
band = [Link] (srdatr, perc) [swingbars] /2
HH = DPlace(prevHigh,"+") +band
HL = DPlace(prevHigh,"+") -band
LH = DPlace(prevLow,"-") +band
LL = DPlace(prevLow,"-") -band
Volume(GV,RV,TV,BC)=>
GR = GV / TV
RR = RV / TV
GI = int(GR * BC)
RI = int(RR * BC)
[GI , RI , GR , RR]
Message(dir)=>
Message = ""
Message+= dir == pump ? "Price pumped : " +
[Link]([Link](pump,2),[Link]) + " %\n" : "Price dumped :" +
[Link]([Link](dump,2),[Link]) + "\n"
Message+= "ATR avarage : " +
[Link]([Link]([Link](ATR),4),[Link]) + "\n"
Message+= "VWAP Mean : " + [Link]([Link](VWAP),[Link]) + "\
n"
Message+= "Volume avarage : " + [Link]([Link](Volume),[Link])
+ "\n"
Message+= "BAR count: " + [Link]([Link](Volume)) + "\n"
if prevLow[1] != prevLow and showHis
BIndex = int(((sync - swingbars) - prevHighIndex))
for i = 0 to BIndex
[Link](Volume,[Link](volume[swingbars + i],2))
[Link](ATR,atrPercent[swingbars + i])
[Link](VWAP,[Link][swingbars + i])
if [Link](Volume) > BIndex +1
[Link](Volume)
[Link](ATR)
[Link](prevHighIndex,
prevHigh,
sync - swingbars,
pivLo,
bgcolor = Red1,
border_color =Red2,
border_width = 1)
[Link](prevHighIndex + int(((sync - swingbars) - prevHighIndex) / 2),
prevHigh,text = "",
tooltip = Message(dump),
size = [Link],
color = Red2)
[Link](prevHighIndex,
[Link](VWAP),
sync - swingbars,
[Link](VWAP),
color = Yellow,
width = 2)
if prevHigh[1] != prevHigh and showHis
BIndex = int(((sync - swingbars) - prevLowIndex))
for i = 0 to BIndex
[Link](Volume,[Link](volume[swingbars + i],2))
[Link](ATR,atrPercent[swingbars + i])
[Link](VWAP,[Link][swingbars + i])
if [Link](Volume) > BIndex +1
[Link](Volume)
[Link](ATR)
[Link](prevLowIndex,
pivHi,
sync - swingbars,
prevLow,
bgcolor =green,
border_color = green2,
border_width = 1)
[Link](prevLowIndex + int(((sync - swingbars) - prevLowIndex) / 2) ,
prevLow,
text = "",
tooltip = Message(pump),
size = [Link],
color = green2,
style = label.style_label_up)
if prevHigh > [Link](VWAP)
[Link](prevLowIndex,
[Link](VWAP),
sync - swingbars,
[Link](VWAP),
color = Yellow,
width = 2)
if [Link]
BIndex = int(((sync - swingbars) - prevHighIndex))
for i = 0 to BIndex
[Link](Volume,[Link](volume[swingbars + i],2))
[Link](ATR,atrPercent[swingbars + i])
[Link](VWAP,[Link][swingbars + i])
if [Link](Volume) > BIndex +1
[Link](Volume)
[Link](ATR)
Bindex = sync - prevHighIndex
IndexB = (sync + 50 )- prevHighIndex
for i = 1 to Bindex
if close[i] > open[i]
[Link](Greenvolume,volume[i])
if close[i] < open[i]
[Link](redvolume,volume[i])
[Link](TotalVolume,volume[i])
[GI , RI,GR,RR ] =
Volume([Link](Greenvolume),[Link](redvolume),[Link](TotalVolume),IndexB)
colorS = close > LH ? green : Red1 , ColorB = close > LH ? green2 : Red2
_colorS = close > HH ? green : Red1 , _ColorB = close > HH ? green2 : Red2
leftover = 100 - ((RR + GR) * 100 )
[Link](LevelsBOX,
[Link](prevHighIndex,
LH,
sync + 50,
LL,
bgcolor = colorS,
border_color =ColorB,
border_width = 1))
[Link](LevelsBOX,
[Link](prevHighIndex,
HH,
sync + 50,
HL,
bgcolor = _colorS,
border_color =_ColorB,
border_width = 1))
[Link](LevelsBOX,
[Link](prevHighIndex,
LH,
prevHighIndex + GI,
LL,
bgcolor = Offwhite,
border_color =_offwhite,
border_width = 1,
text = "Bull Volume",
text_size = [Link],
text_color = Black))
[Link](LevelsBOX,
[Link](prevHighIndex,
HH,
prevHighIndex + RI,
HL,
bgcolor = Offwhite,
border_color =_offwhite,
border_width = 1,
text = "Bear Volume",
text_size = [Link],
text_color = Black))
[Link](Levelslabel,
[Link](prevHighIndex + ( GI + 9 ),
(LL + LH) / 2,
[Link]([Link](GR * 100,2)) + " %",
xloc = xloc.bar_index,
style = label.style_label_left,
textcolor= [Link],
color = [Link]([Link], 100)))
[Link](Levelslabel,
[Link](prevHighIndex + ( RI + 9 ),
(HL + HH) / 2,
[Link]([Link](RR * 100,2)) + " %",
xloc = xloc.bar_index,
style = label.style_label_left,
textcolor= [Link],
color = [Link]([Link], 100)))
var line POC = na , [Link](POC)
if showPOC
POC:=[Link](prevHighIndex,
[Link](VWAP),
sync + 50,
[Link](VWAP),
color = POCcolor,
width = 2,
style = line.style_dotted)
var box left = na , [Link](left)
if leftover > 0
left:=[Link](prevHighIndex + ( RI + 20 ),
HH,
prevHighIndex + ( RI + 30 ),
HL,
bgcolor = [Link](255, 137, 68, 15),
border_color =[Link](255, 137, 68, 8),
border_width = 1,
text = "NV " + [Link]([Link](leftover,2)) +" %",
text_size = [Link],
text_color = Black)
if [Link](LevelsBOX) > 4
for i = 0 to 3
[Link]([Link](LevelsBOX))
if [Link](Levelslabel) > 2
for i = 0 to 1
[Link]([Link](Levelslabel))
Combine this indicator with this indicator with this indicator without losing any
of the functioning. I should be able to turn on and off both the indicators
//@version=6
indicator(" 4 in1 UT Bot Alerts + 2 EMAs + ADX + Supertrend", overlay = true)
// === Inputs ===
a = [Link](1, title = "Key Value (sensitivity)")
c = [Link](10, title = "ATR Period")
h = [Link](false, title = "Use Heikin Ashi Candles")
// === EMA Inputs ===
showFastEMA = [Link](true, title="Show Fast EMA (13)")
fastEMALen = [Link](13, title="Fast EMA Length")
showSlowEMA = [Link](true, title="Show Slow EMA (26)")
slowEMALen = [Link](26, title="Slow EMA Length")
// === ADX Inputs ===
adxLength = [Link](14, title="ADX Length")
// === Supertrend Inputs ===
showSupertrend = [Link](true, title="Show Supertrend")
stAtrPeriod = [Link](10, title="Supertrend ATR Length")
stFactor = [Link](3.0, title="Supertrend Factor", step=0.01)
// === Supertrend Calculation ===
[supertrend, direction] = [Link](stFactor, stAtrPeriod)
supertrendPlotUp = plot(showSupertrend and direction < 0 ? supertrend : na,
"Supertrend Up", color=[Link], style=plot.style_linebr)
supertrendPlotDown = plot(showSupertrend and direction > 0 ? supertrend : na,
"Supertrend Down", color=[Link], style=plot.style_linebr)
bodyMiddle = plot(showSupertrend ? (open + close)/2 : na, "Body Middle",
display=[Link])
fill(bodyMiddle, supertrendPlotUp, [Link]([Link], 90))
fill(bodyMiddle, supertrendPlotDown, [Link]([Link], 90))
// === Supertrend Alerts ===
alertcondition(direction[1] > direction, title='Downtrend to Uptrend',
message='Supertrend changed from Downtrend to Uptrend')
alertcondition(direction[1] < direction, title='Uptrend to Downtrend',
message='Supertrend changed from Uptrend to Downtrend')
alertcondition(direction[1] != direction, title='Supertrend Trend Change',
message='Supertrend trend flipped')
// === ATR Trailing Stop Logic ===
xATR = [Link](c)
nLoss = a * xATR
// Heikin Ashi Handling
src = h ? [Link]([Link], [Link], close) : close
var float xATRTrailingStop = na
xATRTrailingStop := src > nz(xATRTrailingStop[1]) and src[1] >
nz(xATRTrailingStop[1]) ? [Link](nz(xATRTrailingStop[1]), src - nLoss) :
src < nz(xATRTrailingStop[1]) and src[1] <
nz(xATRTrailingStop[1]) ? [Link](nz(xATRTrailingStop[1]), src + nLoss) :
src > nz(xATRTrailingStop[1]) ? src - nLoss : src + nLoss
// === Position Tracking Logic ===
var int pos = 0
newPos = src[1] < nz(xATRTrailingStop[1]) and src > nz(xATRTrailingStop[1]) ? 1 :
src[1] > nz(xATRTrailingStop[1]) and src < nz(xATRTrailingStop[1]) ? -1 :
pos
pos := newPos
xcolor = pos == -1 ? [Link] : pos == 1 ? [Link] : [Link]
// === EMAs ===
fastEMA = [Link](src, fastEMALen)
slowEMA = [Link](src, slowEMALen)
plot(showFastEMA ? fastEMA : na, color=[Link], linewidth=1, title="Fast EMA
(13)")
plot(showSlowEMA ? slowEMA : na, color=[Link], linewidth=1, title="Slow EMA
(26)")
// === UT Bot Alerts ===
ema1 = [Link](src, 1)
above = [Link](ema1, xATRTrailingStop)
below = [Link](xATRTrailingStop, ema1)
buy = src > xATRTrailingStop and above
sell = src < xATRTrailingStop and below
barbuy = src > xATRTrailingStop
barsell = src < xATRTrailingStop
plotshape(buy, title="Buy", text="Buy", style=[Link],
location=[Link], color=[Link], textcolor=[Link],
size=[Link])
plotshape(sell, title="Sell", text="Sell", style=[Link],
location=[Link], color=[Link], textcolor=[Link], size=[Link])
barcolor(barbuy ? [Link] : na)
barcolor(barsell ? [Link] : na)
alertcondition(buy, "UT Long", "UT Long Signal")
alertcondition(sell, "UT Short", "UT Short Signal")
// === ADX ===
upMove = high - high[1]
downMove = low[1] - low
plusDM = (upMove > downMove and upMove > 0) ? upMove : 0
minusDM = (downMove > upMove and downMove > 0) ? downMove : 0
trur = [Link]([Link], adxLength)
plusDI = 100 * [Link](plusDM, adxLength) / trur
minusDI = 100 * [Link](minusDM, adxLength) / trur
dx = 100 * [Link](plusDI - minusDI) / (plusDI + minusDI)
adx = [Link](dx, adxLength)
// === ADX Label ===
var label adxLabel = [Link](x=na, y=na, text="", style=label.style_label_right,
textcolor=[Link], size=[Link], color=[Link])
label.set_xy(adxLabel, bar_index, high + trur * 1.5)
label.set_text(adxLabel, "ADX: " + [Link](adx, [Link]))
label.set_textcolor(adxLabel, adx >= 25 ? [Link] : [Link])