Working with various timeframe inside script irrespective of timeframe selected in charts

14 Views Asked by At

I want to extract high, low, close, open of 1st 30minute candle and make it save/plot for throughout the day irrespective of the time frame selected in tradingview chart.

I have tried using various codes, also in one of them open and close of first 30minute candles was plotted but high, low was not achieved.

Example Code for Above:

//@version=5
indicator("Levels Indicator COPYY",overlay = true)
isNewDay = time("D") != time("D")[1]
// Determine session start time
sessionStart = time(timeframe.period, "0915-0950")  // Adjust for your timezone

// Calculate OHLC values for the first 30 minutes
var float first30High = na  // Use 'var' to maintain values throughout the day
var float first30Low = na
var float first30Open = na
var float first30Close = na

if time >= sessionStart and time < sessionStart + 30 * 60
    if isNewDay
        first30Open := open
    first30High := math.max(first30High,high)   // Corrected max logic
    first30Low := math.min(first30Low,low[1])         // Corrected min logic
    first30Close := close // Capture close of 30-minute period

// Marking the values for the rest of the day
plot(first30Open, title="Open", color=color.blue) 
plot(first30High, title="High", color=color.green) 
plot(first30Low, title="Low", color=color.red) 
plot(first30Close, title="Close", color=color.orange)

In above code high, low out remained null throughout the day.

0

There are 0 best solutions below