/*[[ Name := trend power Author := Copyright © 2004, Nick Bilak Link := Separate Window := Yes First Color := Red First Draw Type := Line Use Second Data := Yes Second Color := DimGray Second Draw Type := Line Second Symbol := 218 ]]*/ Inputs : SMAfast(7),SMAslow(65),LoTrigger(-0.3),HiTrigger(0.3); Variables : shift(0), MAType(1), cnt(0), loopbegin(0), first(True), prevbars(0); Variables : sum(0), smconst(0), prev(0), weight(0), linear(0); Variables : MAValue(0), MAstring(""); var: signal(0),noise(0),efRatio(0),i(0), Fastest(0.6667), Slowest(0.0645); SetLoopCount(0); // initial checkings // check for additional bars loading or total reloading If Bars < prevbars Or Bars-prevbars>1 Then first = True; prevbars = Bars; If first Then Begin // loopbegin prevent couning of counted bars exclude current loopbegin = Bars-SMAslow-1; If loopbegin < 0 Then Exit; // not enough bars for counting first = False; End; // moving average loopbegin = loopbegin+1; // current bar is to be recounted too For shift = loopbegin Downto 0 Begin MAValue = 100 * (iMA(SMAfast,MODE_SMA,shift) - iMA(SMAslow,MODE_SMA,shift))/iMA(SMAslow,MODE_SMA,shift); SetIndexValue(shift,MAValue); if MAValue<0 Then SetIndexValue2(shift,LoTrigger) Else SetIndexValue2(shift,HiTrigger); loopbegin = loopbegin-1; // prevent to previous bars recounting End;