PureBytes Links
Trading Reference Links
|
See an old mail printed below on the Divergence subject, eg with in it the
Equis website's section on the
"Divergence between the Close and an Indicator" (Rev. 03/18/97)
that uses the Correlation method in the Custom Indicator example given, eg
by referencing the function Correl().
Also, now from the man/p.222 (and Help):
Correlation Analysis
SYNTAX correl( INDEPENDENT, DEPENDENT,PERIODS, SHIFT)
FUNCTION Calculates the predefined Correlation indicator.
Compares the correlation of DEPENDENT to INDEPENDENT
over PERIODS time periods, after shifting DEPENDENT to the
right SHIFT-periods.
EXAMPLE The formula "correl( macd(), CLOSE, 5, 10 )" compares the MACD
indicator to the closing price 10-periods in the future, after statistically
averaging each data array over the preceding 5-periods.
For more on Correlation see its section also printed further below.
Regards,
Ton Maas
ms-irb@xxxxxxxxxxxxx
Dismiss the ".nospam" bit (including the dot) when replying.
----- Original Message -----
From: Laurent GITTLER
To: 'Metastock@xxxxxxxxxxxxx' <metastock@xxxxxxxxxxxxx>
Sent: maandag 7 juni 1999 12:17
Subject: Formula to identify a divergence with an indicator
> I would like to make an explorer with Metastock getting divergence between a
> chart price and an indicator, like MACD.
>
> I would like to detect all securities where this divergence appeared in the
> last 3 days.
>
> I wonder how to do this in Metastock.
>
> My problems are :
>
> 1) How to identify the latest valley on price (number of bars since)
>
> 2) How to identify the valley before the latest one on price (number of bars
> since).
>
> 3) Then I would apply the ROC % on both price and indicators and deduce
> diffrent cases to see if there is a positive or negative divergence of more
> than x %.
>
> Has anybody done this before and has a formula for this ?
>
> Thank you
>
> Laurent Gittler
>
>
===============================================
===============================================
The old mail:
------------------
>Just wondering if anyone has a way to scan for divergence in an exploration.
>I am trying to scan for divergence between price and an indicator eg.
>stochastics.
>
>For example, compare the values of the current price and previous low/high
>and and current stochastics and stochastics at the time of the previous
>high/low in the price.
>
>Any help with the formula for this would be much apreciated. Thanks
Creating an Exploration = p. 347 MSv65-manual
Current price = C
Previous HIGH = Ref(H,-1)
Previous Low = Ref(L,-1)
Stochastics = Stoch(5,3)
Previous Stoch = Ref(Stoch(5,3),-1)
Divergence example = see below(old mail)
Correlation Analysis = see below
Divergence Indicator = see below
Regression Oscillator - Richard Goedde = see below
Slope/Close Indicator - Richard Goedde = see below
RO+SC Explorations - Richard Goedde = see below
Regards,
Ton Maas
===================================================
Divergence example(old mail)
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)
Substitute any formula for the "RSI(9)"
i am using this in the explorer.
Mike Arnoldi
===================================================
Correlation Analysis
Correlation analysis measures the inter-relationship between two variables. The output
of this measurement is called the 'correlation coefficient'. A correlation coefficient will
ranges between ±1.0. A correlation coefficient of +1.0 is a perfect positive correlation.
A correlation coefficient of -1.0 is a perfect negative correlation.
The inputs are variables. There may be two or more variables. If there is no relationship
between the variables they will have a correlation coefficient of zero.
Correlation analysis involves a "dependent" and an "independent" variable. Correlation
analysis measures whether or not a change in the independent variable will result in a
change in the dependent variable.
With correlation analysis there is always one "dependent" variable. There may be one
or more 'independent' variables. The dependent variable is always the security's price.
The independent variable can be an indicator or one or more securities.
When a technician is using correlation analysis, he is measuring the degree to which
a change in the independent variable will result in a change in the dependent variable.
A low correlation coefficient (e.g., ±0.10) suggests that the relationship between the two
variables is weak or non-existent. A high correlation coefficient (e.g., ±0.85) indicates
that the dependent variable (e.g., the security's price) will change when the independent
variable (e.g., an indicator) changes.
The direction of the dependent variable's change depends on the sign of the coefficient.
If the coefficient is a positive number, then the dependent variable will move in the same
direction as the independent variable; if the coefficient is negative, then the dependent
variable will move in the opposite direction of the independent variable.
A useful feature of correlation analysis is its predictive capability, because the
correlation coefficient shows how well a change in the independent variable
(e.g., an indicator) predicts a change in the dependent variable (e.g., the security's price).
Many technicians will forward shift periods. The independent variable, which might
be an indicator, will be shifted forward x period of time. One might shift the
independent variable forward 7 days to see if there is in fact any predictive power
in the indicator. Any time period can be used.
When one uses this method of technical analysis, it is very important to not only
back-test the method, but to also forward-test this method without putting any money
on the trades.
Keep in mind that the trader may encounter a very low correlation such as -.85. If this
occurs the security's price will move in the opposite direction. It is also a very strong
indication and can be used to successfully trade. One will also notice that certain
securities tend to lead other securities or will move in opposite directions.
The Correlation indicator can be used in two ways:
· Correlation of a security's price to an indicator
You can measure the relationship between an indicator and a security's price. A high
positive correlation coefficient means that a change in the indicator usually predicts a
change in the security's price. A high negative correlation (e.g., -0.70) means that when
the indicator's value changes, the security's price will usually move in the opposite
direction. Remember, a low (e.g., 0.10) correlation coefficient indicates that the
relationship between the security's price and the indicator is not significant.
· Correlation of one security to another
Another use of correlation analysis is to measure the strength of a relationship between
two securities. Often, one security's price "leads" or predicts the price of another
security. This is especially noticeable with commodities. For example, the correlation
coefficient of gold versus the dollar shows a strong negative relationship. In other words,
an increase in the dollar usually predicts a decrease in the price of gold.
· Correlation of one indicator to another
Another use of correlation analysis is to measure the strength of a relationship between
two indicators. Often, one indicator's movement "leads" or predicts the movement of
another indicator. For example, a volume-based indicator (i.e., Chaikin Oscillator,
Money Flow Index, etc.) may be found to lead a momentum based indicator
(i.e., RSI, Stochastic, etc.).
SYNTAX correl( INDEPENDENT, DEPENDENT,PERIODS, SHIFT)
FUNCTION Calculates the predefined Correlation indicator. Compares the correlation
of DEPENDENT to INDEPENDENT over PERIODS time periods, after
shifting DEPENDENT to the right SHIFT-periods.
EXAMPLE The formula "correl( macd(), CLOSE, 5, 10 )" compares the MACD indicator
to the closing price 10-periods in the future, after statistically averaging each
data array over the preceding 5-periods.
SEE ALSO The stdev() function (see Standard Deviation).
====================================================
Divergence between the Close and an Indicator
Rev. 03/18/97
The following formula will calculate the correlation of the Close and the
MACD. It is written using a "long form" MACD
so that the time periods used by the MACD may be changed. This indicator
shows "divergence" between the close and the indicator:
In the Windows versions of MetaStock the formula is:
Correl(((Sum(Cum(1)*(Mov(C,12,E)-Mov(C,26,E)),100))-(Sum(Cum(1),100)*
Sum((Mov(C,12,E)-Mov(C,26,E)),100)/100))/((Sum(Power(Cum(1),2),100))-
(Power(Sum(Cum(1),100),2)/100)),((Sum(Cum(1)*C,100))-(Sum(Cum(1),100)*
Sum(C,100)/100))/((Sum(Power(Cum(1),2),100))-(Power(Sum(Cum(1),100),2)/100)),12,0)
The interpretation of the indicator output is as follows:
- .08 (80%) and lower is divergence between the Close and the MACD.
- 1 is very strong divergence.
+ 1 is very strong correlation.
The formula was constructed this way so that most other indicators may be
used in place of the MACD.
For example here is the same indicator using the RSI(14):
Correl(((Sum(Cum(1)*(RSI(14)),100))-(Sum(Cum(1),100)*
Sum((RSI(14)),100)/100))/((Sum(Power(Cum(1),2),100))-(Power(Sum(Cum(1),100),2)/100)),
((Sum(Cum(1)*C,100))-(Sum(Cum(1),100)*Sum(C,100)/100))/((Sum(Power(Cum(1),2),100))-
(Power(Sum(Cum(1),100),2)/100)),12,0)
================================================
Standard Deviation
Standard Deviation is a statistical measurement of volatility. It is derived by calculating
an x-time period simple moving average of the data item (i.e., the closing price or an
indicator); summing the squares of the difference between the data item and its moving
average over each of the preceding x-time periods; dividing this sum by x; and then
calculating the square root of this result.
Interpretation
Standard Deviation is typically used as a component of an indicator, rather than as a
stand-alone indicator. For example, Bollinger Bands (see Bollinger Bands) are
calculated by adding a security's Standard Deviation to a moving average.
High Standard Deviation values signify high volatility: the data item being analyzed is
deviating from its moving average significantly. Similarly, low Standard Deviation
values signify low volatility; the data item is remaining close to its moving average.
Typically, low Standard Deviation values (i.e., low volatility) tend to come before
significant upward price changes. Many analysts agree that major tops are normally
accompanied with high volatility and major bottoms are generally calm with low volatility.
Parameters
The parameters for the predivined Standard Deviation indicator are shown below.
These parameters are specified at the time the indicator is plotted. You can edit
the parameters of an existing plot by right-clicking on the indicator and choosing
Properties from the shortcut menu.
Time Periods. Enter the number of time periods to use when calculating the Standard
Deviation. The term "time periods" refers to days if the chart contains
daily data, weeks for weekly data, etc.
Deviations. Enter the number of standard deviations by which to shift the plot upward.
Price Field. Choose the price field (i.e., open, high, low, or close) to use when
calculating the Standard Deviation.
SYNTAX stdev( DATA ARRAY, PERIODS )
FUNCTION Calculates the predefined Standard Deviation indicator.
EXAMPLE stdev( CLOSE, 21 )
Custom indicator
A 4-period Standard Deviation indicator can be written as follows. The first
statement assigns a 4-period simple moving average to the variable named
"4PeriodMA". The second statement sums the squares of the differences
between the moving average and the closing prices on each of the preceding
four periods. It then calculates the square root of this total.
4PeriodMA:= mov( close, 4, S );
sqrt(( power(4PeriodMA) - C, 2) +
power(fml(4PeriodMA)- ref(C,-1), 2) +
power(fml(4PeriodMA)- ref(C,-2), 2) +
power(fml(4PeriodMA)- ref(C,-3), 2) ) / 4 )
An easier method is to take the square root of the variance function as
shown below:
sqrt( var( close, 4 ) )
Of course, the easiest way is to write the Standard Deviation formula using the
predefined stdev() function (see above Standard Deviation).
================================================
Regression Oscillator and the 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
=====================================================
|