'How to plot only current day open on chart at end as line for NQ cash session?
//@version=4
study("Open of first bar of a day")
// If start of the daily session changed, then it's first bar of the new session
isNewDay = time("D") != time("D")[1]
var firstBarCloseValue = open
if isNewDay
firstBarCloseValue := open
plot(firstBarCloseValue)
Above code plots the series but i just want current day open like line extended to right not sure how i can achieve that. Any help appreicated.
Solution 1:[1]
You can use the line() for that.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vitruvius
//@version=5
indicator("My script", overlay=true)
var line l_open = na
// If start of the daily session changed, then it's first bar of the new session
isNewDay = time("D") != time("D")[1]
var firstBarCloseValue = open
if isNewDay
firstBarCloseValue := open
line.set_extend(l_open, extend.none) // This at the moment points to the previous day's line. Do not extend it anymore as that day is over.
l_open := line.new(bar_index, firstBarCloseValue, bar_index+1, firstBarCloseValue, extend=extend.right)
else
line.set_x2(l_open, bar_index)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | vitruvius |

