Professional Documents
Culture Documents
UT Bot ABC Waddah Attar Trendilo Strategy 9 Sierpnia 2023
UT Bot ABC Waddah Attar Trendilo Strategy 9 Sierpnia 2023
strategy(title="UT Bot ABC Waddah Attar Trendilo Strategy 9 sierpnia 2023", overlay = true)
// Inputs
a = input(1, title = "Key Vaule. 'This changes the sensitivity'")
c = input(10, title = "ATR Period")
h = input(false, title = "Signals from Heikin Ashi Candles")
xATR = atr(c)
nLoss = a * xATR
xATRTrailingStop = 0.0
xATRTrailingStop := iff(src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1])
iff(src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), src + nLoss),
iff(src > nz(xATRTrailingStop[1], 0), src - nLoss, src + nLoss)))
pos = 0
pos := iff(src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0), 1,
iff(src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0)))
ema = ema(src,1)
above = crossover(ema, xATRTrailingStop)
below = crossover(xATRTrailingStop, ema)
plotshape(buy, title = "Buy", text = '', style = shape.labelup, location = location.belowbar, color= color.green, textcolor
plotshape(sell, title = "Sell", text = '', style = shape.labeldown, location = location.abovebar, color= color.red, textcolor
//"ABC UT alert", overlay = true, max_bars_back = 500, max_lines_count = 500, max_labels_count = 500)
prd = input(defval = 8, title="ZigZag Period", minval = 2, maxval = 50, group = "Setup")
fiboup = input(defval = 0.618, title = "Fibonacci Max", group = "Setup")
fibodn = input(defval = 0.382, title = "Fibonacci Min", group = "Setup")
errorrate = input(defval = 5.0, title = "Error Rate", minval = 0, maxval = 30, group = "Setup") / 100
showabc = input(defval = true, title = "Show ABC", group = "Extras")
keepabc = input(defval = true, title = "Keep Old ABCs", group = "Extras")
showcloud = input(defval = true, title = "Show Cloud", group = "Extras", inline = "cloud")
c_upcol = input(defval = color.new(#125837, 75), title = "", group = "Extras", inline = "cloud")
c_dncol = input(defval = color.new(#831a1a, 75), title = "", group = "Extras", inline = "cloud")
showzigzag = input(defval = true, title = "Show Zig Zag & Fibo", group = "Extras", inline = "zigzag")
upcol = input(defval = color.rgb(0, 65, 33), title = "", group = "Extras", inline = "zigzag")
dncol = input(defval = color.rgb(102, 0, 0), title = "", group = "Extras", inline = "zigzag")
srcma = input(defval = close, title = "Source for Moving Averages", group = "Trend Cloud")
malen1 = input(defval = 10, title = "SMA 1 Length", minval = 1, group = "Trend Cloud")
malen2 = input(defval = 20, title = "SMA 2 Length", minval = 1, group = "Trend Cloud")
malen3 = input(defval = 55, title = "SMA 3 Length", minval = 1, group = "Trend Cloud")
malen4 = input(defval = 89, title = "SMA 4 Length", minval = 1, group = "Trend Cloud")
malen5 = input(defval = 20, title = "EMA 1 Length", minval = 1, group = "Trend Cloud")
malen6 = input(defval = 40, title = "EMA 2 Length", minval = 1, group = "Trend Cloud")
ma_array = array.new_float(6)
array.set(ma_array, 0, sma(srcma, malen1))
array.set(ma_array, 1, sma(srcma, malen2))
array.set(ma_array, 2, sma(srcma, malen3))
array.set(ma_array, 3, sma(srcma, malen4))
array.set(ma_array, 4, ema(srcma, malen5))
array.set(ma_array, 5, ema(srcma, malen6))
float umax = na
float umin = na
float lmax = na
float lmin = na
int upper = 0
int lower = 0
for x = 1 to 6
ma = array.get(ma_array, x -1)
if ma >= max(open, close)
upper := upper + 1
if na(umax)
umax := ma
umin := ma
else
umax := max(umax, ma)
umin := min(umin, ma)
else if ma <= min(open, close)
lower := lower + 1
if na(lmax)
lmax := ma
lmin := ma
else
lmax := max(lmax, ma)
lmin := min(lmin, ma)
//===================================================================
// zigzag part
get_ph_pl_dir(len)=>
float ph = highestbars(high, len) == 0 ? high : na
float pl = lowestbars(low, len) == 0 ? low : na
var dir = 0
dir := iff(ph and na(pl), 1, iff(pl and na(ph), -1, dir))
[ph, pl, dir]
var max_array_size = 10
var zigzag = array.new_float(0)
add_to_zigzag(value, bindex)=>
array.unshift(zigzag, bindex)
array.unshift(zigzag, value)
if array.size(zigzag) > max_array_size
array.pop(zigzag)
array.pop(zigzag)
update_zigzag(value, bindex)=>
if array.size(zigzag) == 0
add_to_zigzag(value, bindex)
else
if (dir == 1 and value > array.get(zigzag, 0)) or (dir == -1 and value < array.get(zigzag, 0))
array.set(zigzag, 0, value)
array.set(zigzag, 1, bindex)
0.
dir_changed = change(dir)
if ph or pl
if dir_changed
add_to_zigzag(dir == 1 ? ph : pl, bar_index)
else
update_zigzag(dir == 1 ? ph : pl, bar_index)
[l1_, l2_] = draw_line(dir, bar_index, array.get(zigzag, 0), round(array.get(abc, 1)), array.get(abc, 0), round(array.get
array.unshift(abclines, l1_)
array.unshift(abclines, l2_)
[la1_, la2_, la3_] = draw_label(dir, bar_index, array.get(zigzag, 0), round(array.get(abc, 1)), array.get(abc, 0), round
array.unshift(abclabels, la1_)
array.unshift(abclabels, la2_)
array.unshift(abclabels, la3_)
// bounce?
lbounced = false
sbounced = false
for i = 0 to 5
if min(low, low[1]) <= array.get(ma_array, i) and close > array.get(ma_array, i) and close > open
lbounced := true
if max(high, high[1]) >= array.get(ma_array, i) and close < array.get(ma_array, i) and close < open
sbounced := true
// long condition
long = trend == 1 and abc_bar_count <= 6 and lbounced and lll_ >= last_zz_point
short = trend == -1 and abc_bar_count <= 6 and sbounced and hhh_ <= last_zz_point
// Strategy Conditions
waddahUpTrend = (t1 >= 0)
trendiloUpTrend = (cdir > 0)
// Plotting
plotshape(waddahUpTrend, color = color.rgb(76, 175, 79, 43), style = shape.triangleup, title = "Waddah Up Trend")
plotshape(waddahDownTrend, color = color.rgb(255, 82, 82, 54), style = shape.triangledown, title = "Waddah Down Trend")
plotshape(trendiloUpTrend, color = color.rgb(255, 255, 255), style = shape.triangleup, title = "Trendilo Up Trend")
plotshape(trendiloDownTrend, color = color.rgb(255, 251, 0), style = shape.triangledown, title = "Trendilo Down Trend")
//"Najwyższa i Najniższa Cena Sesji", shorttitle="HHLL Session", overlay=true)
is_new_session = change(time("D"))
if is_new_session
sessionHigh := high
sessionLow := low
sessionOpen := open
line.delete(sessionHighLine)
line.delete(sessionLowLine)
sessionHighLine := line.new(x1=bar_index[1], y1=sessionHigh, x2=bar_index, y2=sessionHigh, color=color.rgb(253, 253, 253)
sessionLowLine := line.new(x1=bar_index[1], y1=sessionLow, x2=bar_index, y2=sessionLow, color=color.rgb(121, 0, 0), width
if not is_new_session
sessionHigh := max(sessionHigh, high)
sessionLow := min(sessionLow, low)
line.set_xy1(sessionHighLine, x=bar_index[1], y=sessionHigh)
line.set_xy2(sessionHighLine, x=bar_index, y=sessionHigh)
line.set_xy1(sessionLowLine, x=bar_index[1], y=sessionLow)
line.set_xy2(sessionLowLine, x=bar_index, y=sessionLow)
if change(time("D"))
highestHigh := high
lowestLow := low
fibHigh = highestHigh
fibLow = lowestLow
fibRange = fibHigh - fibLow