|
I have the tradestation code for TRIX...and IMHO it is a good indicator. the code is divided into a function and an indicator. hope somebody will be able to convert it.
Function::::::::::::
Price( numericseries ),
Length( numericsimple ) ; { this input assumed to be a constant >= 1 }
variables:
TRIXRaw( 0 ) ;
TRIXRaw = XAverage( XAverage( XAverage( Log( Price ), Length ) , Length ) , Length ) ;
if CurrentBar > 1 then
TRIX = ( TRIXRaw - TRIXRaw[1] ) * 10000 ;
Indicator::::::::::::::::
inputs:
Price( Close ),
Length( 9 ),
ColorNormLength( 14 ), { Number of bars over which to normalize the indicator
for gradient coloring. See also: comments in function NormGradientColor. }
UpColor( Yellow ), { Color to use for indicator values that are relatively high
over ColorNormLength bars. }
DnColor( Red ), { Color to use for indicator values that are relatively low
over ColorNormLength bars. }
GridForegroundColor( Black ) ; { Color to use for numbers in RadarScreen cells
when gradient coloring is enabled, that is, when both UpColor and DnColor are
set to non-negative values. }
{ Set either UpColor and/or DnColor to -1 to disable gradient plot coloring.
When disabled, Plot1 color is determined by settings in indicator properties
dialog box. Plot2 (ZeroLine) color always comes from indicator properties
dialog box. }
variables:
ApplicationType( 0 ),
TRIXValue( 0 ),
ColorLevel( 0 ) ;
if CurrentBar = 1 then
ApplicationType = GetAppInfo( aiApplicationType ) ;
TRIXValue = TRIX( Price, Length ) ;
Plot1( TRIXValue, "TRIX" ) ;
Plot2( 0, "ZeroLine" ) ;
{ Gradient coloring }
if UpColor >= 0 and DnColor >= 0 then
begin
ColorLevel = NormGradientColor( TRIXValue, true, ColorNormLength, UpColor, DnColor ) ;
if ApplicationType = 1 then { study is applied to a chart }
SetPlotColor( 1, ColorLevel )
else if ApplicationType > 1 then { study is applied to grid app }
begin
SetPlotColor( 1, GridForegroundColor ) ;
SetPlotBGColor( 1, ColorLevel ) ;
end ;
end ;
{ Alert criteria }
if TRIXValue crosses over 0 then
Alert( "Indicator turning positive" )
else if TRIXValue crosses under 0 then
Alert( "Indicator turning negative" ) ;
----------------------------------------------------------------
The XAverage function is a weighted moving average of the prices of the last length bars. This function returns the current value of the exponentially smoothed moving average.
|