function TrendStrengthESeries( Series: Integer; PeriodStart: Integer ; PeriodEnd: Integer ; Step: integer): integer;) begin var Bar: integer; var sName: string; var Value: float; var i, dummy:integer; var SMAval, maxval:float; var lst: TList; sName := 'TrendStrengthE(' + GetDescription( Series ) + ',' + IntToStr( PeriodStart ) + ',' + IntToStr( PeriodEnd )+ ','+Inttostr(step)+')'; Result := FindNamedSeries( sName ); if Result >= 0 then Exit; Result := CreateNamedSeries( sName ); If PeriodStart>PeriodEnd then begin //make sure startPeriodEnd; lst.SortNumeric; Value:=0; for i:=0 to int(lst.count-1) do //sum up all square-differences value := value + sqr(i-lst.data(i)); maxval := 0; //calc maximum value of the indicator (to normalize it) for i:=int(lst.count/2-1) downto 0 do maxval:= maxval + sqr(lst.count - 1 - 2*i); SetSeriesValue( Bar, Result, Value / Maxval - 1 ); end; SingleCalcMode(false); //Restore settings to normal values end; function TrendStrengthE( Bar: integer; Series: Integer; PeriodStart: Integer; PeriodEnd: Integer ; Step: integer): float; begin Result := GetSeriesValue( Bar, TrendStrengthESeries( Series, PeriodStart, PeriodEnd, Step ) ); end;