Tony maxx
Tony maxx

Reputation: 1

How to Plot Supply Zones Based on Daily Timeframe Data When Viewing Lower Timeframes in Pine Script (TradingView)?

I am trying to create a TradingView indicator using Pine Script that calculates supply zones based on daily timeframe data. However, I want these supply zones to remain plotted and accurately represented when I switch to lower timeframes (e.g., hourly, 15-minute charts). My goal is to have the supply zones identified on the daily chart persist and display correctly even when I view the chart in lower timeframes.

I wrote a script to identify supply zones based on volume and price action conditions. The script works correctly when applied to the daily chart, plotting the supply zones as intended. However, when I switch to a lower timeframe, the script recalculates the supply zones based on the lower timeframe data, which is not what I want.I want the supply zones to be calculated using daily timeframe data and then be plotted on the chart in a way that they are visible and correctly positioned even when switching to lower timeframes. will plot fuction or others solve this problem? i am fairly new to pinescript development and stackoverflow. I added two images, in daily timeframe i marked a supply zone with a rectangle and in 4h timeframe the lines should be extended like the rectangle but the indicator calculates for 4h timeframe

//@version=5
indicator("SnD and SMT", overlay=true)

// Function to check conditions for supply zone
ConditionForSupply(volume, high, close) =>
    volume > volume[1] and high > high[1] and high[1] > close

// Check if current candle satisfies supply zone condition
candle1 = ConditionForSupply(volume, high, close) and close < low[1]

// Supply zone drawing condition
drawingConditionSupplyHigh = ta.valuewhen(candle1, high, 0)
drawingConditionSupplyClose = ta.valuewhen(candle1, close, 0)

var int extend_bars = 60

// Function to plot lines
plotLines(index, high, close) =>
    line.new(x1=index, y1=high, x2=index+extend_bars, y2=high, color=color.green, width=2, style=line.style_solid)
    line.new(x1=index, y1=close, x2=index+extend_bars, y2=close, color=color.green, width=2, style=line.style_solid)

// Call plotLines function when the supply zone condition is met
if candle1
    plotLines(bar_index, high, close)

enter image description here enter image description here

Upvotes: 0

Views: 76

Answers (0)

Related Questions