or return to Contents
Before creating the indicator and system, a new TRIX function must be developed. The function, which we'll call NewTRIX, is thus:
Type: Function
Name: NewTRIX
Inputs: Price(NumericSeries), Length(NumericSimple);
Vars: LogP(0), alpha(0), sm1(0), sm2(0), sm3(0);
LogP = Log(Price);
IF CurrentBar = 1 Then Begin
sm1 = LogP;
sm2 = LogP;
sm3 = LogP;
alpha = 2 / (Length + 1);
End Else Begin
sm1 = (LogP - sm1) * alpha + sm1;
sm2 = (sm1 - sm2) * alpha + sm2;
sm3 = (sm2 - sm3) * alpha + sm3;
NewTrix = (sm3 - sm3[1]) * 100;
End;
The TRIX indicator will plot a total of three lines: the TRIX value, the linear regression average of TRIX, and a zero line. The ZeroCrss (zero cross) and AvgCrss (linear regression cross) inputs determine the basis of the alerts (if alerts are enabled). If both are set to Y, then either occurrence will trigger an alert. If N is used as the input value for either, then an alert won't be triggered for that event. The indicator should be scaled to "screen."
Type: Indicator
Name: TRIX Indicator S&C
Inputs: Price(Close), TrixLen(3), TSLen(8), ZeroCrss("Y"), AvgCrss("Y");
Vars: TRXval(0), AvgTRX(0);
Condition1 = False;
Condition2 = False;
TRXval = NewTRIX(Price, TRIXLen);
AvgTRX = LinearRegValue(TRXval, TSLen, 0);
Plot1(TRXval, "TRIX");
Plot2(AvgTRX, "TRIX_LR");
Plot3(0, "Zero");
IF UpperStr(ZeroCrss) = "Y" Then Begin
IF Plot1 Crosses Above Plot3 OR Plot1 Crosses Below Plot3 Then
Condition1 = True;
End;
IF UpperStr(AvgCrss) = "Y" Then Begin
IF Plot1 Crosses Above Plot2 OR Plot1 Crosses Below Plot2 Then
Condition2 = True;
End;
IF CheckAlert AND (Condition1 OR Condition2) Then
Alert = True;
Continuing on, the entries for the TRIX system code are based on the same premise as the alerts for the indicator code given above. The ZeroCrss and AvgCross inputs are used to determine the basis for the entry signals. If both inputs are set to Y, a zero cross or a linear regression average cross will trigger a long/
short entry. If one of the two inputs is set to N, then only the other criteria will be used to generate entry signals.
Type: System
Name: TRIX System S&C
Inputs: Price(Close), TrixLen(3), TSLen(8), ZeroCrss("Y"), AvgCrss("Y");
Vars: TRXval(0), AvgTRX(0), Zero(0);
TRXval = NewTRIX(Price, TRIXLen);
AvgTRX = LinearRegValue(TRXval, TSLen, 0);
IF UpperStr(ZeroCrss) = "Y" Then Begin
IF TRXval Crosses Above Zero Then
Buy ("B_ZCrss") This Bar on Close;
IF TRXval Crosses Below Zero Then
Sell ("S_ZCrss") This Bar on Close;
End;
IF UpperStr(AvgCrss) = "Y" Then Begin
IF TRXval Crosses Above AvgTRX Then
Buy ("B_AvgCrss") This Bar on Close;
IF TRXval Crosses Below AvgTRX Then
Sell ("S_AvgCrssS") This Bar on Close;
End;
This code is available at Omega Research's Web site. The file name is "NewTrix.ela."
Gaston Sanchez with Francis A. Rivera, Omega Research 800 422-8587, 305 270-1095 Internet: https://www.omegaresearch.com
To perform this test, first enter the following three custom indicators by choosing "indicator builder" from the Tools menu. (Note: The first two formulas are repeated from last month's Traders' Tips, so if you've already entered them, you'll only have to enter the third formula.)
Rainbow Oscillator
100 *
(CLOSE - ((Mov(C,2,S) +
Mov(Mov(C,2,S),2,S) +
Mov(Mov(Mov(C,2,S),2,S),2,S) +
Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S) +
Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S) +
Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S) +
Mov(Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S),2, S) +
Mov(Mov(Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S),2,S),2,S) +
Mov(Mov(Mov(Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S),2,S),2,S),2,S) +
Mov(Mov(Mov(Mov(Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S),2,S),2,S),2,S),2,S)) /
10)) / (HHV(C,10) - LLV(C,10))
Upper Rainbow Band
100 *
(Fml("Rainbow Max") - Fml("Rainbow Min")) /
(HHV(C,10) - LLV(C,10))
Rainbow Uptrend Binary Wave
Mov(C,2,S) >
Mov(Mov(C,2,S),2,S) AND
Mov(Mov(C,2,S),2,S) >
Mov(Mov(Mov(C,2,S),2,S),2,S) AND
Mov(Mov(Mov(C,2,S),2,S),2,S) >
Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S) AND
Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S) >
Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S) AND
Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S) >
Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S) AND
Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S) >
Mov(Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S),2,S) AND
Mov(Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S),2,S) >
Mov(Mov(Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S),2,S),2,S) AND
Mov(Mov(Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S),2,S),2,S) >
Mov(Mov(Mov(Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S),2,S),2, S),2,S) AND
Mov(Mov(Mov(Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S),2,S),2,S),2,S) >
Mov(Mov(Mov(Mov(Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S),2,S),2,S),2,S),2,S)
Next, enter the following system by choosing System Tester from the Tools menu. I've created an optimization variable for the Ubro constant so you can find the results that work best for you, but you can also replace the opt1 with 38 as mentioned in Widner's article.
Rainbow Chart System
SIGNAL FORMULAS
Enter Long:
Cross( Fml( "Rainbow Uptrend Binary Wave" ),.5)
Close Long:
(Fml( "Rainbow Oscillator" ) < 0 AND
Sum(ROC(Fml( "Rainbow Oscillator" ),1,$) < 0,2) =2 AND
Fml( "Upper Rainbow Band" ) < opt1) OR
200 * (C - Ref(C,-7))/(C + Ref(C,-7)) < -7
OPTIMIZATION VARIABLES
OPT1: Ubro
Min = 30.00 Max = 60.00 Step = 1.00
First, we'll look at stochastics. In recent years, hybrid calculations for the stochastic oscillator have been developed, but here we'll stick to the formula originally given by George Lane. The stochastic that's preprogrammed in SmarTrader consists of a K line and a D% line. Rows 9 and 10 in Figure 1 are the standard K and D% calculations. Note that they both use the high, low and close price fields, since they may be calculated independently of each other. The number of periods is five. Slow D% is based on the regular D% over three periods.
Row 12 uses the preprogrammed function "highest" to determine the highest high over last five periods. Row 13 uses the function "lowest" to determine the lowest low in a similar manner. Row 14, which is W1, is a user row that calculates the current close minus the five-period lowest low. Row 15, which is W2, is a user row to calculate the five-period highest minus lowest. Row 16, which is myK, normalizes the division of W1 by W2 to a scale of zero to 100. Rows 17 and 18 sum W1 and W2 over three periods, and the results are normalized in row 19 as myD%. The easy part is mySlowD%; it's a simple moving average of the regular myD% over three periods.
The MACD indicator that's preprogrammed in SmarTrader, which is based on George Appel's original calculation, consists of an MACD line and a signal line. MACD in row 21 is based on the close and has two periods, 12 and 26. Row 22 is the signal calculation and it uses the MACD over nine periods.
Creating the MACD line is simple. Rows 23 and 24 use the preprogrammed exponential moving average (EMA) of the close over 12 and 26 periods. Note that this is not a simple moving average, which would give different results. Next, row 25 subtracts the 26-period EMA from the 12-period EMA. That
result is the MACD and is named myMACD. Row 26 is a nine-period Ema of myMACD. It's named mySignal.
FIGURE 1: SMARTRADER. The stochastic and slow stochastic and the moving average convergence/divergence (MACD) are perpetually popular studies with market technicians. This specsheet shows how each is constructed.
Although some technical analysis studies are quite complex, most are fairly simple. Many are "canned" in software to insulate the technician from having to remember how they work and from the tedium of construction.
The SmarTrader specsheet file for building the stochastic and MACD oscillators is available from Stratagem's Web site.
Jim Ritter, Stratagem Software International 504 885-7353, E-mail: Stratagem1@aol.com Internet: https://www.stratagem1.com.
WAVE WI$E spreadsheet formulas
A: DATE @TC2000(c:\tc2000\data,DJ-30,DOW JONES INDUSTRIALS,DB)
B: HIGH
C: LOW
D: CLOSE
E: OPEN
F: VOL
G: Request @INPUT(ENTER 2 DIGIT YEAR,97,1)
H: Year @IF(@YEAR(DATE) = REQUEST, CLOSE)
I: eachHi X$1=0; @IF(YEAR>X$1, YEAR : X$1=YEAR, @BLANK() )
J: HIcount X$1=0; @IF(EACHHI>0, X$1=X$1+1 : X$1, @BLANK() )
K: Gain X$2=@BLANK(); @IF(HICOUNT=1, X$2=EACHHI); 100*((EACHHI/X$2) - 1)