Metastock Formulas - R
Click here to go back to Metastock Formula Index

IMPORTANT: These formulas aren't my complete collection. For my complete collection of instantly usable, profitable and powerful MetaStock formulas Click Here

Would You Like To Use MetaStock To Its Full Potential? Discover the Amazingly Simple Secret to Master Metastock Step-By-Step - click here


A | A 1 | B | B 1 | C | C 1 | D | D 1 | E | F | G | H | I | J | K | L | M | M 1 | N | O | P | R | S | S 1 | T | U | V | W | Z |

Rally Gap and Inside Day
Range High
Recursive Moving Trend Average
Regression Asymmetric Volatile Price Band
Resistance and Support
Resistance and Support *F

Random Walk Index
Rate of Change Since a Specific Date
Regression Oscillator and Slope/Close Indicator
Relative Strength Index (RSI) Custom

RSI, sine-weighted smoothed
RSI - Stochastic-normalized
Random trade generator
ROC Moving Average System Test
RSI and Moving Averages
RSI Divergence
RSI Divergence Exploration
RSI Offset
Ruggerio's Trend

Relative Volatility Index (RVI)
R-squared, Chande and Kroll's
Rule of 7 Oscillator

Rainbow Charts
Regress Slope/Money Flow Index/Time Series Forecast

Rally Gap and Inside Day

Finds stocks which have rallied, gapped upwards, and then had an inside day.

Usually leads to a resumption of the rally. The search returns 1 for Ok and 0 for not ok.

  • RallyWithVol()
  • Inside()
  • GapUp()
(Go Top)

Range High

Looks for out of range move where the close equals the high. Suggests more buying pressure.

The search returns 1 for Ok and 0 for not ok.

  • BigWhite()
  • CLOSE
(Go Top)

{Recursive Moving Trend Average}

Lb:=Input("Look-Back Period?",3,100,21);

Alpha:=2/(LB+1);

Bot:=(1-Alpha)*(If(Cum(1)<Lb,C,PREV))+C;

RMTA:=(1-Alpha)*(If(Cum(1)<Lb,C,PREV))+

(Alpha*(C+Bot-Ref(Bot,-1)));

RMTA;

{TOSC}

Lb:=Input("Look-Back Period?",3,100,21);

Alpha:=2/(LB+1);

Bot:=(1-Alpha)*(If(Cum(1)<Lb,C,PREV))+C;

RMTA:=(1-Alpha)*(If(Cum(1)<Lb,C,PREV))+

(Alpha*(C+Bot-Ref(Bot,-1)));

TOSC:=RMTA-Mov(C,lb,E);

TOSC;

Is the name of an article in the December issue of TASC, written by Dennis Meyers. In it he describes what he calls " The Recursive Moving Trend Average" . I wont go into all the article right now, but here is my translation of his math (for Metastock 6.5) :

{Recursive Moving Trend Average}
Lb:=Input("Look-Back Period?",3,100,21);
Alpha:=2/(LB+1);
Bot:=(1-Alpha)*(If(Cum(1)<Lb,C,PREV))+C;
RMTA:=(1-Alpha)*(If(Cum(1)<Lb,C,PREV))+
(Alpha*Abs(C+Bot-Ref(Bot,-1)));
RMTA;

He then explains how to make an oscillator by subtracting an Exponential MA form the Recursive MA...... again here is the code:

{TOSC}
Lb:=Input("Look-Back Period?",3,100,21);
Alpha:=2/(LB+1);
Bot:=(1-Alpha)*(If(Cum(1)<Lb,C,PREV))+C;
RMTA:=(1-Alpha)*(If(Cum(1)<Lb,C,PREV))+
(Alpha*Abs(C+Bot-Ref(Bot,-1)));
TOSC:=RMTA-Mov(C,lb,E);
TOSC;

Here is the code for System Testing;
Buy Long:

Lb:=opt1;
ent:=3;
Alpha:=2/(LB+1);
Bot:=(1-Alpha)*(If(Cum(1)<Lb,C,PREV))+C;
RMTA:=(1-Alpha)*(If(Cum(1)<Lb,C,PREV))+
(Alpha*Abs(C+Bot-Ref(Bot,-1)));
TOSC:=RMTA-Mov(C,lb,E);
Cross(tosc,(0-Abs(ent)))

Sell short:

Lb:=opt1;
ent:=3;
Alpha:=2/(LB+1);
Bot:=(1-Alpha)*(If(Cum(1)<Lb,C,PREV))+C;
RMTA:=(1-Alpha)*(If(Cum(1)<Lb,C,PREV))+
(Alpha*Abs(C+Bot-Ref(Bot,-1)));
TOSC:=RMTA-Mov(C,lb,E);
Cross((0+Abs(ent)),tosc1)

Opt1 is the look- back periods, of 3 to 30, and Opt2 is the entry value of the oscillator, 0 to 5.
Now, after all the hours spent on figuring out the code, I have discovered that the RMTA plots very similar to the DEMA, oh well............

(Go Top)

Regression Asymmetric Volatile Price Band

SIGNAL FORMULAS

Enter Long:
Periods := 21;
UpperBand := STEBandTop(CLOSE,Periods,1) ;

Sum(CLOSE > UpperBand,3) = 3 AND LinRegSlope(CLOSE,21) > 0 AND ROC(Correl(CLOSE,Cum(1) ,21,0),2,$) >= .2

Close Long:
Periods := 21;
LowerBand := STEBandBot(CLOSE,Periods,1.5) ;

SellSignal1 := Sum(CLOSE < LowerBand,3) = 3;

SellSignal2 := CLOSE < (1-.18) * HHV(HIGH,Periods + 1) AND HIGH < LowerBand;

SellSignal1 OR SellSignal2

STOPS

Maximum Loss: LONG ONLY

10.00 Percent

(Go Top)

Resistance and Support

LookBack := Input("Look Back Periods",1,1000,10);
Resistance :=ValueWhen(1,Cross(Mov(C, LookBack,
S),C),HHV(H, LookBack));
Support :=ValueWhen(1,Cross(C,Mov(C, LookBack,
S)),LLV(L, LookBack));
Resistance;
Support;

(Go Top)

Resistance and Support *F

PrCnt:=Input("Percentage",0,100,10);
LookBack:= Input("Look Back Periods",1,1000,10);
Resistance:=ValueWhen(1,Cross(Mov(C,LookBack,S),C),HHV(H,LookBack));

Support:=ValueWhen(1,Cross(C,Mov(C,LookBack,S)),LLV(L,LookBack));
Resistance * ((100-prcnt)/100);
Support * ((prcnt/100)+1);

(Go Top)

ROC Moving Average System Test

ENTER LONG:
ROC(Mov(C,12,E),1,%)>0 AND ROC(Mov(C,60,E),1,%)>0

EXIT LONG:
(ROC(Mov(C,12,E),1,%)<0 AND ROC(Mov(C,60,E),1,%)>0)
OR
(ROC(Mov(C,12,E),1,%)>0 AND ROC(Mov(C,60,E),1,%)<0)

SHORT:
ROC(Mov(C,12,E),1,%)<0 AND ROC(Mov(C,60,E),1,%)<0

EXIT SHORT:
(ROC(Mov(C,12,E),1,%)<0 AND ROC(Mov(C,60,E),1,%)>0)
OR
(ROC(Mov(C,12,E),1,%)>0 AND ROC(Mov(C,60,E),1,%)<0)

{Ref(c,-1) gives yesterday's close today. So all values are shifted to the
right!}

(Go Top)

RSI and Moving Averages

{place in filter section}

C>MOV(C,5,E) AND C>MOV(C,200,E) AND CROSS(RSI(14),30)

(Go Top)

RSI Divergence

{RSI(9) DIVERGENCE BUY:}
If(RSI(9) >= HHV(RSI(9),19) AND CLOSE <HHV(CLOSE,19), 1,0) OR
If(CLOSE <= LLV(CLOSE,19) AND RSI(9) > LLV(RSI(9),19), 1,0)

{RSI(9) DIVERGENCE SELL:}
If(CLOSE >= HHV(CLOSE,19) AND RSI(9)<HHV(RSI(9),19),1,0) OR
If(RSI(9) <= LLV(RSI(9),19) AND CLOSE > LLV(CLOSE,19),1,0)

{You can substitute any formula for the "RSI(9)"}

(Go Top)

RSI Divergence Exploration

{A simple exploration filter formula for finding a bullish divergence
between the RSI and the price is shown below. To find a bearish divergence,
replace > with <. The differences in the trough function was found through
an optimization routine and they may not be the best values for your
application.}

Ref(RSI(14),-1)>Trough(1,RSI(14),.8)
AND
Ref(CLOSE,-1)<Trough(1,CLOSE,.2)

(Go Top)

RSI Offset

RSI(13) - 50 {offset the RSI to +-50}

(Go Top)

Ruggerio's Trend

Ruggiero's rules for trend mode quoting his table 4.9:

1. If ADX crosses above 25, then the market is trending.
2. If ADX crosses below 20, then the market is consolidating.
3. If ADX crosses below 45 from above, then the market is consolidating.
4. If ADX rises from below 10 on 3 out of 4 days, then the market will start
to trend.
5. If a trend is based on rule 4, it remains in effect until the 5 day
difference in ADX is less than 0.

Ruggiero employs a 14 day ADX but that is based on T-Bonds data. He suggests employing the above rules as a filter. I make the indicator take the value +1 if trending, a -1 if consolidating according to the above criteria but I guess the zero is for the grey area
in between. Anyway according to definition: If a market is not trending it must be consolidating. However the zero may contain additional useful information. Ruggiero suggests tweaking the threshold values.

periods:=Input("Periods?",1,63,14);
If((ADX(periods)>25 AND (BarsSince(Cross(45,ADX(periods))) >
BarsSince(Cross(ADX(periods),25)))) OR (ADX(periods) > 10 AND
Ref(ADX(periods),-4)<10 AND (ADX(periods)-Ref(ADX(periods),-5)>0)), 1,
If(ADX(periods)<20 OR ((BarsSince(Cross(45,ADX(periods))) <
BarsSince(Cross(ADX(periods),25))) AND ADX(periods) < 45),-1,0))

(Go Top)

Random Walk Index

The following formulas, for the Random Walk Index, were constructed using information from the article "Are There Persistent Cycles", by E. Michael Poulos, in the September 1992 TASC.

All formulas are needed.

MetaStock Windows versions:

Random Walk Index:

Max( ( Ref(HIGH,-1) - LOW ) / ( ( Ref(Sum (Atr ( 1 ) ,2 ),-1) / 2) * Sqrt( 2 ) )
,Max( (Ref(HIGH,-2) -LOW) / ( ( Ref(Sum (Atr ( 1 ),3),-1) / 3) * Sqrt( 3 ) ), Max( (Ref(HIGH,-3) - LOW)
/ ( (Ref(Sum (Atr( 1 ) ,4) ,-1) / 4) * Sqrt( 4 ) ) , Max( ( Ref( HIGH,-4) - LOW) /
( (Ref(Sum(Atr( 1 ),5),-1) / 5) * Sqrt( 5 ) ), Max( (Ref(HIGH,-5) - LOW) / ( (Ref( Sum( Atr ( 1 ),6),-1) / 6 )
* Sqrt( 6 ) ), Max( ( Ref(HIGH,-6) -LOW) / ( (Ref( Sum( Atr( 1 ),7),-1) / 7) * Sqrt( 7 ) ),
Max((Ref(HIGH,-7)-LOW) / ( (Ref(Sum (Atr( 1 ),8),-1) / 8) * Sqrt(8) ), (Ref(HIGH,-8)-LOW) /
( (Ref(Sum (Atr (1),9),-1) / 9) * Sqrt( 9 ) ) ) ) ) ) ) ) )

(Go Top)

Rate of Change Since a Specific Date

The following formula plots a percent rate of change between a specific date and today. The user is prompted for the specific date.This will only work in MetaStock™ for Windows 95/NT version 6.5 (or higher) or in MetaStock Professional.

Construct the formula in the Indicator Builder, giving it the name shown below in bold. All the text after "FORMULA:" and before "*END OF FORMULA*" below should be placed in the Formula field in the Indicator Builder. Once the indicator has been created, you can drag it out of the Indicator Quicklist for placement in an inner-window of your chart.

NAME: ROC Since a Date

FORMULA:

Day1 := Input("Day",1,31,4);
Month1 := Input("Month",1,12,1);
Year1 := Input("Year",1900,2400,1999);

100 * (CLOSE - ValueWhen(1,DayOfMonth() = Day1 AND Month() = Month1 AND Year() = Year1, CLOSE))/ ValueWhen(1,DayOfMonth() = Day1 AND Month() = Month1 AND Year() = Year1,CLOSE)

(Go Top)

Regression Oscillator and Slope/Close Indicator

In MetaStock 6.0 it’s easy to create the Regression Oscillator and the Slope/Close Indicator from Richard Goedde’s article, "Market timing with the regression oscillator", which appears in the March 97 issue of Technical Analysis Stocks and Commodities magazine.

First choose Indicator Builder from the Tools menu and enter the following formulas:

Regression Oscillator
100 * (CLOSE/ LinearReg(CLOSE,63)-1)

Slope/Close
10000* LinRegSlope(CLOSE,63)/CLOSE

Next drag each of these formulas from the Indicator QuickList and drop them on the heading of a chart. To create horizontal lines, click the right mouse button while the mouse pointer is positioned over the Regression Oscillator to display the shortcut menu. Choose Regression Oscillator Properties. On the Horizontal lines page add horizontal lines at 14, 0, and -14.

You can use The Explorer to perform the screen mentioned in the article. First choose The Explorer from the Tools menu, next create a new Exploration with the following information:

Column A
Name: Reg Osc
Formula: Fml("Regression Oscillator")

Column B
Name: Slp/Cls
Formula: Fml("Slope/Close")

Filter
Formula: ColB > 50 and ColA >-15 and ColA < -5

Choose OK and then Explore to run the Exploration. For MetaStock for Windows 5.x users the instructions are the same except enter the following custom indicator in place the ones mentioned earlier.

Regression Oscillator
100 * (CLOSE/ ((63 * Sum(Cum(1) * C,63) - Sum(Cum(1),63) * Sum(C,63)) /
(63 * Sum(Pwr(Cum(1),2),63) - Pwr(Sum(Cum(1),63),2)) * Cum(1) + (Mov(C,63,S) - Mov(Cum(1),63,S)
* (63 * Sum(Cum(1) * C,63) - Sum(Cum(1),63) * Sum(C,63)) / (63 * Sum(Pwr(Cum(1),2),63) -
Pwr(Sum(Cum(1),63),2))))-1)

Slope/Close
10000* ((63 * Sum(Cum(1) * C,63) - Sum(Cum(1),63) * Sum(C,63)) / (63
* Sum(Pwr(Cum(1),2),63) - Pwr(Sum(Cum(1),63),2)))/CLOSE

(Go Top)

Relative Strength Index (RSI) Custom

This custom RSI will allow you to select which price data to use when you plot it. The standard RSI uses the close value as Welles Wilder did when he created the indicator. This custom indicator will allow you to use the other price fields including volume.

Q:=Input("Time Periods",1,1000,14);

B:=Input("Field: 1=Close, 2=Open, 3=High, 4=Low, 5=Volume",1,5,1);

Z:=If(B=1,Wilders(If(ROC(C,1,$)>0,ROC(C,1,$),0),LastValue(Q)),If(B=2,Wilders(If(ROC(O,1,$)>
0,ROC(O,1,$),0)LastValue(Q)),If(B=3,Wilders(If(ROC(H,1,$)>0,ROC(H,1,$),0),LastValue(Q)),
If(B=4,Wilders(If(ROC(L,1,$)>0,ROC (L,1,$),0),LastValue(Q)),Wilders(If(ROC(V,1,$)>0
,ROC(V,1,$),0),LastValue(Q))))));

Y:=If(B=1,Wilders(If(ROC(C,1,$)<0,Abs(ROC(C,1,$)),0),LastValue(Q)),If(B=2,Wilders(If(ROC
(O,1,$) <0,Abs(ROC(O,1,$)),0),LastValue(Q)),If(B=3,Wilders(If(ROC(H,1,$)<0,Abs
(ROC(H,1,$)),0),LastValue(Q)),If(B=4,Wilders(If(ROC(L,1,$)0,Abs(ROC(L,1,$)),0),LastValue(Q))
,Wilders(If(ROC(V,1, $)<0,Abs(ROC(V,1,$)),0),LastValue(Q))))));

RS:=Z/Y;

100-(100/(1+RS))

(Go Top)

Relative Volatility Index (RVI)

The following formulas were taken from the article "The relative volatility index," written by Dorsey, Donald, in the June 93 issue of Technical Analysis of STOCKS & COMMODITIES.

Taken from Stocks & Commodities, V. 11:6 (253-256): The Relative Volatility Index by Donald Dorsey

"The RVI is simply the relative strength index (RSI) with the standard deviation over the past 10 days used in place of daily price change. Because most indicators use price change for their calculations, we need a confirming indicator that uses a different measurement to interpret market strength. The RVI measures the direction of volatility on a scale of zero to 100. Readings above 50 indicate that the volatility as measured by the 10-day standard deviation of the closing prices is more to the upside. Readings below 50 indicate that the direction of volatility is to the downside. The initial testing indicates that the RVI can be used wherever you might use the RSI and in the same way, but the specific purpose of this study is to measure the RVI's performance as a confirming indicator."

The RVI was designed to measure the direction of volatility. It calculates price strength by measuring volatility rather than price change.

All of the following formulas are required:

@RVI Down

((PREV*13)+If(ROC(C,1,%)<0,Stdev(C,10),0))/14

@RVI Up

((PREV*13)+If(ROC(C,1,%)>0,Stdev(C,10),0))/14

@RVI

(100*Fml("@RVI Up"))/(Fml("@RVI Up")+Fml("@RVI Down"))

(Go Top)

R-squared, Chande and Kroll's

In their book The New Technical Trader, Chande & Kroll introduce the r2 indicator. They state that "the primary use of r2 is as a confirming indicator" and that "it is a lagging indicator that shows the strength of the trend."

In MetaStock the r2 formula is:

Pwr(Corr(Cum( 1 ),C,14,0),2)

They also present a smoothed r2 which would be:

Mov(Pwr(Corr(Cum( 1 ),C,14,0),2)*100,14,S)

For interpretation refer to Chande & Kroll's book, as stated above.

Note: The r-squared indicator is built into MetaStock for Windows version 6.0 and later.

(Go Top)

Rule of 7 Oscillator

Rule of 7 Down Objective
If((ROC(C,12,%)>-1.5),If((ROC(C,12,%)>-3),
If((ROC(C,12,%)>-4.5),((H-(H-L)*1.75)),((H-(H-L)*2.33))),((H-(H-L)*3.5))),(H-(H-L)))

Rule of 7 Up Objective
If((ROC(C,12,%)>1.5),If((ROC(C,12,%)>3),
If((ROC(C,12,%)>4.5),(((H-L)*1.75)+L),(((H-L)*2.33)+L)),(((H-L)*3.5)+L)),((H-L)+L))

Rule of 7 Oscillator
Fml("Rule of 7 UP Objective") -
Fml("Rule of 7 DOWN Objective")

(Go Top)

Rainbow Charts

To create Rainbow Charts in MetaStock for Windows, open any chart, drop the moving average indicator from the Indicator QuickList, and drop it in the same inner windows as the price bars. Enter two for the Periods and simple for the Method. Next plot a second moving average on the first moving average by dragging a moving average from the QuickList and dropping it on the first moving average (Note: The first moving average should turn light purple before you release the mouse button). If you dropped it correctly the Parameters dialog should say ‘Indicator’ for the Price Field. Click OK to accept two periods and simple as the parameters. Change the colour of this moving average as desired. Now plot a third moving average of the second moving average by repeating these steps. Continue this until you have ten moving averages. Choose Yes if MetaStock prompts you about plotting a duplicate indicator.

To save you time, Equis have created a template that allows you to bypass these steps. You can download this template directly off of the Equis web site. Download this file to the Charts folder (e.g. C:\Program Files\Equis\MetaStock\Charts) in your MetaStock folder. Open any chart and then click on your right mouse button while the pointer is located on the chart. Choose Apply Template from the Chart Shortcut menu and choose the Rainbow Chart template. You should now have a chart with ten different coloured moving averages.

Next choose Indicator Builder from the Tools menu and enter the following formulas.

Rainbow Max
Max(Mov(C,2,S),
Max(Mov(Mov(C,2,S),2,S),
Max(Mov(Mov(Mov(C,2,S),2,S),2,S),
Max(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),
Max(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),
Max(Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S),
Max(Mov(Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S),2,S),
Max(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),
Max(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))))))))))
 
Rainbow Min
Min(Mov(C,2,S),
Min(Mov(Mov(C,2,S),2,S),
Min(Mov(Mov(Mov(C,2,S),2,S),2,S),
Min(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),
Min(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),
Min(Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S),
Min(Mov(Mov(Mov(Mov(Mov(Mov(Mov(C,2,S),2,S),2,S),2,S),2,S),2,S),2,S),
Min(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),
Min(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))))))))))
 
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))
 
Lower Rainbow Band
-100 * (Fml("Rainbow Max") - Fml("Rainbow Min")) /
(HHV(C,10) - LLV(C,10))
 
Upper Rainbow Band
100 * (Fml("Rainbow Max") - Fml("Rainbow Min")) /
(HHV(C,10) - LLV(C,10))

Plot the Rainbow Oscillator in a new inner window of your chart with the ten moving averages, by dropping the custom indicator from the QuickList onto the chart’s heading. Right click on the Rainbow Oscillator and choose properties, then change the Style to a histogram. Now plot the Lower Rainbow Band and the Upper Rainbow Band in the same inner window as the Rainbow Oscillator. If the scaling dialog appears when plotting these indicators, choose ‘Merge with Scale on Right.’ Change the colors of the Upper and Lower Rainbow Bands as desired. Now save this as a new template by choosing Save As from the File Menu and changing the File Type to template, so you can easily apply it to any chart.

(Go Top)

Regress Slope/Money Flow Index/Time Series Forecast

A series of four trading systems, using the Regress Slope as basis and combining with other indicators.

1. Regress Slope: Signal Formulas
Enter Long: 
 
Alert(RSquared(C,21) < 0.15,21) AND
LinRegSlope(C,34) > opt1 AND
HHV(LinRegSlope(C,34),5) =
HHV(LinRegSlope(C,34),13) AND
HHV(MFI(55),5) = HHV(MFI(55),13) AND
HHV(TSF(C,55),5) = HHV(TSF(C,55),13)
Close Long:  LLV(TSF(C,55),5) = LLV(TSF(C,55),13) AND
LinRegSlope(C,34) < opt1
Enter Short: 
 
Alert(RSquared(C,21) < 0.15,13) AND
LinRegSlope(C,34) < opt2 AND
LLV(LinRegSlope(C,34),5) =
LLV(LinRegSlope(C,34),13) AND
LLV(MFI(55),5) = LLV(MFI(55),13) AND
LLV(TSF(C,144),5) = LLV(TSF(C,144),13)
Close Short:  HHV(TSF(C,144),5) = HHV(TSF(C,144),13)
 
Optimization Variables
OPT1: Min = -0.10 Max = 0.00 Step = 0.10
OPT2: Min = -0.20 Max = 0.00 Step = 0.10
STOPS: ALL OFF

 
2. Regress Slope/CMO - All: Signal Formulas
Enter Long: 
 
Alert(RSquared(C,21) < 0.15,21) AND
LinRegSlope(C,34) > opt1 AND
HHV(LinRegSlope(C,34),5) =
HHV(LinRegSlope(C,34),13) AND
CMO(C,55) > 0 AND
C = HHV(C,5)
Close Long:  LinRegSlope(C,34) < opt1 AND
CMO(C,55) < 0 AND
C = LLV(C,5)
Enter Short: 
 
Alert(RSquared(C,21) < 0.15,13) AND
LinRegSlope(C,34) < opt2 AND
LLV(LinRegSlope(C,34),5) =
LLV(LinRegSlope(C,34),13) AND
CMO(C,55) < 0 AND
C = LLV(C,5)
Close Short:  LinRegSlope(C,34) > opt2 AND
CMO(C,55) > 0 AND
C = HHV(C,5)
 
Optimization Variables
OPT1: Min = -0.10 Max = 0.00 Step = 0.10
OPT2: Min = -0.20 Max = 0.00 Step = 0.10
STOPS: ALL OFF

 
3. Regress Slope/Qstick - (OHLC Rqd): Signal Formulas
Enter Long: 
 
Alert(RSquared(C,21) < 0.15,21) AND
LinRegSlope(C,34) > opt1 AND
HHV(LinRegSlope(C,34),5) =
HHV(LinRegSlope(C,34),13) AND
Qstick(55) > opt1 AND
HHV(Qstick(55),5) = HHV(Qstick(55),13)
AND C=HHV(C,5)
Close Long:  LinRegSlope(C,34) < opt1 AND
Qstick(55) < opt1 AND
C = LLV(C,5)
Enter Short: 
 
Alert(RSquared(C,21) < 0.15,13) AND
LinRegSlope(C,34) < opt2 AND
LLV(LinRegSlope(C,34),5) =
LLV(LinRegSlope(C,34),13) AND
Qstick(55) < opt2 AND
LLV(Qstick(55),5) = LLV(Qstick(55),13)
AND C = LLV(C,5)
Close Short:  LinRegSlope(C,34) > opt2 AND
Qstick(55) > opt2 AND
C = HHV(C,5)
 
Optimization Variables
OPT1: Min = -0.10 Max = 0.00 Step = 0.10
OPT2: Min = -0.10 Max = 0.00 Step = 0.10
STOPS: ALL OFF

 
4. Regress Slope/CCI/TSF - All: Signal Formulas
Enter Long: 
 
Alert(RSquared(C,21) < 0.15,21) AND
LinRegSlope(C,34) > opt1 AND
HHV(LinRegSlope(C,34),5) =
HHV(LinRegSlope(C,34),13) AND
HHV(CCI(55),5) = HHV(CCI(55),13) AND
CCI(55) > 0 AND
HHV(TSF(C,55),5) = HHV(TSF(C,55),13)
AND C = HHV(C,5)
Close Long:  LLV(TSF(C,55),5) = LLV(TSF(C,55),13) AND
LinRegSlope(C,34) < opt1 AND
CCI(55) < 0 AND
C = LLV(C,5)
Enter Short: 
 
Alert(RSquared(C,21) < 0.15,13) AND
LinRegSlope(C,34) < opt2 AND
LLV(LinRegSlope(C,34),5) =
LLV(LinRegSlope(C,34),13) AND
LLV(CCI(55),5) = LLV(CCI(55),13) AND
LLV(TSF(C,144),5) = LLV(TSF(C,144),13)
AND C = LLV(C,5)
Close Short:  HHV(TSF(C,144),5) = HHV(TSF(C,144),13) AND
C = HHV(C,5)
 
Optimization Variables
OPT1: Min = -0.10 Max = 0.00 Step = 0.10
OPT2: Min = -0.20 Max = 0.00 Step = 0.10
STOPS: ALL OFF

(Go Top)

RSI, sine-weighted smoothed

{ Smoothed RSI indicator v1.1 }{ Internal sine-weighted smoothing }{ Automatic historically-valid RSI peak/trough boundaries}{ Boundary crossover signals: +1=Long, -1=Short}{ ©Copyright 2004 Jose Silva }{ [email protected] }

{ user input }
pds:=1/Input("RSI periods",1,2520,10);
plot:=Input("plot:  [1]-RSI,  [2]-Long/Short signals",1,2,1);

{ RSI up/down average components }
x:=If(C>Ref(C,-1),C-Ref(C,-1),0);
y:=If(C<Ref(C,-1),Ref(C,-1)-C,0);
up:=PREV*(1-pds)+x*pds;
dw:=PREV*(1-pds)+y*pds;

{ sine-weighted internal smoothing }
s1:=Sin(30)*up;
s2:=Sin(60)*Ref(up,-1);
s3:=Sin(90)*Ref(up,-2);
s4:=Sin(60)*Ref(up,-3);
s5:=Sin(30)*Ref(up,-4);
up:=(s1+s2+s3+s4+s5)/(Sin(30)*2+Sin(60)*2
 +Sin(90));
S1:=Sin(30)*dw;
S2:=Sin(60)*Ref(dw,-1);
S3:=Sin(90)*Ref(dw,-2);
S4:=Sin(60)*Ref(dw,-3);
S5:=Sin(30)*Ref(dw,-4);
dw:=(s1+s2+s3+s4+s5)/(Sin(30)*2+Sin(60)*2
 +Sin(90));

{ RSI indicator }
dw:=If(dw=0,.000001,dw);
RS:=100-100/(1+up/dw);

{ automatic RSI peak/trough boundaries }
pk:=Ref(RS,-1)>Ref(RS,-2) AND Ref(RS,-1)>RS
 AND Alert(Ref(C,-1)>Ref(C,-2)
 AND Ref(C,-1)>C,2) {AND Ref(RS,-1)>50};
pkVal:=ValueWhen(1,pk,Ref(RS,-1));
pkAvg:=Cum(pkVal)/Cum(pkVal>-1);
tr:=Ref(RS,-1)<Ref(RS,-2) AND Ref(RS,-1)<RS
 AND Alert(Ref(C,-1)<Ref(C,-2)
 AND Ref(C,-1)<C,2) {AND Ref(RS,-1)<50};
trVal:=ValueWhen(1,tr,Ref(RS,-1));
trAvg:=Cum(trVal)/Cum(trVal>-1);

{ RSI peak/trough boundary cross signals }
up:=Cross(trAvg,RS);
dw:=Cross(RS,pkAvg);
signals:=up-dw;

{ alternative RSI peak/trough signals }
{up:=Ref(RS,-1)<Ref(RS,-2) AND Ref(RS,-1)<RS
 AND Ref(RS,-1)<trAvg;
dw:=Ref(RS,-1)>Ref(RS,-2) AND Ref(RS,-1)>RS
 AND Ref(RS,-1)>pkAvg;
signals:=up-dw;}

{ plot }
If(plot=1,pkAvg,0);
If(plot=1,trAvg,0);
If(plot=1,RS,signals)

(Go Top)

RSI - Stochastic-normalized

{ Stochastic-normalized RSI v1.0 }{ [email protected] }

pds1:=Input("RSI periods",2,252,21);
pds2:=Input("Stochastic periods",2,252,63);
x:=Input("use Open=1 High=2 Low=3 Close=4 Volume=5 P=6",1,6,4);
plot:=Input("plot Stoch-RSI=1, RSI=2, both=3",1,3,1);

x:=If(x=1,O,If(x=2,H,If(x=3,L,If(x=5,V,If(x=6,P,C)))));

Rs:=RSI(x,pds1);
{MetaStock versions earlier than v7.2, use:}
{Rs:=RSI(pds1);}

StochRsi:=(Rs-LLV(Rs,pds2))/
 (HHV(Rs,pds2)-LLV(Rs,pds2)+.000001)*100;

If(plot=3,Rs,50);
If(plot=2,Rs,StochRsi)
 

(Go Top)

Random trade generator

{ Random trade generator v2.5 }{ ©Copyright 2001-2004 Jose Silva }{ [email protected] }

{Download  Random.dll  from  http://www.traderhelp.net  and place in  MetaStock External Function DLLs folder}

{Plot indicator in its own window below price  chart & refresh screen to generate new trades}
{Buy signal: +1, Sell signal: -1}{Smaller signals: secondary buy/sell events}

{user input}
x:=Input("Frequency of random trades (0-100%)",
 0,100,10);
seed:=Input("Randomizer seed = 1~1000000,   none = 0",0,1000000,0)-1;

{trade generator engine}
y:=ExtFml("Random.Number",seed);
z:=(100-x)/2;
Buy:=y>50+z;
Sell:=y<50-z;

{trade organizer}
Init:=Cum(Buy+Sell>-1)=1;
BuyInit:=Cum(Buy)=1;
flag:=BarsSince(Init OR Buy)
 <BarsSince(Init OR Sell)+BuyInit;
signals:=(BuyInit AND Alert(BuyInit=0,2)
  OR flag AND Alert(flag=0,2))
   -(flag=0 AND Alert(flag,2));
BuySm:=Buy AND signals<1;
SellSm:=Sell AND signals>-1;

{signals display}
0;(BuySm-SellSm)*.3;signals

Random Strategy market test report

Market Trade $ Profit test for four random strategies, as at Close Fri 23/01/2004.

Tested on 475 ASX All Ords stocks; Avg test period: 8.25 years of data (2075 days); $10K starting capital for each stock; 1% Entry/Exit Slippage, $34 brokerage each way.

Buy & Hold: +$22,699 (+227%) avg profit per stock

Entry on Open of day one
Exit on Close of last day

Strategy 1: -$7,540 (-75.4%) avg profit per stock
==========
Random entry (10% of max signals) set at seed 1
Random exit (10% of max signals) set at seed 1

Exit 2: -$10,794 (-107.9%) avg profit per stock
======
Random entry (10% of max signals) set at seed 1
2% Trailing StopLoss exit

Exit 3: -$6,851 (-68.5%) avg profit per stock
======
Random entry (10% of max signals) set at seed 1
5% Trailing StopLoss exit

Exit 4: +$647 (+6.5%) avg profit per stock
======
Random entry (10% of max signals) set at seed 1
10% Trailing StopLoss exit

(Go Top)



If you have Metastock formulas you would like to share,
Please email to MetaStock Formula
We look forward to hearing from you!


To learn more about how to use Metastock and its formula click here.


copyright 2003 MetaStock Website Home
Metastock® is a registered trademark of Equis International.