I stuck again in a little problem with following code
_SECTION_BEGIN("Donchian channel");
Pds = Param("Periods",20,2,200,1);
bullcolor=ParamColor("bullcolor", colorbrightgreen);
bearcolor=ParamColor("bearcolor", colorred);
drawcolor= colorWhite;
DonchianUpper =HHV(Ref(H,0),pds);
DonchianLower = LLV(Ref(L,0),pds);
DonchianMiddle = (DonchianUpper+DonchianLower)/2;
uptrend = (DonchianUpper>Ref(DonchianUpper,-1) and DonchianLower>=Ref(DonchianLower,-1))
or (DonchianLower>Ref(DonchianLower,-1) and DonchianUpper>=Ref(DonchianUpper,-1));
downtrend = (DonchianUpper<Ref(DonchianUpper,-1) and DonchianLower<=Ref(DonchianLower,-1))
or (DonchianLower<Ref(DonchianLower,-1) and DonchianUpper<=Ref(DonchianUpper,-1));
drawcolor = IIf(uptrend,bullcolor,IIf(downtrend,bearcolor,Ref(drawcolor,-1)));
Plot(DonchianUpper,"DU",drawcolor,styleLine);
Plot(DonchianMiddle,"DM",drawcolor,styleLine);
Plot(DonchianLower,"DL",drawcolor,styleLine);
_SECTION_END();
I want simply that always the last trend of the Donchian channel reflects in the color,
and the last trendcolor remains also if the channel continues horizontal but it just doesn't work.
I also tried with
drawcolor = Flip( bullcolor,bearcolor);
as it was recommanded elsewhere, but this doesn't work neither.
Thank you for your attention and help.