tradingview/lightweight-charts

Both Box and line controls not movable using mouse into the future

BillionShields opened this issue · 1 comments

Both Box and Line controls are preventing from moving them using mouse into the future
This is a bug! Make sure controls can be moved into the future grabbing corners with the mouse. Sample video and code included

https://youtu.be/Q6b_qLXpafI

//@Version=5
indicator("X3EM Forecasting Box", shorttitle="X3EM FBox", overlay=true)

// Input for start point
startPrice = input.price(defval=0, title="Start Price", confirm=true, inline="Start")
startTime = input.time(defval=timestamp("2023-01-01"), title="Start Time", confirm=true, inline="Start")

// Input for end point
endPrice = input.price(defval=0, title="End Price", confirm=true, inline="End")
endTime = input.time(defval=timestamp("2023-12-31"), title="End Time", confirm=true, inline="End")

// Color and style inputs
boxColor = input.color(defval=color.blue, title="Box Color", inline="Style")
boxTransparency = input.int(defval=80, title="Transparency", minval=0, maxval=100, inline="Style")
borderWidth = input.int(defval=2, title="Border Width", minval=1, maxval=5)

// Store the last valid inputs
var float lastStartPrice = na
var int lastStartTime = na
var float lastEndPrice = na
var int lastEndTime = na

// Update stored values only on the last historical bar
if barstate.islastconfirmedhistory
lastStartPrice := startPrice
lastStartTime := startTime
lastEndPrice := endPrice
lastEndTime := endTime

// Calculate box coordinates
var box forecastBox = na

if barstate.isfirst
forecastBox := box.new(left=lastStartTime, top=lastStartPrice, right=lastEndTime+100, bottom=lastEndPrice,
xloc=xloc.bar_time,
bgcolor=color.new(boxColor, boxTransparency),
border_color=boxColor,
border_width=borderWidth)

// Update box on every bar
if not na(forecastBox) and barstate.islast
box.set_lefttop(forecastBox, lastStartTime, math.max(lastStartPrice, lastEndPrice))
box.set_rightbottom(forecastBox, lastEndTime, math.min(lastStartPrice, lastEndPrice))
box.set_bgcolor(forecastBox, color.new(boxColor, boxTransparency))
box.set_border_color(forecastBox, boxColor)
box.set_border_width(forecastBox, borderWidth)

// Extend visible chart area into the future
maxLookaheadBars = 1000 // Increase this value to see further into the future
lastVisibleTime = math.max(time + maxLookaheadBars * timeframe.multiplier * 60 * 1000, lastEndTime)
plot(time == lastVisibleTime ? high : na, style=plot.style_circles, color=color.new(color.blue, 100))

// Plot points for visibility
plotColor = input.color(defval=color.green, title="Point Color", inline="PointStyle")
plotSize = input.int(defval=3, title="Point Size", minval=1, maxval=10, inline="PointStyle")
plot(time == lastStartTime ? lastStartPrice : na, style=plot.style_circles, color=plotColor, linewidth=plotSize, title="Start Point")
plot(time == lastEndTime ? lastEndPrice : na, style=plot.style_circles, color=plotColor, linewidth=plotSize, title="End Point")

This repo is for the Lightweight Charts open source project and is unrelated to PineScript.
Please view the link below to find some more help and resources for PineScript:
https://www.tradingview.com/pine-script-docs/where-can-i-get-more-information/