Help on TTM Trend

#1
I am trying to code TTM trend. The logic is as follows:
AVPR = Avg Price of last 6 days
When current day candle close is greater than AVPR, the candle will be of GREEN color, else RED.

The code that I have written is as follows:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
_SECTION_BEGIN("TTM Trend ");

SetChartOptions(0,chartShowArrows|chartShowDates);
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

Up = C > O;
Down = C < O ;

SetBarFillColor( IIf( up, colorGreen, colorRed ) );


AVPR = (((Ref(H,-1) +Ref(L,-1))/2)+((Ref(H,-2) +Ref(L,-2))/2)+((Ref(H,-3) +Ref(L,-1))/3)+((Ref(H,-4) +Ref(L,-4))/2)+((Ref(H,-5) +Ref(L,-5))/2)+((Ref(H,-6) +Ref(L,-6))/2))/6;

Plot( C, "C-AVPR",IIf( (Close > AVPR), colorGreen, colorRed), styleCandle );

_SECTION_END();
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
But candle color is not changing based on the logic. It is always green candle.
Seems some issue with code Plot( C, "C-AVPR",IIf( (Close > AVPR), colorGreen, colorRed), styleCandle );
Not able to fix this.
Can anyone please help in correcting the code?

Regards,
Sarit
 

Similar threads

Zerodha – Open Paperless Account

Open online account with Zerodha. Free delivery trading and Max Rs 20 for Intraday, F&O, Currency and Commodity Trading. Intraday High leverage with MIS, CO and BO.

Name:Phone:
Email:City:
State:
Are you a day trader?