Stock Market Tools (13) - Using Correlation as Pattern Recognition

The above slide shows the concept of correlation formula of two set of data.  In application wise, it can use for pattern recognition.  Such as image or voice recognition, etc.

In his latest book, "Cycle Analytics for Traders", John F. Ehlers even uses it to calculate the dominant cycle in the stock chart.

So, in broad term, Correlation can be used to find the similar patterns in stock market charts.
There are various usages:

* Such as using one index or ticker to confirm another - like Dow Jones Transport Index to confirm the bull or bear state of Dow Jones Industrial Average in the past (may be not so valuable now as internet age taken over, and many software products can be download online.)

* Find some current patterns that highly correlated with historical patterns, and use it for prediction that it will follow through in the short future.  - Such as head and shoulders, scourers, etc.

* Correlation of season in the year for commodity trading, etc...

* And, correlation would work for even more complex type of waveform, as it can use as the engine for image recognition algorithm...  And, here comes the story...

Well, I suddenly think of posting this article because, just a moment ago,  I come across another article - "SCARY PARALLEL" that could be of high interest to others and would like to see how it develops over the next few months.

The link of the original article is Here "Scary 1929 market chart gains traction".

From the chart patterns, though I don't have the access to the raw data to compute the correlation value, but experience would tell me that the correlation value would surely be higher than 0.8.  So, in theory wise, it has the Prediction Value until Proven Wrong!

On the other hand, when applying this concept...
This short video clip is an excellent example of illustrating the concept of pattern recognition - One can only confirm the actual answer after thing happen.

Will come back here in 2 months time to see the outcome. :-)

Bless you
KH Tang


Stock Market Tools (12) - A Better OBV and Time Segmented Money Flow

Part 1: A Better OBV

In the classical OBV (On-Balance Volume) indicator, it simply takes the idea from traditional tape reading - treat the "up tick" as Buy, "down tick" as Sell, and it assumes no change in price as neutral* (*which is not the case in tape reading).

When it comes to interpret the daily volume as such, errors will add up cumulatively.  For example, there are days when a Doji Star with high volume just merely one cent higher than yesterday price and the whole day volume would be taken as a BUY Volume....

Here is a gentlemen, William C. Garrett, attempted to break down the daily volume into two parts in his book - "Torque Analysis of Stock Market Cycle".   And, I think it makes sense.


William showed his method in Fig. 4.3 in his book, and we can derive the formula from it as follows:
He made the assumption that the trading volume is about linear over the trading hour, and thus it can derive how the paths the stock was traveled and workout the Buy Volume and Sell Volume accordingly as shown in the below chart:

Now a better OBV formula can be written as the cumulative number of  (Buy Volume - Sell Volume).
It should named as Garrett OBV.
And, it can multiply the daily average price to it and named as Garrett Money Flow.

The following chart shows the plot of it and the comparison to Classical OBV.

(Click on the Chart to Zoom in)

Part 2: Time Segmented Money Flow

There is a proprietary volume indicator known as Time Segmented Volume (TSV).  Since it is proprietary, probably the public would not know about the exact formula.  But the concept is not difficult.

Let say for the Classical way of plotting of OBV, there is no clear sign for both entry and exit.  We can then fix a look back period to compare it accumulation/distribution over it's own historical value.  One simple way is to perform a MACD operation on the Garrett Money Flow.  

Now we can compare the Garrett Money Flow Indicator to the Classic MACD indicator.  In the above chart, they are using the same look back period for short MA, long MA and Signal.
From the chart, there are some very interesting point to take note.
Since the Volume Action is taken into account in this new indicator together with price.  The Time Segmented Money Flow behave differently at couple of  place on the above chart.
For examples:  On March, April and July, the RED Line maintain above the Zero line to prevent any short trades - this happened as a result of  more Buying Volume than Selling Volume.

Note on Divergence:
When using a indicator as Time Segmented Money Flow, divergence would surely occur on and off.  This is where Wyckoff 3rd principle comes into play - "Effort vs Result" that is not matching.  Meaning that the cumulation of shares goes in one direction while the price goes another direction.

"It ain't what you don't know that gets you 
into trouble.  It's what you know 
for sure that just ain't so." 
- Mark Twain

Attached is the AFL formula:

//  Formula Name  : OGTS Time Segmented Money Flow
//  Author        : KH Tang
//  Company       : Wealth Resonance
//  Last Update   : 15 Jan 2014
//  Date Updated  : 22 Nov 2013 // Update with opening price as direction*
//  Origin date   : 5 Jun 2007
//  Origin        : KH Tang
//  Version       : 1.01
//  Level         : Volume Analysis
//  Description   : Key Usages:
//                : 1.Tape Reading for Direction of Breakout in Trading Range
//                : 2.Tape Reading for Divergence in Trending
//        : Note: Enhancement to include Opening price as direction.
procedure BackgroundSetting()
SetChartBkGradientFill( ParamColor("BackgroundTop", colorSkyblue),
        ParamColor("BackgroudBottom", colorWhite),ParamColor("TitleBlock",colorWhite));
SetBarsRequired( -2, -2 );
_SECTION_BEGIN("Display Setting");
GraphXSpace = 10;
_SECTION_END();//Display Setting
//William C. Garrett's Approximation:
//GPaths   = IIf(C>Ref(C,-1),((H-Ref(C,-1))+(H-L)+(C-L)),IIf(C
//GUpShare = IIf(C>Ref(C,-1),((H-Ref(C,-1))+(C-L)),IIf(C
//GDnShare = IIf(C>Ref(C,-1),(H-L),IIf(C
//Expansion for clarity:
PathA1= Ref(C,-1)-L;
PathB1= H-L;
PathC1= H-C;
Path1 = PathA1+PathB1+PathC1;
UpShare1 = PathB1;
DnShare1 = PathA1+PathC1;
PathA2= H-Ref(C,-1);
PathB2= H-L;
PathC2= C-L;
Path2 = PathA2+PathB2+PathC2;
UpShare2 = PathA2+PathC2;
DnShare2 = PathB2;
Paths  = IIf(C<Ref(C,-1),Path1,    IIf(C>Ref(C,-1),Path2,   1));
UpShare= IIf(C<Ref(C,-1),UpShare1,IIf(C>Ref(C,-1),UpShare2,0));
DnShare= IIf(C<Ref(C,-1),DnShare1,IIf(C>Ref(C,-1),DnShare2,0));
FlowFactor = Avg;
FlowIn  = UpShare/Paths*Volume*FlowFactor;
FlowOut = DnShare/Paths*Volume*FlowFactor;
NetFlow = FlowIn - FlowOut;
TotalFlow = Cum(NetFlow );
PlotType = ParamList("Type of Chart Plotting:","Cumulative|Time Segmented",1);
LBP = Param("LBP for Time Segmented Plot",26,10,50,1);
FastSmoothMF     = EMA(TotalFlow,int(LBP/2));
SlowSmoothMF   = EMA(TotalFlow,LBP);
DailyNetFlow= IIf(NetFlow==0,MA(Netflow,30),NetFlow);
    Plot(TotalFlow ,"Garrett Money Flow",colorRed,styleThick);
else if (PlotType=="Time Segmented")
    TSMF=FastSmoothMF - SlowSmoothMF;
    Plot(TSMF,"Time Segmented Money Flow",colorRed,styleThick);
    TSMFsig = EMA(TSMF,9);
    Histogram = TSMF-TSMFSig;