not able to calculate high low properly when use custom dates

22 Views Asked by At

i am trying to plot last 365 calender days high / low into 4 different level. when it is in defaul mode ( today's date to last 365 calender days ) that time works ok. but when i use custom date option that time it calculatationg ( today's date to custom date ) but i want to it like ( custom's date to last 365 calender days from custom's dates )

//@version=5
 
indicator(title='ZONER ', overlay=true)
 
// -------------------------------------
// ----------- Inputs ------------------
// -------------------------------------
dateType = input.string('Use Default'
  , 'Lookback'
  , display = display.none
  , options = ['Use Default', 'Use Start Time'])
 
i_date = input.time(timestamp("01 Jan 2023 00:00 +2000")
  , ' Start Time ')
 
patl = true
pfib1 = true
pfib2 = true
pfib3 = true
path = true
 
 
// -------------------------------------
// ---------- Calculs ------------------
// -------------------------------------
 
getPrice(src1, src2, src3) =>
    bool getT = false
    float HH  = na
    float LL  = na
    get1 = src1
    get2 = src2
    t1 = src3 + 365 * 86400000
    if dateType == 'Use Default'
        if timenow <= t1
            getT := true
    if dateType == 'Use Start Time'
        if src3 >= i_date
            getT := true
    if getT
        HH := math.max(get1, HH[1])
        LL := math.min(get2, LL[1])
    else
        HH := 0.0
        LL := 999999.0
    [HH, LL]
 
[h, l] = request.security(syminfo.tickerid, 'D', getPrice(high, low, time))
fib1 = (h - l) * 0.25 + l
fib2 = (h - l) * 0.5 + l
fib3 = (h - l) * 0.75 + l
 
 
// -------------------------------------
// ------------ Plots ------------------
// -------------------------------------
var line l_line = na
l_line := line.new(bar_index-4500
  , l
  , bar_index
  , l
  , color = color.black
  , extend = extend.right,style=line.style_solid)
line.delete(l_line[1])
 
plot(patl ? l : na, title='Base-0', color=color.new(color.black, 100), trackprice=true, linewidth=1, offset=-9999, editable=false, display=display.all - display.status_line)
var label Ll = na
label.delete(Ll)
if patl
    Ll := label.new(bar_index, l, 'Base-0 (' + str.tostring(l, '#.##') + ' )', textcolor=color.black, color=color.new(#000000, 100), style=label.style_label_left, yloc=yloc.price)
    Ll
 
var line pfib1_line = na
pfib1_line := line.new(bar_index-4500
  , fib1
  , bar_index
  , fib1
  , color = color.new(#F44336, 0)
  , extend = extend.right,style=line.style_solid)
line.delete(pfib1_line[1])
 
plot(pfib1 ? fib1 : na, title='Base-1', color=color.new(#F44336, 100), trackprice=true, linewidth=1, offset=-9999, editable=false, display=display.all - display.status_line)
var label Lfib1 = na
label.delete(Lfib1)
if pfib1
    Lfib1 := label.new(bar_index, fib1, 'Base-1 (' + str.tostring(fib1, '#.##') + ' )', textcolor=#F44336, color=color.new(#000000, 100), style=label.style_label_left, yloc=yloc.price)
    Lfib1
 
var line pfib2_line = na
pfib2_line := line.new(bar_index-4500
  , fib2
  , bar_index
  , fib2
  , color = color.blue
  , extend = extend.right,style=line.style_solid)
line.delete(pfib2_line[1])
 
plot(pfib2 ? fib2 : na, title='Value-1', color=color.new(color.blue, 100), trackprice=true, linewidth=1, offset=-9999, editable=false, display=display.all - display.status_line)
var label Lfib2 = na
label.delete(Lfib2)
if pfib2
    Lfib2 := label.new(bar_index, fib2, 'Value-1 (' + str.tostring(fib2, '#.##') + ' )', textcolor=color.blue, color=color.new(#000000, 100), style=label.style_label_left, yloc=yloc.price)
    Lfib2
 
var line pfib3_line = na
pfib3_line := line.new(bar_index-4500
  , fib3
  , bar_index
  , fib3
  , color = color.green
  , extend = extend.right,style=line.style_solid)
line.delete(pfib3_line[1])
 
plot(pfib3 ? fib3 : na, title='Value-2', color=color.new(color.green, 100), trackprice=true, linewidth=1, offset=-9999, editable=false, display=display.all - display.status_line)
var label Lfib3 = na
label.delete(Lfib3)
if pfib3
    Lfib3 := label.new(bar_index, fib3, 'Value-2 (' + str.tostring(fib3, '#.##') + ' )', textcolor=color.green, color=color.new(#000000, 100), style=label.style_label_left, yloc=yloc.price)
    Lfib3
 
var line h_line = na
h_line := line.new(bar_index-4500
  , h
  , bar_index
  , h
  , color = color.green
  , extend = extend.right,style=line.style_solid)
line.delete(h_line[1])
 
plot(path ? h : na, title='Growth', color=color.new(color.green, 100), linewidth=1, editable=false, display=display.all - display.status_line)
var label Lh = na
label.delete(Lh)
if path
    Lh := label.new(bar_index, h, 'Growth (' + str.tostring(h, '#.##') + ' )', textcolor=color.green, color=color.new(#000000, 100), style=label.style_label_left, yloc=yloc.price)
    Lh
//-------------------------------------------------------------------------------
// Get signals for alerts
 
getSig(src1, src2) =>
    int sig = na
    bool Pdn = false
    bool Pup = false
    getP = line.get_price(src1, src2)
    if open >= getP or high >= getP or low >= getP or close >= getP
        sig := 1
    if open <= getP or high <= getP or low <= getP or close <= getP
        sig := 0
    if sig[1] == 1 and sig == 0
        Pdn := true 
    if sig[1] == 0 and sig == 1
        Pup := true
    [Pdn, Pup]
 
[Pdn1_, Pup1_] = getSig(l_line, bar_index)
[Pdn2_, Pup2_] = getSig(pfib1_line, bar_index)
[Pdn3_, Pup3_] = getSig(pfib2_line, bar_index)
[Pdn4_, Pup4_] = getSig(pfib3_line, bar_index)
[Pdn5_, Pup5_] = getSig(h_line, bar_index)
//-------------------------------------------------------------------------------
// Alerts
 
if Pdn1_
    alert(message = 'Price Moving Below Base-0 for ' + syminfo.tickerid + ': ' + str.tostring(close, '#.####'), freq = alert.freq_once_per_bar)
if Pdn2_
    alert(message = 'Price Moving Below Base-1 for ' + syminfo.tickerid + ': ' + str.tostring(close, '#.####'), freq = alert.freq_once_per_bar)
if Pdn3_
    alert(message = 'Price Moving Below Value-1 for ' + syminfo.tickerid + ': ' + str.tostring(close, '#.####'), freq = alert.freq_once_per_bar)
if Pdn4_
    alert(message = 'Price Moving Below Value-2 for ' + syminfo.tickerid + ': ' + str.tostring(close, '#.####'), freq = alert.freq_once_per_bar)
if Pdn5_
    alert(message = 'Price Moving Below Growth for ' + syminfo.tickerid + ': ' + str.tostring(close, '#.####'), freq = alert.freq_once_per_bar)
 
if Pup1_
    alert(message = 'Price Moving Above Base-0 for ' + syminfo.tickerid + ': ' + str.tostring(close, '#.####'), freq = alert.freq_once_per_bar)
if Pup2_
    alert(message = 'Price Moving Above Base-1 for ' + syminfo.tickerid + ': ' + str.tostring(close, '#.####'), freq = alert.freq_once_per_bar)
if Pup3_
    alert(message = 'Price Moving Above Value-1 for ' + syminfo.tickerid + ': ' + str.tostring(close, '#.####'), freq = alert.freq_once_per_bar)
if Pup4_
    alert(message = 'Price Moving Above Value-2 for ' + syminfo.tickerid + ': ' + str.tostring(close, '#.####'), freq = alert.freq_once_per_bar)
if Pup5_
    alert(message = 'Price Moving Above Growth for ' + syminfo.tickerid + ': ' + str.tostring(close, '#.####'), freq = alert.freq_once_per_bar)
0

There are 0 best solutions below