Metastock Formulas – Trend Intensity Index & Flatliner

Hi Christian,

Going through this code line by line, there are some savings to be made:

chartdays:= (Cum(C/C));
is just a bar counter and is the same as:
chartdays:= Cum(1);

check:= (O=C AND H=C AND L=C);
this implies H=L and if the H=L then open and close prices must also be the same (unless you have shonky data) so we can save some more processing by using:
check:= H=L;

flatliner:= Cum(check);
no problems here.

result:= chartdays – flatliner;
isn’t addressed so can be removed from the code.

percentage:= (flatliner / chartdays)*(100/1);
the 1 divisor is redundant, but I can see the way you think.

So my take on the code would be:

chartdays:= Cum(1);
check:= H=L;
flatliner:= Cum(check);
percentage:= 100 * flatliner / chartdays;
{plot/return}
percentage;

You might also consider that looking back through the entire history on the chart might not be that relevant to the latest price action, so you could use a lookback setting to view the percentage of “flatbars” in a given period, something like:

{requires the free forum.dll for the adaptive sum function}
lookback:=255; {bars}
lookback:=If(Cum(1)<lookback,Cum(1),lookback);
check:= H=L;
flatliner:= ExtFml(“forum.Sum”,check,lookback);
percentage:= 100 * flatliner / lookback;
{plot/return}
percentage;

Hope this gives some more ideas?

wabbit :D

Be the first to comment

Leave a Reply

Your email address will not be published.


*