anonymouss
Pine Script Rookie
Pine Script Rookie
Posts: 5
Joined: February 25th, 2023

creating pivot for the next day using pinescript

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)

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: creating pivot for the next day using pinescript

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!

anonymouss
Pine Script Rookie
Pine Script Rookie
Posts: 5
Joined: February 25th, 2023

Re: creating pivot for the next day using pinescript

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

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: creating pivot for the next day using pinescript

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?

anonymouss
Pine Script Rookie
Pine Script Rookie
Posts: 5
Joined: February 25th, 2023

Re: creating pivot for the next day using pinescript

here check this link

Code: Select all

https://ibb.co/DR1J6hv

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: creating pivot for the next day using pinescript

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

anonymouss
Pine Script Rookie
Pine Script Rookie
Posts: 5
Joined: February 25th, 2023

Re: creating pivot for the next day using pinescript

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:

anonymouss
Pine Script Rookie
Pine Script Rookie
Posts: 5
Joined: February 25th, 2023

Re: creating pivot for the next day using pinescript

any suggestions ?

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: creating pivot for the next day using pinescript

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!

Return to “Pine Script Q&A”