Dear gentlemen, I am trying to make an AFL code of the Uhlma index.
For the time being I have two problems in which I ask for your help.
(1) The CTS line is not accurately reflected.
(2) The CMA line does not appear in the Amibroker's chart at all and writes to me that it is Empty.
I quote the code I have written,
thanking in advance for every possible help.
_SECTION_BEGIN( "UHLMA Crossover System" );
SetBarsRequired(100, 0);
Plot( C, "Price", colorDefault, styleCandle );
Length = Param("Length", 100, 10, 500, 10);
Mult = Param("Multiplier", 1.0, 0.1, 5.0, 0.1);
Src = ParamField("Source", 3);
Mean = MA(Src, Length);
Var = Sum((Src - Mean)^2, Length) / Length * Mult;
SMAVal = MA(Src, Length);
CMA = SMAVal;
CTS = Src;
for (i = 1; i < BarCount; i++)
{
secma = (SMAVal[i] - CMA[i-1])^2;
sects = (Src[i] - CTS[i-1])^2;
ka = IIf(Var[i] < secma, 1 - Var[i] / (secma+1e-9), 0);
kb = IIf(Var[i] < sects, 1 - Var[i] / (sects+1e-9), 0);
CMA[i] = ka * SMAVal[i] + (1 - ka) * CMA[i-1];
CTS[i] = kb * Src[i] + (1 - kb) * CTS[i-1];
}
Plot(CTS, "CTS", colorBlue, styleLine|styleThick);
Plot(CMA, "CMA", colorRed, styleLine|styleThick);
ColorFill = IIf(CTS > CMA, colorBlue, colorRed);
PlotOHLC(CTS, CTS, CMA, CMA, "", ColorFill, styleCloud);
_SECTION_END();