I found this indicator by mladen - TMA Bands + CD non repaint. I'd like to convert the mq4 to Amibroker afl but my coding is limited.
On the Amibroker forum there is some code for TMA bands but it repaints horribly - https://forum.amibroker.com/t/need-m...e-for-tma/1645
If anyone knows why it repaints so much, please correct the code.
_SECTION_BEGIN("TMA");
HalfLength = Param("HalfLength", 61, 1, 999);
ATRPeriod = Param("ATRPeriod", 110,1,1000);
ATRMultiplier9 = Param("ATR Multiplier 9", 5.0);
cMidB = ParamColor("Mid Band", colorGreen);
cUprB = ParamColor("Upper Band", colorRed);
cLwrB = ParamColor("Lower Band", ColorRGB(30,144,255));
HalfLength=Max(HalfLength,1);
midBand = Null;
p = Close;
sma = MA(P, 1);
iatr= ATR(ATRPeriod);
iLmt = BarCount-1 - (HalfLength);
for (i=0; i<BarCount; i++)
{
dSum = (HalfLength+1)* sma[i];
sumw = (HalfLength+1);
for(j=1, k=HalfLength; j<=HalfLength; j++, k--)
{
if(i+j>=BarCount) break;
dSum += k* sma[i+j];
sumw += k;
if (j<=i)
{
dSum += k*sma[i-j];
sumw += k;
}
}
MidBand[i] = dSum/sumw;
}
UprBand9 = MidBand+iATR*ATRMultiplier9;
LwrBand9 = MidBand-iATR*ATRMultiplier9;
Plot(MidBand, "MidBand", cMidB, styleNoLabel|styleNoTitle);
Plot(UprBand9, "UprBand9", cUprB, styleNoLabel|styleNoTitle|styleStaircase);
Plot(LwrBand9, "LwrBand9", cLwrB, styleNoLabel|styleNoTitle|styleStaircase);
_SECTION_END();
Attached File(s)
On the Amibroker forum there is some code for TMA bands but it repaints horribly - https://forum.amibroker.com/t/need-m...e-for-tma/1645
If anyone knows why it repaints so much, please correct the code.
_SECTION_BEGIN("TMA");
HalfLength = Param("HalfLength", 61, 1, 999);
ATRPeriod = Param("ATRPeriod", 110,1,1000);
ATRMultiplier9 = Param("ATR Multiplier 9", 5.0);
cMidB = ParamColor("Mid Band", colorGreen);
cUprB = ParamColor("Upper Band", colorRed);
cLwrB = ParamColor("Lower Band", ColorRGB(30,144,255));
HalfLength=Max(HalfLength,1);
midBand = Null;
p = Close;
sma = MA(P, 1);
iatr= ATR(ATRPeriod);
iLmt = BarCount-1 - (HalfLength);
for (i=0; i<BarCount; i++)
{
dSum = (HalfLength+1)* sma[i];
sumw = (HalfLength+1);
for(j=1, k=HalfLength; j<=HalfLength; j++, k--)
{
if(i+j>=BarCount) break;
dSum += k* sma[i+j];
sumw += k;
if (j<=i)
{
dSum += k*sma[i-j];
sumw += k;
}
}
MidBand[i] = dSum/sumw;
}
UprBand9 = MidBand+iATR*ATRMultiplier9;
LwrBand9 = MidBand-iATR*ATRMultiplier9;
Plot(MidBand, "MidBand", cMidB, styleNoLabel|styleNoTitle);
Plot(UprBand9, "UprBand9", cUprB, styleNoLabel|styleNoTitle|styleStaircase);
Plot(LwrBand9, "LwrBand9", cLwrB, styleNoLabel|styleNoTitle|styleStaircase);
_SECTION_END();