PowerX Strategy "PowerZ"

everything that doesn't belong elsewhere cometh here

Moderator: moderators

User avatar
IgazI
rank: 1000+ posts
rank: 1000+ posts
Posts: 2016
Joined: Sat Feb 17, 2018 5:28 pm
Reputation: 1663
Gender: None specified

Re: PowerX Strategy "PowerZ"

Postby IgazI » Mon Dec 12, 2022 4:58 am

Looks like the jig is up, boys.

"Everything Should Be Made As Simple As Possible, But Not Simpler!"

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.

User avatar
IgazI
rank: 1000+ posts
rank: 1000+ posts
Posts: 2016
Joined: Sat Feb 17, 2018 5:28 pm
Reputation: 1663
Gender: None specified

Re: PowerX Strategy "PowerZ"

Postby IgazI » Tue Dec 13, 2022 4:56 pm

I added some features to the BSW indicator:
- inputs for adjusting chart brightness and turning the dots on and off

Code: Select all

//@version=5
indicator(title = "Bodies Show The Way", shorttitle = "BSW", overlay = true)
h = high
l = low
c = high
o = low
candleTransp = input(65, title= "Darkness")
plotDot = input(true,title= "Plot Dots?")
join_HTF = input(false, title = "Connect:", inline = "2")
peri = input("", title = "Time Frame", inline = "2")
x = time_close(timeframe.period)
y = time_close(peri)
z = x[1] == y[1] ? close[1] : na
plot(peri != "" ? z : na,color = color.new(color.blue,50), offset = -1, style = plot.style_circles, linewidth = 2, trackprice = true)
plot(join_HTF and peri != "" ? z : na,color = color.new(color.blue,45), offset = -1, style = plot.style_line, linewidth = 4, display = display.all - display.price_scale)
plot_TRI = input(false, title = "Display:", inline = "1")
adj = input(0.0, title = "Adjust Triangles", inline = "1")
trend_CLR = close > high[1]? color.rgb(46, 112, 167) : close < low[1] ? color.red : color.white

plotcandle(o,h,l,c, color = color.new(trend_CLR,candleTransp), wickcolor =color.rgb(107, 113, 133), bordercolor = color.new(#26310d,70), display = display.all - display.status_line - display.price_scale)
plot(plotDot?close:na, color = color.new(#e1e6eb, 40), style = plot.style_line, linewidth = 1, join = true, display = display.all - display.status_line)
plot(plotDot?close:na, color = color.new(color.orange, 45), style = plot.style_circles, linewidth = 4, join = false, display = display.all - display.price_scale - display.status_line)
plot(peri != "" and y[1]==x[1]?close[1]:na, offset = -1, color = color.new(color.blue, 0), style = plot.style_circles, linewidth = 4, join = false, display = display.all - display.price_scale - display.status_line)
plot(plotDot?close:na, color = color.new(color.white, 10), style = plot.style_circles, linewidth = 3, join = false,display = display.all - display.price_scale)
plot(peri != "" and y[1]==x[1]?close[1]:na, offset = -1, color = color.new(#26310d, 0), style = plot.style_circles, linewidth = 3, join = false, display = display.all - display.price_scale - display.status_line)


fh = h
fl = l
cond1 = close[2] > close[3] and close[2] > close[4] and close[2] > close[5] and close[2] > close[6] and close[2] >= close[1] and close[2] >= close[0] // is highest of 5, is >= 2 to the right.
cond2 = close[2] < close[3] and close[2] < close[4] and close[2] < close[5] and close[2] < close[6] and close[2] <= close[1] and close[2] <= close[0] // is lowest of 5, is <= 2 to the right.
plotchar(plot_TRI and cond1 ? fh[2] + adj : na, char = "⬜", color = color.new(#26310d,82), offset = -2, location = location.absolute, editable = false, display = display.all - display.status_line)
plotchar(plot_TRI and cond2 ? fl[2] - adj : na, char = "⬜", color = color.new(#26310d,82), offset = -2, location = location.absolute, editable = false, display = display.all - display.status_line)
plotchar(plot_TRI and cond1 ? fh[2] + adj : na, char = "△", color = color.new(color.white,15), offset = -2, location = location.absolute, editable = false, display = display.all - display.status_line)
plotchar(plot_TRI and cond2 ? fl[2] - adj : na, char = "▽", color = color.new(color.white,15), offset = -2, location = location.absolute, editable = false, display = display.all - display.status_line)



I added a line width setting to Zig Zag. . .why it doesn't have one to begin with, IDK.
I use a depth of 1 on range bar charts.

Code: Select all

//@version=5
indicator("Zig Zag", overlay=true, max_lines_count=500, max_labels_count=500)
lineWidth = input(4, title= "Line Width")
dev_threshold = input.float(title="Deviation (%)", defval=2.0, minval=0.00001, maxval=100.0)
depth = input.int(title="Depth", defval=4, minval=1)
line_color = input(title="Line Color", defval=#2962FF)
extend_to_last_bar = input(title="Extend to Last Bar", defval=true)
display_reversal_price = input(title="Display Reversal Price", defval=true)
display_cumulative_volume = input(title="Display Cumulative Volume", defval=true)
display_reversal_price_change = input(title="Display Reversal Price Change", defval=true, inline="price rev")
difference_price = input.string("Absolute", "", options=["Absolute", "Percent"], inline="price rev")

pivots(src, length, isHigh) =>
    p = nz(src[length])
    if length == 0
        [time, p]
    else
        isFound = true
        for i = 0 to math.abs(length - 1)
            if isHigh and src[i] > p
                isFound := false
            if not isHigh and src[i] < p
                isFound := false
        for i = length + 1 to 2 * length
            if isHigh and src[i] >= p
                isFound := false
            if not isHigh and src[i] <= p
                isFound := false
        if isFound and length * 2 <= bar_index
            [time[length], p]
        else
            [int(na), float(na)]

[iH, pH] = pivots(high, math.floor(depth / 2), true)
[iL, pL] = pivots(low, math.floor(depth / 2), false)

calc_dev(base_price, price) =>
    100 * (price - base_price) / base_price

price_rotation_aggregate(price_rotation, pLast, cum_volume) =>
    str = ""
    if display_reversal_price
        str += str.tostring(pLast, format.mintick) + " "
    if display_reversal_price_change
        str += price_rotation + " "
    if display_cumulative_volume
        str += "\n" + cum_volume
    str
   
caption(isHigh, iLast, pLast, price_rotation, cum_volume) =>
    price_rotation_str = price_rotation_aggregate(price_rotation, pLast, cum_volume)
    if display_reversal_price or display_reversal_price_change or display_cumulative_volume
        if not isHigh
            label.new(iLast, pLast, text=price_rotation_str, style=label.style_none, xloc=xloc.bar_time, yloc=yloc.belowbar, textcolor=color.red)
        else
            label.new(iLast, pLast, text=price_rotation_str, style=label.style_none, xloc=xloc.bar_time, yloc=yloc.abovebar, textcolor=color.green)

price_rotation_diff(pLast, price) =>
    if display_reversal_price_change
        tmp_calc = price - pLast
        str = difference_price == "Absolute"? (math.sign(tmp_calc) > 0? "+" : "") + str.tostring(tmp_calc, format.mintick) : (math.sign(tmp_calc) > 0? "+" : "-") + str.tostring((math.abs(tmp_calc) * 100)/pLast, format.percent)
        str := "(" + str  + ")"
        str
    else
        ""

var line lineLast = na
var label labelLast = na
var int iLast = 0
var float pLast = 0
var bool isHighLast = true // otherwise the last pivot is a low pivot
var int linesCount = 0
var float sumVol = 0
var float sumVolLast = 0

pivotFound(dev, isHigh, index, price) =>
   if isHighLast == isHigh and not na(lineLast)
        // same direction
        if isHighLast ? price > pLast : price < pLast
            if linesCount <= 1
                line.set_xy1(lineLast, index, price)
            line.set_xy2(lineLast, index, price)
            label.set_xy(labelLast, index, price)
            label.set_text(labelLast, price_rotation_aggregate(price_rotation_diff(line.get_y1(lineLast), price), price, str.tostring(sumVol + sumVolLast, format.volume)))
            [lineLast, labelLast, isHighLast, false, sumVol + sumVolLast]
        else
            [line(na), label(na), bool(na), false, float(na)]
    else // reverse the direction (or create the very first line)
        if na(lineLast)
            id = line.new(index, price, index, price, xloc=xloc.bar_time, color=line_color, width=lineWidth)
            lb = caption(isHigh, index, price, price_rotation_diff(pLast, price),  str.tostring(sumVol, format.volume))
            [id, lb, isHigh, true, sumVol]
        else
            // price move is significant
            if math.abs(dev) >= dev_threshold
                id = line.new(iLast, pLast, index, price, xloc=xloc.bar_time, color=line_color, width=lineWidth)
                lb = caption(isHigh, index, price, price_rotation_diff(pLast, price),  str.tostring(sumVol, format.volume))
                [id, lb, isHigh, true, sumVol]
            else
                [line(na), label(na), bool(na), false, float(na)]

sumVol += nz(volume[math.floor(depth / 2)])

if not na(iH) and not na(iL) and iH == iL
    dev1 = calc_dev(pLast, pH)
    [id2, lb2, isHigh2, isNew2, sum2] = pivotFound(dev1, true, iH, pH)
    if isNew2
        linesCount := linesCount + 1
    if not na(id2)
        lineLast := id2
        labelLast := lb2
        isHighLast := isHigh2
        iLast := iH
        pLast := pH
        sumVolLast := sum2
        sumVol := 0
    dev2 = calc_dev(pLast, pL)
    [id1, lb1, isHigh1, isNew1, sum1] = pivotFound(dev2, false, iL, pL)
    if isNew1
        linesCount := linesCount + 1
    if not na(id1)
        lineLast := id1
        labelLast := lb1
        isHighLast := isHigh1
        iLast := iL
        pLast := pL
        sumVolLast := sum1
        sumVol := 0
else
    if not na(iH)
        dev1 = calc_dev(pLast, pH)
        [id, lb, isHigh, isNew, sum] = pivotFound(dev1, true, iH, pH)
        if isNew
            linesCount := linesCount + 1
        if not na(id)
            lineLast := id
            labelLast := lb
            isHighLast := isHigh
            iLast := iH
            pLast := pH
            sumVolLast := sum
            sumVol := 0
    else
        if not na(iL)
            dev2 = calc_dev(pLast, pL)
            [id, lb, isHigh, isNew, sum] = pivotFound(dev2, false, iL, pL)
            if isNew
                linesCount := linesCount + 1
            if not na(id)
                lineLast := id
                labelLast := lb
                isHighLast := isHigh
                iLast := iL
                pLast := pL
                sumVolLast := sum
                sumVol := 0

var line extend_line = na
var label extend_label = na
if extend_to_last_bar == true and barstate.islast == true
    isHighLastPoint = not isHighLast
    curSeries = isHighLastPoint ? high : low
    if na(extend_line) and na(extend_label)
        extend_line := line.new(line.get_x2(lineLast), line.get_y2(lineLast), time, curSeries, xloc=xloc.bar_time, color=line_color, width=lineWidth)
        extend_label := caption(not isHighLast, time, curSeries,  price_rotation_diff(line.get_y2(lineLast), curSeries), str.tostring(sumVol, format.volume)) 
    line.set_xy1(extend_line, line.get_x2(lineLast), line.get_y2(lineLast))
    line.set_xy2(extend_line, time, curSeries)
   
    price_rotation = price_rotation_diff(line.get_y1(extend_line), curSeries)                                                                                                 
    remaingRealTimeVol = 0.
    for i = math.abs(math.floor(depth / 2) - 1) to 0
        remaingRealTimeVol += volume[i]
    label.set_xy(extend_label, time, curSeries)   
    label.set_text(extend_label, price_rotation_aggregate(price_rotation, curSeries, str.tostring(sumVol+remaingRealTimeVol, format.volume)))
    label.set_textcolor(extend_label, isHighLastPoint? color.green : color.red)
    label.set_yloc(extend_label, yloc= isHighLastPoint? yloc.abovebar : yloc.belowbar)

If you were going to use them on a range bar chart then it might look like this:
range_bars_3R_15R.jpg
range_bars_3R_15R.jpg (150.79 KiB) Viewed 1094 times


In other news, I started learning Haskell to maybe do something with Cardano in the future.

I hear that Haskell is an absolute nightmare to learn, seems pretty ABC so far :lol:
"Everything Should Be Made As Simple As Possible, But Not Simpler!"

User avatar
kiwiarian
rank: 500+ posts
rank: 500+ posts
Posts: 767
Joined: Thu Dec 23, 2021 8:15 am
Reputation: 455
Location: New Zealand
Gender: Male

Re: PowerX Strategy "PowerZ"

Postby kiwiarian » Tue Dec 13, 2022 7:57 pm

IgazI wrote:I added some features to the BSW indicator:
- inputs for adjusting chart brightness and turning the dots on and off

Code: Select all

//@version=5
indicator(title = "Bodies Show The Way", shorttitle = "BSW", overlay = true)
h = high
l = low
c = high
o = low
candleTransp = input(65, title= "Darkness")
plotDot = input(true,title= "Plot Dots?")
join_HTF = input(false, title = "Connect:", inline = "2")
peri = input("", title = "Time Frame", inline = "2")
x = time_close(timeframe.period)
y = time_close(peri)
z = x[1] == y[1] ? close[1] : na
plot(peri != "" ? z : na,color = color.new(color.blue,50), offset = -1, style = plot.style_circles, linewidth = 2, trackprice = true)
plot(join_HTF and peri != "" ? z : na,color = color.new(color.blue,45), offset = -1, style = plot.style_line, linewidth = 4, display = display.all - display.price_scale)
plot_TRI = input(false, title = "Display:", inline = "1")
adj = input(0.0, title = "Adjust Triangles", inline = "1")
trend_CLR = close > high[1]? color.rgb(46, 112, 167) : close < low[1] ? color.red : color.white

plotcandle(o,h,l,c, color = color.new(trend_CLR,candleTransp), wickcolor =color.rgb(107, 113, 133), bordercolor = color.new(#26310d,70), display = display.all - display.status_line - display.price_scale)
plot(plotDot?close:na, color = color.new(#e1e6eb, 40), style = plot.style_line, linewidth = 1, join = true, display = display.all - display.status_line)
plot(plotDot?close:na, color = color.new(color.orange, 45), style = plot.style_circles, linewidth = 4, join = false, display = display.all - display.price_scale - display.status_line)
plot(peri != "" and y[1]==x[1]?close[1]:na, offset = -1, color = color.new(color.blue, 0), style = plot.style_circles, linewidth = 4, join = false, display = display.all - display.price_scale - display.status_line)
plot(plotDot?close:na, color = color.new(color.white, 10), style = plot.style_circles, linewidth = 3, join = false,display = display.all - display.price_scale)
plot(peri != "" and y[1]==x[1]?close[1]:na, offset = -1, color = color.new(#26310d, 0), style = plot.style_circles, linewidth = 3, join = false, display = display.all - display.price_scale - display.status_line)


fh = h
fl = l
cond1 = close[2] > close[3] and close[2] > close[4] and close[2] > close[5] and close[2] > close[6] and close[2] >= close[1] and close[2] >= close[0] // is highest of 5, is >= 2 to the right.
cond2 = close[2] < close[3] and close[2] < close[4] and close[2] < close[5] and close[2] < close[6] and close[2] <= close[1] and close[2] <= close[0] // is lowest of 5, is <= 2 to the right.
plotchar(plot_TRI and cond1 ? fh[2] + adj : na, char = "⬜", color = color.new(#26310d,82), offset = -2, location = location.absolute, editable = false, display = display.all - display.status_line)
plotchar(plot_TRI and cond2 ? fl[2] - adj : na, char = "⬜", color = color.new(#26310d,82), offset = -2, location = location.absolute, editable = false, display = display.all - display.status_line)
plotchar(plot_TRI and cond1 ? fh[2] + adj : na, char = "△", color = color.new(color.white,15), offset = -2, location = location.absolute, editable = false, display = display.all - display.status_line)
plotchar(plot_TRI and cond2 ? fl[2] - adj : na, char = "▽", color = color.new(color.white,15), offset = -2, location = location.absolute, editable = false, display = display.all - display.status_line)



I added a line width setting to Zig Zag. . .why it doesn't have one to begin with, IDK.
I use a depth of 1 on range bar charts.

Code: Select all

//@version=5
indicator("Zig Zag", overlay=true, max_lines_count=500, max_labels_count=500)
lineWidth = input(4, title= "Line Width")
dev_threshold = input.float(title="Deviation (%)", defval=2.0, minval=0.00001, maxval=100.0)
depth = input.int(title="Depth", defval=4, minval=1)
line_color = input(title="Line Color", defval=#2962FF)
extend_to_last_bar = input(title="Extend to Last Bar", defval=true)
display_reversal_price = input(title="Display Reversal Price", defval=true)
display_cumulative_volume = input(title="Display Cumulative Volume", defval=true)
display_reversal_price_change = input(title="Display Reversal Price Change", defval=true, inline="price rev")
difference_price = input.string("Absolute", "", options=["Absolute", "Percent"], inline="price rev")

pivots(src, length, isHigh) =>
    p = nz(src[length])
    if length == 0
        [time, p]
    else
        isFound = true
        for i = 0 to math.abs(length - 1)
            if isHigh and src[i] > p
                isFound := false
            if not isHigh and src[i] < p
                isFound := false
        for i = length + 1 to 2 * length
            if isHigh and src[i] >= p
                isFound := false
            if not isHigh and src[i] <= p
                isFound := false
        if isFound and length * 2 <= bar_index
            [time[length], p]
        else
            [int(na), float(na)]

[iH, pH] = pivots(high, math.floor(depth / 2), true)
[iL, pL] = pivots(low, math.floor(depth / 2), false)

calc_dev(base_price, price) =>
    100 * (price - base_price) / base_price

price_rotation_aggregate(price_rotation, pLast, cum_volume) =>
    str = ""
    if display_reversal_price
        str += str.tostring(pLast, format.mintick) + " "
    if display_reversal_price_change
        str += price_rotation + " "
    if display_cumulative_volume
        str += "\n" + cum_volume
    str
   
caption(isHigh, iLast, pLast, price_rotation, cum_volume) =>
    price_rotation_str = price_rotation_aggregate(price_rotation, pLast, cum_volume)
    if display_reversal_price or display_reversal_price_change or display_cumulative_volume
        if not isHigh
            label.new(iLast, pLast, text=price_rotation_str, style=label.style_none, xloc=xloc.bar_time, yloc=yloc.belowbar, textcolor=color.red)
        else
            label.new(iLast, pLast, text=price_rotation_str, style=label.style_none, xloc=xloc.bar_time, yloc=yloc.abovebar, textcolor=color.green)

price_rotation_diff(pLast, price) =>
    if display_reversal_price_change
        tmp_calc = price - pLast
        str = difference_price == "Absolute"? (math.sign(tmp_calc) > 0? "+" : "") + str.tostring(tmp_calc, format.mintick) : (math.sign(tmp_calc) > 0? "+" : "-") + str.tostring((math.abs(tmp_calc) * 100)/pLast, format.percent)
        str := "(" + str  + ")"
        str
    else
        ""

var line lineLast = na
var label labelLast = na
var int iLast = 0
var float pLast = 0
var bool isHighLast = true // otherwise the last pivot is a low pivot
var int linesCount = 0
var float sumVol = 0
var float sumVolLast = 0

pivotFound(dev, isHigh, index, price) =>
   if isHighLast == isHigh and not na(lineLast)
        // same direction
        if isHighLast ? price > pLast : price < pLast
            if linesCount <= 1
                line.set_xy1(lineLast, index, price)
            line.set_xy2(lineLast, index, price)
            label.set_xy(labelLast, index, price)
            label.set_text(labelLast, price_rotation_aggregate(price_rotation_diff(line.get_y1(lineLast), price), price, str.tostring(sumVol + sumVolLast, format.volume)))
            [lineLast, labelLast, isHighLast, false, sumVol + sumVolLast]
        else
            [line(na), label(na), bool(na), false, float(na)]
    else // reverse the direction (or create the very first line)
        if na(lineLast)
            id = line.new(index, price, index, price, xloc=xloc.bar_time, color=line_color, width=lineWidth)
            lb = caption(isHigh, index, price, price_rotation_diff(pLast, price),  str.tostring(sumVol, format.volume))
            [id, lb, isHigh, true, sumVol]
        else
            // price move is significant
            if math.abs(dev) >= dev_threshold
                id = line.new(iLast, pLast, index, price, xloc=xloc.bar_time, color=line_color, width=lineWidth)
                lb = caption(isHigh, index, price, price_rotation_diff(pLast, price),  str.tostring(sumVol, format.volume))
                [id, lb, isHigh, true, sumVol]
            else
                [line(na), label(na), bool(na), false, float(na)]

sumVol += nz(volume[math.floor(depth / 2)])

if not na(iH) and not na(iL) and iH == iL
    dev1 = calc_dev(pLast, pH)
    [id2, lb2, isHigh2, isNew2, sum2] = pivotFound(dev1, true, iH, pH)
    if isNew2
        linesCount := linesCount + 1
    if not na(id2)
        lineLast := id2
        labelLast := lb2
        isHighLast := isHigh2
        iLast := iH
        pLast := pH
        sumVolLast := sum2
        sumVol := 0
    dev2 = calc_dev(pLast, pL)
    [id1, lb1, isHigh1, isNew1, sum1] = pivotFound(dev2, false, iL, pL)
    if isNew1
        linesCount := linesCount + 1
    if not na(id1)
        lineLast := id1
        labelLast := lb1
        isHighLast := isHigh1
        iLast := iL
        pLast := pL
        sumVolLast := sum1
        sumVol := 0
else
    if not na(iH)
        dev1 = calc_dev(pLast, pH)
        [id, lb, isHigh, isNew, sum] = pivotFound(dev1, true, iH, pH)
        if isNew
            linesCount := linesCount + 1
        if not na(id)
            lineLast := id
            labelLast := lb
            isHighLast := isHigh
            iLast := iH
            pLast := pH
            sumVolLast := sum
            sumVol := 0
    else
        if not na(iL)
            dev2 = calc_dev(pLast, pL)
            [id, lb, isHigh, isNew, sum] = pivotFound(dev2, false, iL, pL)
            if isNew
                linesCount := linesCount + 1
            if not na(id)
                lineLast := id
                labelLast := lb
                isHighLast := isHigh
                iLast := iL
                pLast := pL
                sumVolLast := sum
                sumVol := 0

var line extend_line = na
var label extend_label = na
if extend_to_last_bar == true and barstate.islast == true
    isHighLastPoint = not isHighLast
    curSeries = isHighLastPoint ? high : low
    if na(extend_line) and na(extend_label)
        extend_line := line.new(line.get_x2(lineLast), line.get_y2(lineLast), time, curSeries, xloc=xloc.bar_time, color=line_color, width=lineWidth)
        extend_label := caption(not isHighLast, time, curSeries,  price_rotation_diff(line.get_y2(lineLast), curSeries), str.tostring(sumVol, format.volume)) 
    line.set_xy1(extend_line, line.get_x2(lineLast), line.get_y2(lineLast))
    line.set_xy2(extend_line, time, curSeries)
   
    price_rotation = price_rotation_diff(line.get_y1(extend_line), curSeries)                                                                                                 
    remaingRealTimeVol = 0.
    for i = math.abs(math.floor(depth / 2) - 1) to 0
        remaingRealTimeVol += volume[i]
    label.set_xy(extend_label, time, curSeries)   
    label.set_text(extend_label, price_rotation_aggregate(price_rotation, curSeries, str.tostring(sumVol+remaingRealTimeVol, format.volume)))
    label.set_textcolor(extend_label, isHighLastPoint? color.green : color.red)
    label.set_yloc(extend_label, yloc= isHighLastPoint? yloc.abovebar : yloc.belowbar)

If you were going to use them on a range bar chart then it might look like this:
range_bars_3R_15R.jpg

In other news, I started learning Haskell to maybe do something with Cardano in the future.

I hear that Haskell is an absolute nightmare to learn, seems pretty ABC so far :lol:


What are you learning Haskell for, trading? Are there any trading clients that use it?
The Cardano description says it is useful for solving real world problems, not sure what that translates too.

nonibadsha
rank: 150+ posts
rank: 150+ posts
Posts: 161
Joined: Thu Jun 23, 2022 9:16 am
Reputation: 55
Gender: None specified

Re: PowerX Strategy "PowerZ"

Postby nonibadsha » Tue Dec 13, 2022 8:07 pm

IgazI wrote:I added some features to the BSW indicator:
- inputs for adjusting chart brightness and turning the dots on and off

Code: Select all

//@version=5
indicator(title = "Bodies Show The Way", shorttitle = "BSW", overlay = true)
h = high
l = low
c = high
o = low
candleTransp = input(65, title= "Darkness")
plotDot = input(true,title= "Plot Dots?")
join_HTF = input(false, title = "Connect:", inline = "2")
peri = input("", title = "Time Frame", inline = "2")
x = time_close(timeframe.period)
y = time_close(peri)
z = x[1] == y[1] ? close[1] : na
plot(peri != "" ? z : na,color = color.new(color.blue,50), offset = -1, style = plot.style_circles, linewidth = 2, trackprice = true)
plot(join_HTF and peri != "" ? z : na,color = color.new(color.blue,45), offset = -1, style = plot.style_line, linewidth = 4, display = display.all - display.price_scale)
plot_TRI = input(false, title = "Display:", inline = "1")
adj = input(0.0, title = "Adjust Triangles", inline = "1")
trend_CLR = close > high[1]? color.rgb(46, 112, 167) : close < low[1] ? color.red : color.white

plotcandle(o,h,l,c, color = color.new(trend_CLR,candleTransp), wickcolor =color.rgb(107, 113, 133), bordercolor = color.new(#26310d,70), display = display.all - display.status_line - display.price_scale)
plot(plotDot?close:na, color = color.new(#e1e6eb, 40), style = plot.style_line, linewidth = 1, join = true, display = display.all - display.status_line)
plot(plotDot?close:na, color = color.new(color.orange, 45), style = plot.style_circles, linewidth = 4, join = false, display = display.all - display.price_scale - display.status_line)
plot(peri != "" and y[1]==x[1]?close[1]:na, offset = -1, color = color.new(color.blue, 0), style = plot.style_circles, linewidth = 4, join = false, display = display.all - display.price_scale - display.status_line)
plot(plotDot?close:na, color = color.new(color.white, 10), style = plot.style_circles, linewidth = 3, join = false,display = display.all - display.price_scale)
plot(peri != "" and y[1]==x[1]?close[1]:na, offset = -1, color = color.new(#26310d, 0), style = plot.style_circles, linewidth = 3, join = false, display = display.all - display.price_scale - display.status_line)


fh = h
fl = l
cond1 = close[2] > close[3] and close[2] > close[4] and close[2] > close[5] and close[2] > close[6] and close[2] >= close[1] and close[2] >= close[0] // is highest of 5, is >= 2 to the right.
cond2 = close[2] < close[3] and close[2] < close[4] and close[2] < close[5] and close[2] < close[6] and close[2] <= close[1] and close[2] <= close[0] // is lowest of 5, is <= 2 to the right.
plotchar(plot_TRI and cond1 ? fh[2] + adj : na, char = "⬜", color = color.new(#26310d,82), offset = -2, location = location.absolute, editable = false, display = display.all - display.status_line)
plotchar(plot_TRI and cond2 ? fl[2] - adj : na, char = "⬜", color = color.new(#26310d,82), offset = -2, location = location.absolute, editable = false, display = display.all - display.status_line)
plotchar(plot_TRI and cond1 ? fh[2] + adj : na, char = "△", color = color.new(color.white,15), offset = -2, location = location.absolute, editable = false, display = display.all - display.status_line)
plotchar(plot_TRI and cond2 ? fl[2] - adj : na, char = "▽", color = color.new(color.white,15), offset = -2, location = location.absolute, editable = false, display = display.all - display.status_line)



I added a line width setting to Zig Zag. . .why it doesn't have one to begin with, IDK.
I use a depth of 1 on range bar charts.

Code: Select all

//@version=5
indicator("Zig Zag", overlay=true, max_lines_count=500, max_labels_count=500)
lineWidth = input(4, title= "Line Width")
dev_threshold = input.float(title="Deviation (%)", defval=2.0, minval=0.00001, maxval=100.0)
depth = input.int(title="Depth", defval=4, minval=1)
line_color = input(title="Line Color", defval=#2962FF)
extend_to_last_bar = input(title="Extend to Last Bar", defval=true)
display_reversal_price = input(title="Display Reversal Price", defval=true)
display_cumulative_volume = input(title="Display Cumulative Volume", defval=true)
display_reversal_price_change = input(title="Display Reversal Price Change", defval=true, inline="price rev")
difference_price = input.string("Absolute", "", options=["Absolute", "Percent"], inline="price rev")

pivots(src, length, isHigh) =>
    p = nz(src[length])
    if length == 0
        [time, p]
    else
        isFound = true
        for i = 0 to math.abs(length - 1)
            if isHigh and src[i] > p
                isFound := false
            if not isHigh and src[i] < p
                isFound := false
        for i = length + 1 to 2 * length
            if isHigh and src[i] >= p
                isFound := false
            if not isHigh and src[i] <= p
                isFound := false
        if isFound and length * 2 <= bar_index
            [time[length], p]
        else
            [int(na), float(na)]

[iH, pH] = pivots(high, math.floor(depth / 2), true)
[iL, pL] = pivots(low, math.floor(depth / 2), false)

calc_dev(base_price, price) =>
    100 * (price - base_price) / base_price

price_rotation_aggregate(price_rotation, pLast, cum_volume) =>
    str = ""
    if display_reversal_price
        str += str.tostring(pLast, format.mintick) + " "
    if display_reversal_price_change
        str += price_rotation + " "
    if display_cumulative_volume
        str += "\n" + cum_volume
    str
   
caption(isHigh, iLast, pLast, price_rotation, cum_volume) =>
    price_rotation_str = price_rotation_aggregate(price_rotation, pLast, cum_volume)
    if display_reversal_price or display_reversal_price_change or display_cumulative_volume
        if not isHigh
            label.new(iLast, pLast, text=price_rotation_str, style=label.style_none, xloc=xloc.bar_time, yloc=yloc.belowbar, textcolor=color.red)
        else
            label.new(iLast, pLast, text=price_rotation_str, style=label.style_none, xloc=xloc.bar_time, yloc=yloc.abovebar, textcolor=color.green)

price_rotation_diff(pLast, price) =>
    if display_reversal_price_change
        tmp_calc = price - pLast
        str = difference_price == "Absolute"? (math.sign(tmp_calc) > 0? "+" : "") + str.tostring(tmp_calc, format.mintick) : (math.sign(tmp_calc) > 0? "+" : "-") + str.tostring((math.abs(tmp_calc) * 100)/pLast, format.percent)
        str := "(" + str  + ")"
        str
    else
        ""

var line lineLast = na
var label labelLast = na
var int iLast = 0
var float pLast = 0
var bool isHighLast = true // otherwise the last pivot is a low pivot
var int linesCount = 0
var float sumVol = 0
var float sumVolLast = 0

pivotFound(dev, isHigh, index, price) =>
   if isHighLast == isHigh and not na(lineLast)
        // same direction
        if isHighLast ? price > pLast : price < pLast
            if linesCount <= 1
                line.set_xy1(lineLast, index, price)
            line.set_xy2(lineLast, index, price)
            label.set_xy(labelLast, index, price)
            label.set_text(labelLast, price_rotation_aggregate(price_rotation_diff(line.get_y1(lineLast), price), price, str.tostring(sumVol + sumVolLast, format.volume)))
            [lineLast, labelLast, isHighLast, false, sumVol + sumVolLast]
        else
            [line(na), label(na), bool(na), false, float(na)]
    else // reverse the direction (or create the very first line)
        if na(lineLast)
            id = line.new(index, price, index, price, xloc=xloc.bar_time, color=line_color, width=lineWidth)
            lb = caption(isHigh, index, price, price_rotation_diff(pLast, price),  str.tostring(sumVol, format.volume))
            [id, lb, isHigh, true, sumVol]
        else
            // price move is significant
            if math.abs(dev) >= dev_threshold
                id = line.new(iLast, pLast, index, price, xloc=xloc.bar_time, color=line_color, width=lineWidth)
                lb = caption(isHigh, index, price, price_rotation_diff(pLast, price),  str.tostring(sumVol, format.volume))
                [id, lb, isHigh, true, sumVol]
            else
                [line(na), label(na), bool(na), false, float(na)]

sumVol += nz(volume[math.floor(depth / 2)])

if not na(iH) and not na(iL) and iH == iL
    dev1 = calc_dev(pLast, pH)
    [id2, lb2, isHigh2, isNew2, sum2] = pivotFound(dev1, true, iH, pH)
    if isNew2
        linesCount := linesCount + 1
    if not na(id2)
        lineLast := id2
        labelLast := lb2
        isHighLast := isHigh2
        iLast := iH
        pLast := pH
        sumVolLast := sum2
        sumVol := 0
    dev2 = calc_dev(pLast, pL)
    [id1, lb1, isHigh1, isNew1, sum1] = pivotFound(dev2, false, iL, pL)
    if isNew1
        linesCount := linesCount + 1
    if not na(id1)
        lineLast := id1
        labelLast := lb1
        isHighLast := isHigh1
        iLast := iL
        pLast := pL
        sumVolLast := sum1
        sumVol := 0
else
    if not na(iH)
        dev1 = calc_dev(pLast, pH)
        [id, lb, isHigh, isNew, sum] = pivotFound(dev1, true, iH, pH)
        if isNew
            linesCount := linesCount + 1
        if not na(id)
            lineLast := id
            labelLast := lb
            isHighLast := isHigh
            iLast := iH
            pLast := pH
            sumVolLast := sum
            sumVol := 0
    else
        if not na(iL)
            dev2 = calc_dev(pLast, pL)
            [id, lb, isHigh, isNew, sum] = pivotFound(dev2, false, iL, pL)
            if isNew
                linesCount := linesCount + 1
            if not na(id)
                lineLast := id
                labelLast := lb
                isHighLast := isHigh
                iLast := iL
                pLast := pL
                sumVolLast := sum
                sumVol := 0

var line extend_line = na
var label extend_label = na
if extend_to_last_bar == true and barstate.islast == true
    isHighLastPoint = not isHighLast
    curSeries = isHighLastPoint ? high : low
    if na(extend_line) and na(extend_label)
        extend_line := line.new(line.get_x2(lineLast), line.get_y2(lineLast), time, curSeries, xloc=xloc.bar_time, color=line_color, width=lineWidth)
        extend_label := caption(not isHighLast, time, curSeries,  price_rotation_diff(line.get_y2(lineLast), curSeries), str.tostring(sumVol, format.volume)) 
    line.set_xy1(extend_line, line.get_x2(lineLast), line.get_y2(lineLast))
    line.set_xy2(extend_line, time, curSeries)
   
    price_rotation = price_rotation_diff(line.get_y1(extend_line), curSeries)                                                                                                 
    remaingRealTimeVol = 0.
    for i = math.abs(math.floor(depth / 2) - 1) to 0
        remaingRealTimeVol += volume[i]
    label.set_xy(extend_label, time, curSeries)   
    label.set_text(extend_label, price_rotation_aggregate(price_rotation, curSeries, str.tostring(sumVol+remaingRealTimeVol, format.volume)))
    label.set_textcolor(extend_label, isHighLastPoint? color.green : color.red)
    label.set_yloc(extend_label, yloc= isHighLastPoint? yloc.abovebar : yloc.belowbar)

If you were going to use them on a range bar chart then it might look like this:
range_bars_3R_15R.jpg

In other news, I started learning Haskell to maybe do something with Cardano in the future.

I hear that Haskell is an absolute nightmare to learn, seems pretty ABC so far :lol:


Zig Zag fails to compile.
Compilation error. Line 79: Mismatched input 'if' expecting 'end of line without line continuation'

User avatar
IgazI
rank: 1000+ posts
rank: 1000+ posts
Posts: 2016
Joined: Sat Feb 17, 2018 5:28 pm
Reputation: 1663
Gender: None specified

Re: PowerX Strategy "PowerZ"

Postby IgazI » Tue Dec 13, 2022 8:16 pm

kiwiarian wrote:
What are you learning Haskell for, trading? Are there any trading clients that use it?
The Cardano description says it is useful for solving real world problems, not sure what that translates too.


I listed only the resources that I am using, and going to be using, to learn Haskell.

HERE you can see that Haskell is used to interact with the Cardano blockchain.

Of course, you can use Haskell for a number of other things such as machine learning and all the other fun stuff.
"Everything Should Be Made As Simple As Possible, But Not Simpler!"

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.

User avatar
IgazI
rank: 1000+ posts
rank: 1000+ posts
Posts: 2016
Joined: Sat Feb 17, 2018 5:28 pm
Reputation: 1663
Gender: None specified

Re: PowerX Strategy "PowerZ"

Postby IgazI » Tue Dec 13, 2022 8:30 pm

It works fine for me. . .
then I paste it on Klik and paste it back to TV and it throws an error, wth #-o

Plan B:

Click on Zig Zag under 'Technicals'

zig_z.jpg
zig_z.jpg (11.31 KiB) Viewed 1024 times


Click '{}' and copy+paste to new indicator. . .

Add a line width input:

add_this.jpg
add_this.jpg (30.49 KiB) Viewed 1024 times


Temporarily add the word 'width' to line 13, highlight it, and scroll down to the places where it says 'width =' and replace the number with 'lineWidth':

temp_.jpg
temp_.jpg (4.96 KiB) Viewed 1024 times

there is another one on line 166. . .
another_166.jpg
another_166.jpg (48.05 KiB) Viewed 1024 times


delete your temp word 'width' on line 13 and click save.
"Everything Should Be Made As Simple As Possible, But Not Simpler!"

User avatar
IgazI
rank: 1000+ posts
rank: 1000+ posts
Posts: 2016
Joined: Sat Feb 17, 2018 5:28 pm
Reputation: 1663
Gender: None specified

Re: PowerX Strategy "PowerZ"

Postby IgazI » Wed Dec 14, 2022 8:05 pm

Your only salvation is in not holding USD. Hold just about anything else :lol:

what_the.jpg
what_the.jpg (77.57 KiB) Viewed 945 times
"Everything Should Be Made As Simple As Possible, But Not Simpler!"

nonibadsha
rank: 150+ posts
rank: 150+ posts
Posts: 161
Joined: Thu Jun 23, 2022 9:16 am
Reputation: 55
Gender: None specified

Re: PowerX Strategy "PowerZ"

Postby nonibadsha » Thu Dec 15, 2022 8:40 pm

@Igazi

Is there anyway to modify the zigzag to draw the highs/low with range showing?

Also I understand what you said but not sure how to utilize it.
Would you be kind enough to show and example entry and exit please.
Attachments
TradingView_Screenshot_1671135124932.jpg
TradingView_Screenshot_1671135124932.jpg (157.39 KiB) Viewed 852 times

User avatar
IgazI
rank: 1000+ posts
rank: 1000+ posts
Posts: 2016
Joined: Sat Feb 17, 2018 5:28 pm
Reputation: 1663
Gender: None specified

Re: PowerX Strategy "PowerZ"

Postby IgazI » Fri Dec 16, 2022 4:41 pm

nonibadsha wrote:@Igazi

Is there anyway to modify the zigzag to draw the highs/low with range showing?

Also I understand what you said but not sure how to utilize it.
Would you be kind enough to show and example entry and exit please.


Sure.

Display 'absolute' will give you the pip range. . .
before you do that, select 'percent' and look for rotations that you want to ignore:

under 'deviation %' set it a tick higher than the baby rotation values.

howto_zig_zag.jpg
howto_zig_zag.jpg (215.54 KiB) Viewed 802 times


This is how you adjust your triangles by 1 pip so that they are not on top of your candles:
adjust_TRI.jpg
adjust_TRI.jpg (43.99 KiB) Viewed 802 times


There are only patterns and breakouts:

If I say "this is a 1-2-3 pattern" then how do you trade it? you trade the breakout of the pattern, right?

Likewise, you trade the breakout of a pattern or price returning to a pattern. . .
anything that is not a breakout is a pattern, and anything that is not a pattern is a breakout.

What is up? what is dn? what is in? what is out? these you have to answer for yourself.

How do you trade?

- trading is placing stops. . .
an entry is any price that is within range of your stop loss. . .
the purpose behind the entry is trading patterns.

- use profit to increase position size.

How can you achieve a higher win rate?

- be more observant. . .
- be more observant.

You do, you fail, you do better next time.

pat_and_brrr.jpg
pat_and_brrr.jpg (130.72 KiB) Viewed 802 times
"Everything Should Be Made As Simple As Possible, But Not Simpler!"

User avatar
IgazI
rank: 1000+ posts
rank: 1000+ posts
Posts: 2016
Joined: Sat Feb 17, 2018 5:28 pm
Reputation: 1663
Gender: None specified

Re: PowerX Strategy "PowerZ"

Postby IgazI » Fri Dec 16, 2022 5:42 pm

What can you own that you are not forced to convert back into fiat?

If you have a Bitcoin contract and it settles in USD then it's practically worthless for anything other than as a hedge.

If you own stocks and you can only sell your stocks for USD. . .again, worthless.

They've printed more money than god has ever seen, close to 100 trillion dollars, . . .
you tell me what a dollar is worth. . .

trade it for ANYTHING.

PS: it cost me less than 6 cents per transaction to move ADA on the Cardano blockchain and the transactions settled in 1-15 seconds. . .
guess how much banks or PayPal would charge and how long it would take?

"Everything Should Be Made As Simple As Possible, But Not Simpler!"

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.


Return to “general”