I am a newbie, and can’t get the attached code to work.
It just yield zero line.
It is my attempt to translate code from amibroker.
Please help.
Xlength = 5
Length = 18
Synthetic = Xlength * Length
Value1 = lowest[synthetic](Low)
Value2 = highest[synthetic](High) - Value1
If Value2 > 0 then
XTK = (Close - Value1)/Value2 * 100.0
else
XTK = 0
endif
for i = 0 to BarIndex do
if i >= Xlength then
XTDF = XTDF[i-Xlength] + 0.5 *( XTK[i] - XTDF[i-Xlength])
else
XTDF = 0
endif
next
Return XTDF coloured(100,100,0) as "XTDF"
I didn’t check the calculations, yet.
Still I can see you are using very time consuming loops.
BARINDEX will soon exceed a value of several thousands units… slowing (if not freezing at all) your system quite much. I can’t figure out why you weren’t reported an error message by the system!
The result is always ZERO because the initial value of XTDF is 0 and you ALWAYS end up there because your loop backwards will always end up catching the value tied to variable i which will always go back i times to when the code started.