o1-preview-2024-09-12· OpenAI
WildChat-4.8M (AI2)
Create an Indicator for TradingView that Highlight Each Day Range with Different Color…
- User
Create an Indicator for TradingView that Highlight Each Day Range with Different Color in Week
- Assistant
Create an Indicator for TradingView that Highlight Each Day Range with Different Color in Week
Certainly! Below is a TradingView Pine Script indicator that highlights each day's range with a different color for each weekday. This script calculates the high and low of each day and fills the area between them with a specific color corresponding to the day of the week.
//@version=5
indicator("Day Range Highlighter", overlay=true)
// Initialize variables
var float dayHigh = na
var float dayLow = na
var color fillColor = na
var int curDayOfWeek = dayofweek
// Detect new day
isNewDay = ta.change(time('D'))
if isNewDay
// Reset high and low for the new day
dayHigh := high
dayLow := low
// Update the current day of the week
curDayOfWeek := dayofweek
else
// Update the day's high and low
dayHigh := math.max(dayHigh, high)
dayLow := math.min(dayLow, low)
// Assign colors based on the day of the week
switch curDayOfWeek
dayofweek.monday =>
fillColor := color.new(color.blue, 80)
dayofweek.tuesday =>
fillColor := color.new(color.green, 80)
dayofweek.wednesday =>
fillColor := color.new(color.red, 80)
dayofweek.thursday =>
fillColor := color.new(color.orange, 80)
dayofweek.friday =>
fillColor := color.new(color.purple, 80)
=>
fillColor := na // No color for weekends or undefined days
// Plot the day's high and low
plotHigh = plot(dayHigh, display=display.none) // Hide the plot lines
plotLow = plot(dayLow, display=display.none)
// Fill the area between the day's high and low with the assigned color
fill(plotHigh, plotLow, color=fillColor)
Variable Initialization:
dayHigh and dayLow store the highest high and lowest low of the current day.fillColor will hold the color used to fill the day's range.curDayOfWeek keeps track of the current day of the week.Detecting a New Day:
isNewDay checks if a new day has started by detecting a change in the daily time (time('D')).dayHigh, dayLow, and updates curDayOfWeek.Updating Day's High and Low:
dayHigh and dayLow with the maximum and minimum values.Assigning Colors:
switch statement assigns a specific color to fillColor based on curDayOfWeek.Plotting and Filling:
display=display.none).fill function fills the area between plotHigh and plotLow with fillColor.color.new(color.<color_name>, opacity) in the switch statement.This indicator will now highlight each day's range on your chart with different colors for each weekday, helping you visually distinguish the trading ranges throughout the week.
Not yet included in a published release.