Page 1 of 1

creating pivot for the next day using pinescript

Posted: Tue Feb 28, 2023 3:18 am
by anonymouss
i can draw pivot on next day by eod, but if market starts a lot of new lines adding for every bar. How to avoid this?
below is code:

Code: Select all

getPivotResolution() =>
    endBarIndex = 0
    resolution = 'D'
    if pivot_time_frame == AUTO
        resolution := 'D'
        if timeframe.isminutes and timeframe.multiplier == 5
            endBarIndex := 74
        else if timeframe.isminutes and timeframe.multiplier == 3
            endBarIndex := 124
        [resolution,endBarIndex]

[resolution,endBarIndex]= getPivotResolution()

//finding high,low,close of the script
tH = request.security(syminfo.tickerid, resolution, high, barmerge.gaps_off, barmerge.lookahead_on)
tC = request.security(syminfo.tickerid, resolution, close, barmerge.gaps_off, barmerge.lookahead_on)
tL = request.security(syminfo.tickerid, resolution, low, barmerge.gaps_off, barmerge.lookahead_on)
tP = (tH + tL + tC) / 3
tBC = (tH + tL) / 2
tTC = tP - tBC + tP

//creating pivot line for the next day
if(barstate.islast)  
    line.new(bar_index+1,tP,bar_index+endBarIndex,tP, style=line.style_dotted,color = color.blue,width = 2)
line.new(bar_index+1,tBC,bar_index+endBarIndex,tBC, style=line.style_dotted,color = color.purple,width = 2)
    line.new(bar_index+1,tTC,bar_index+endBarIndex,tTC, style=line.style_dotted,color = color.purple,width = 2)

Re: creating pivot for the next day using pinescript

Posted: Tue Feb 28, 2023 6:50 am
by Steve Burman
It may be a repainting issue with your request.security statements. The best way to fix this is for reference the prior bar when a real-time bar is updating such as this:

tH = request.security(syminfo.tickerid, resolution, barstate.isconfirmed ? high : high[1], barmerge.gaps_off, barmerge.lookahead_on)

I hope this helps!

Re: creating pivot for the next day using pinescript

Posted: Tue Feb 28, 2023 4:42 pm
by anonymouss
i have change code for th,tl and tc as mentioned above,but cpr moves for every bar forms, ie lines move from the position to right side for every bar completed

Re: creating pivot for the next day using pinescript

Posted: Tue Feb 28, 2023 10:46 pm
by Steve Burman
Sorry, if it's not a repainting issue, I don't know how to fix it. Can you send a pic of the issue where new lines are adding for every bar?

Re: creating pivot for the next day using pinescript

Posted: Wed Mar 01, 2023 3:23 am
by anonymouss
here check this link

Code: Select all

https://ibb.co/DR1J6hv

Re: creating pivot for the next day using pinescript

Posted: Wed Mar 01, 2023 7:17 am
by Steve Burman
Ok, thanks for that. I just realised something.

You have specified the dotted lines to be displayed on the current real-time bar because you are conditioning the lines on barstate.islast. The pine script manual states... "PineScript code that uses this variable could calculate differently on history and real-time data. Please note that using this variable/function can cause indicator repainting" which may be part of the problem."

I'm thinking that if you are wanting to draw pivot lines at the end of the day ready for the next day then you could use code like this...

newDay = ta.change(time('D')) // Determines if this is a new day based on the market you are charting.
if newDay
line.new(bar_index+1,tP,bar_index+endBarIndex,tP, style=line.style_dotted,color = color.blue,width = 2)
line.new(bar_index+1,tBC,bar_index+endBarIndex,tBC, style=line.style_dotted,color = color.purple,width = 2)
line.new(bar_index+1,tTC,bar_index+endBarIndex,tTC, style=line.style_dotted,color = color.purple,width = 2)

Please correct me if my assumtion is wrong

Re: creating pivot for the next day using pinescript

Posted: Wed Mar 01, 2023 9:07 am
by anonymouss
thanks for the update, iam not able to see next day pivot line, untill next day first bar starts, then only i can see three lines. here i want to get lines before day itself and also it will present on next day when bar starts

eod image:
first bar starts on next day:

Re: creating pivot for the next day using pinescript

Posted: Fri Mar 03, 2023 3:26 am
by anonymouss
any suggestions ?

Re: creating pivot for the next day using pinescript

Posted: Fri Mar 03, 2023 5:13 am
by Steve Burman
Yes quite a challenge. Sorry I don't have any further ideas on how to fix this for you.

Hopefully someone else can help with this one!