Selected Article
Home Cart 0

Selected Article

Minimizing risk in trading


by Tim Straiton

Paul Tudor Jones, the legendary trader stated that financial markets trend only 15 percent of the time. The rest of the time they move sideways. When markets are in a trendless or sideways state, they become choppy and more difficult to predict.

Technical analysis offers numerous indicators which are valuable in making us aware of the market trend state. We will be looking at four technical indicators available in Metastock which are useful in evaluating trend direction and trend strength.

  • The R-Squared Indicator

  • The Linear Regression Slope

  • The Choppiness Index

  • The Directional Movement Index

The R-Squared Indicator

The r-squared indicator shows the strength of a trend.It is based on linear regression outputs. The more prices move in a linear relationship over time, the stronger is the trend. In the chart above the R-squared indicator is coloured green where a clear trend is existent. It is coloured red when a trend begins to lose direction.

Metastock Code for the r-squared indicator:

pds:=Input("Enter the number of periods;",1,600,14);
Sig:=Pwr(Corr(Cum(1),C,pds,0),2);
Green:=If(Sig>Ref(Sig,-1),Sig,0);
Red:=If(Sig<Ref(Sig,-1),Sig,0);Green;Red

 

The Linear Regression Slope

The linear regression slope is a trend-identifying and trend-following indicator. The major trend is identified by calculating a linear regression trendline with the use of the least squares fit method, which helps to minimize the distance between the data points and the linear regression trendline. It has less lag than the moving average and reacts more rapidly to price changes.   

Metastock Code for the linear regression slope indicator

pds:=Input("Time Periods",1,200,21);
((pds*(Sum(Cum(1)*C,pds)))-(Sum(Cum(1),pds)*(Sum(C,pds))))/((pds*Sum(Pwr(Cum(1),2),pds))-Pwr(Sum(Cum(1),pds),2))

 

The Choppiness Index

The choppiness index is used to determine trend strength in a market. If the indicator is above 62%, then the stock is experiencing a choppy trend; however, if the reading is below 38 the stock is beginning to trend. This means that the closer you are to 100, the choppier the market and the closer to 0, the more powerful the trend.

Metastock Code for the Choppiness Index
hlvl:=Input("Select High Level :",55,80,62);
llvl:=Input("Select Low Level :",20,40,38);
sig:=((Log(Sum(ATR(1),14) / (HHV(If(H,>=,Ref(C,-1),H,Ref(C,-1)),14) -
LLV(If(L,<=,Ref(C,-1),L,Ref(C,-1)),14))) / Log(10))/(Log(14)/Log(10))) * 100;
sig;hlvl;llvl;50


 

 

Directional Movement Index

The Directional Movement Index has a value between 0 and 100 and is used to measure the strength of the current trend. +DI and -DI are then used to measure the trend direction. If the ADX is above 25 a strong trend is present and  when the +DI is above the -DI, then a bullish market is defined. When -DI is above +DI, this suggests that a bear market in is place.

 

Metastock Code for the Directional Movement Index

Periods:=Input("Time Periods",1,100,14);
PlusDM:=If(H>Ref(H,-1) AND L>=Ref(L,-1), H-Ref(H,-1),If(H >Ref(H,-1) AND L AND H-Ref(H,-1)>
Ref(L,-1)-L, H-Ref(H,-1),0));
PlusDI:=100*Wilders(PlusDM,Periods)/ATR(Periods);
MinusDM:=If(LRef(H,-1) AND L AND H-Ref(H,-1) MinusDI:=100*Wilders(MinusDM,Periods)/ATR(Periods);
DIDif:=Abs(PlusDI-MinusDI);
DISum:=PlusDI+MinusDI;
ADXFinal:=100*Wilders(DIDif/DISum,Periods);
ADXFinal

 

Metastock Code for the Plus Directional Movement Index

Periods:=Input("Enter time periods",1,100,14);
PlusDM:=If(H>Ref(H,-1) AND L>=Ref(L,-1),H-Ref(H,-1),
If(H>Ref(H,-1) AND L AND H-Ref(H,-1)>Ref(L,-1)-L,H-Ref(H,-1),0));
DIPlus:=100*Wilders(PlusDM,Periods)/ATR(Periods);
DIPlus;

 

Metastock Code for the Minus Directional Movement Index

Periods:=Input("Enter time periods",1,100,14);
MinusDM:=If(L If(H>Ref(H,-1) AND L AND H-Ref(H,-1) DIMinus:=100*Wilders(MinusDM,Periods)/ATR(Periods);
DIMinus;

Take a look at the chart and focus on the yellow vertical line. Note the position of the choppiness index, the r-squared indicator and the minus directional index and you will see why these indicators used together will assist in assessing trend quality and trend direction in your market analysis.