I'm trying to code an indicator using the heikin ashi open and close prices.
I want the program to draw a horizontal ray on the highest close price of a group of consecutive green or red heikin ashi candles.
For example, if the heikin ashi trend changes from red candles to green. I would ask the program to monitor the consecutive heikin green candles pick the highest closing price of the group of green and draw a horizontal ray.
Please see the picture above where I manually drew the horizontal rays according to the criteria I want.
I have written the below code but the problem is that it is drawing a horizontal ray on each candle that has a closing price higher(in case of green candle) or lower(in case of red candle) than the previous one. What I need to is to pick the highest closing price of a group of heikin ashi candles of the same color.
//@version=5
indicator("Heinkin Ashi
lines",shorttitle="HAL",overlay=true,max_bars_back=500)
time_frame=input.timeframe('W',"timeframe", options=['D', 'W', 'M'])
haTicker = ticker.heikinashi(syminfo.tickerid)
[haO, haH, haL, haC] = request.security(haTicker, time_frame, [open, high,
low, close])
float haC_green=0.000
if haC>=haO and haC >=haC[2] and haC >= haC[2]
haC_green:=haC
line.new(0,haC_green,bar_index,haC_green,
xloc=xloc.bar_index,extend=extend.none,color=color.black)
float haC_red=0.000
if haC<=haO and haC <=haC[2]
haC_red:=haC
line.new(0,haC_red,bar_index,haC_red,
xloc=xloc.bar_index,extend=extend.none,color=color.red)