Reputation: 11
I have been trying to plot take profit and stop loss lines for a script I wrote, but I am struggling with plotting lines in the future.
I have tried using the plot and line.new functions but with no success.
An example of what I would like to see
Upvotes: 1
Views: 4390
Reputation: 1
I wrote something that does exactly what you seek. I plot the Daily Pivot lines to the right of the bars, so they don't get in the way. The trick is to use a trendline instead of a "plot" line, and have the trendline offset by a certain amount of time rather than using the "offset" feature.
You can see I calculate the time value of one bar using labeldt, then define the x1 and x2 options using (time + (labeldt * 20)), which means to begin the trendline at the current bar and plot it 20 bars into the future. The y1 and y2 options define what price level it will be plotted on.
Good luck
/////////////////////
// F L O O R P I V O T S
//
/////////////////////
labeldt = time - time[1]
/////////////////
//LINE PRICE CALCULATIONS
/////////////////////////
PPFunc() =>
xHighPP = high[1]
xLowPP = low[1]
xClosePP = close[1]
[xHighPP, xLowPP, xClosePP]
[xHigh, xLow, xClose] = security(syminfo.tickerid, 'D', PPFunc())
//xHigh = security(tickerid,1440, high[1])
//xLow = security(tickerid,1440, low[1])
//xClose = security(tickerid,1440, close[1])
vPP = (xHigh+xLow+xClose) / 3
/////////////////////////
//LINE PLOT
PlothlineDayPivotPoint = line.new(x1=time, y1=vPP, x2=time + (labeldt * 20), y2=vPP, extend=extend.none, color= #0000ff, xloc=xloc.bar_time)
//LINE STYLE
line.set_width(PlothlineDayPivotPoint, 1)
//LINE DELETER
line.delete(PlothlineDayPivotPoint[1])
/////////////////////
For your purposes you can ignore the "Line Price Calculations" section - that is just me calculating the price level.
Upvotes: 0
Reputation: 701
You can calculate the values you want to plot on the graph then set offset. Something like this,
plot(close, offset = 1, color = color.black, linewidth=2)
here offset will be number bars in the future. i.e 1 is calculated bar in future.
Upvotes: 1