I am trying to write a code to get the next day fibonacci pivot point. but the problem is that the lines are extending to infinite, whereas I want to limit it to only next day.
The code is as follows:
`indicator("Next Day Fibonacci Pivot Point",overlay = true)
todaysClose = request.security(syminfo.tickerid,"D",close,gaps =barmerge.gaps_off, lookahead =barmerge.lookahead_on)
todaysHigh = request.security(syminfo.tickerid,"D",high,gaps =barmerge.gaps_off, lookahead =barmerge.lookahead_on)
todaysLow = request.security(syminfo.tickerid,"D",low,gaps =barmerge.gaps_off, lookahead =barmerge.lookahead_on)
pivot = (todaysHigh+todaysClose+todaysLow)/3
R1 = (pivot)+0.382*(todaysHigh-todaysLow)
S1 = (pivot)-0.382*(todaysHigh-todaysLow)
R2 = (pivot)+0.618*(todaysHigh-todaysLow)
S2 = (pivot)-0.618*(todaysHigh-todaysLow)
R3 = (pivot)+1*(todaysHigh-todaysLow)
S3 = (pivot)-1*(todaysHigh-todaysLow)
R4 = (pivot)+0.382*(todaysHigh-todaysLow)
S4 = (pivot)-0.382*(todaysHigh-todaysLow)
R5 = (pivot)+2*(todaysHigh-todaysLow)
S5 = (pivot)-2*(todaysHigh-todaysLow)
R6 = (pivot)+2.414*(todaysHigh-todaysLow)
S6 = (pivot)-2.414*(todaysHigh-todaysLow)
R7 = (pivot)+3*(todaysHigh-todaysLow)
S7 = (pivot)-3*(todaysHigh-todaysLow)
R8 = (pivot)+3.414*(todaysHigh-todaysLow)
S8 = (pivot)-3.414*(todaysHigh-todaysLow)
R9 = (pivot)+4*(todaysHigh-todaysLow)
S9 = (pivot)-4*(todaysHigh-todaysLow)
if(barstate.islast)
line.new(bar_index,pivot, bar_index+1, pivot, extend = extend.right, color= color.blue,width = 2)
line.new(bar_index,R1, bar_index+1, R1, extend = extend.right, color= color.red,width = 2, xloc = xloc.bar_index)
line.new(bar_index,S1, bar_index+1, S1, extend = extend.right, color= color.green,width = 2)
line.new(bar_index,R2, bar_index+1, R2, extend = extend.right, color= color.red,width = 2)
line.new(bar_index,S2, bar_index+1, S2, extend = extend.right, color= color.green,width = 2)
line.new(bar_index,R3, bar_index+1, R3, extend = extend.right, color= color.red,width = 2)
line.new(bar_index,S3, bar_index+1, S3, extend = extend.right, color= color.green,width = 2)
line.new(bar_index,R4, bar_index+1, R4, extend = extend.right, color= color.red,width = 2)
line.new(bar_index,S4, bar_index+1, S4, extend = extend.right, color= color.green,width = 2)
line.new(bar_index,R5, bar_index+1, R5, extend = extend.right, color= color.red,width = 2)
line.new(bar_index,S5, bar_index+1, S5, extend = extend.right, color= color.green,width = 2)
line.new(bar_index,R6, bar_index+1, R6, extend = extend.right, color= color.red,width = 2)
line.new(bar_index,S6, bar_index+1, S6, extend = extend.right, color= color.green,width = 2)
line.new(bar_index,R7, bar_index+1, R7, extend = extend.right, color= color.red,width = 2)
line.new(bar_index,S7, bar_index+1, S7, extend = extend.right, color= color.green,width = 2)
line.new(bar_index,R8, bar_index+1, R8, extend = extend.right, color= color.red,width = 2)
line.new(bar_index,S8, bar_index+1, S8, extend = extend.right, color= color.green,width = 2)
line.new(bar_index,R9, bar_index+1, R9, extend = extend.right, color= color.red,width = 2)
line.new(bar_index,S9, bar_index+1, S9, extend = extend.right, color= color.green,width = 2)
Well, you have
extend = extend.rightin eachline.new()call. That's why they extend.If you want to limit this extension until the start of the next of day, you need to calculate that time and use
xloc=xloc.bar_timeinstead ofxloc=xloc.bar_index.Here is an example:
Please note that the white vertical line is manually drawn by me to show you the timestamp (next day) where the blue line stops.
You may need to cover corner cases like last day of the month or last day of the year. They seem to work as far as I can see.