Candle color change according to indicator value

I want to change candle color in which candle rsi(14) makes the highest value during the day say in 5mint chart.

DN=DateNum();
NewDay=DN!=Ref(DN,-1)  OR BarIndex() == 0;
NwDayBars=SelectedValue(BarsSince(NewDay));
DayHstRSI14=HHV(RSI(14),NwDaybars);
Plot( C, "C", IIf(RSI(14)==DayHstRSI14,colorYellow,colorDefault), styleCandle );
1 Like

thanks for the quick reply sir. But the code is changing color of multiple bar. i want but if the highest value is not same for more than 1 bar then it should change color of one bar onlyrs

NwDayBars=SelectedValue(BarsSince(NewDay));

SelectedValue() will keep changing on selection, if OP is checking for all bars in the day. LastValue() is apt.

Then, HHV() can return the Highest Value in all bars of the day.

1 Like

Thank you @travick .
Had tried both(Selected/LastValue()) before posting, and as the Lastvalue() was producing result only on the last day, opted for SelectedValue() for visual affirmation.
Would HighestSince() be a better option ?

I don't think there'd be much difference in performance, but

rsi14 = RSI( 14);
DayHstRSI14 = HighestSince( NewDay, rsi14, 1);

Would be simpler in straightforward :slight_smile:

2 Likes

@nudip , Please try

DN=DateNum();
NewDay=DN!=Ref(DN,-1)  OR BarIndex() == 0;
RSI14 = RSI( 14);
DayHstRSI14 = HighestSince( NewDay, RSI14, 1);
Plot(C,"C",IIf(RSI14==DayHstRSI14,ColorYellow,ColorDefault), styleCandle );``


OR

DN=DateNum();
RSI14=RSI(14);
NewDay=DN!=Ref(DN,-1)  OR BarIndex() == 0;
NwDayBars=LastValue(BarsSince(NewDay));
DayHstRSI14=HHV(RSI14,NwDayBars);
Plot(C,"C",IIf(RSI14==DayHstRSI14,colorYellow,colorDefault), styleCandle );```
2 Likes

both of the code is giving the same result. changing color of multiple candle. basically the code is starting plotting yellow candle when it cross the previous peak.

This will highlight the price bar with the highest RSI(14) each day. Is that what you want?

RSI14 = RSI( 14);
maxDailyRSI = TimeFrameExpand(TimeFrameCompress(RSI14, inDaily, compressHigh), inDaily, expandFirst);
Plot(C,"C",IIf(RSI14==maxDailyRSI,ColorYellow,ColorDefault), styleCandle );
5 Likes

thanks a lot sir, it works like charm. how simple it is and was thinking for 2days how use bar count this that and all. thanks a lot sir.