Need help for TOS to AFL

Hi,

Can anyone convert the following TOS indicator to AFL?

Thank you very much?

TD Ameritrade IP Company, Inc. (c) 2007-2020

input price = close;
input length = 9;
input bar_plus = 7;

plot TSF = Inertia(price, length) + LinearRegressionSlope(price, length) * bar_plus;
TSF.SetDefaultColor(GetColor(8));

Hi @chaser2009,

you don't need to convert it. First thing to do, check whether it's built into Amibroker. It is. Guide for TSF
That said, your formula looks a bit different. Check whether it's valid/what you want. If it is, you can easily tweak the code in comments' section on the above page.

Plot(LinearReg(Close, 9 )+LinRegSlope(Close, 9)*7, "TSF", colorRed );

In AFL, as mentioned in the manual, it's quite easy to ask for parameters.
For instance, you can replace the constant 9 in the above script by a parameter named length as in:

length = Param("price length/inertia", 9, 1, 50);

Similarly you can replace constants 7 and colorRed by other parameters (hint: use ParamColor() for...selecting a color). This way you get a formula equivalent to the (weird) TOS script.

I hope it will quick start your journey to AFL programming but remind that nobody will come and spoonfeed you, especially when the answer is in the manual/knowledge base/forum...and when you don't format code properly...

4 Likes

Thank you @alligator. I understand now after your explanation. Sorry for bothering you. I am new to coding and have been teaching myself the whole way.