CwHDLL User’s Guide

Copyright © Haiku Laboratories 2010

Updated June, 2010

 

Introduction

Installation

DLL Usage

Function Output

Disclaimer

 

 

INTRODUCTION

The CwHDLL is a dynamic-link library containing a single C function, CwHScan, which implements the Cup-With-Handle search algorithm described in the references:

 

 

The algorithm uses the highs, lows, closes and volumes for 252 consecutive days of a given input stock.  It searches the data and returns the number of CwH patterns found, or, if none are found, the criteria the data did not meet.  If a pattern is found, it also returns the structure’s geometry, its Rank, pivot value (to distinguish high vs low handles) and other information. If a pattern cannot be found, a negative value is returned which indicates the reason the data was rejected.  Negative return values are detailed here. 

 

INSTALLATION

The installation package is downloaded as CwHsetup.zip, which contains the CwHsetup.exe installer.  Running CwHsetup.exe creates the folder C:\Program Files\HaikuLabs\ and installs the Excel spreadsheet Cwh_Demo12.xls.  It also creates sub-folders and installs CwhDll.dll and some test data to their default locations:

 

Filename

Default Location

CwhDll.dll

C:\Program Files\HaikuLabs\DLLs\

Cwh_Demo12.xls

C:\Program Files\HaikuLabs\

Test.csv

C:\Program Files\HaikuLabs\Data\

Table 1.  Package files and their default locations.

 

An icon for the spreadsheet is placed on the desktop, and under Start | Programs | CwH_Demo, along with an Uninstaller.  Here Test.csv refers to one or more test data files used by the spreadsheet. These csv files contain stock data in Yahoo format. To obtain more data, go to Yahoo Finance and download 252 days of any stock. Name the file by its symbol and store it in the same folder as test.csv.  Alternatively, automated downloaders are available from Haiku Labs.

 

DLL USAGE

The spreadsheet contains complete VBA code demonstrating the calling procedure for the DLL function.  The following is an outline in pseudo-code.  The VBA function declaration is 

 

Public Declare Function CwHScan Lib " C:\Program Files\HaikuLabs\DLLs\CwHDll.dll"

          (ByVal Npts As Integer, ByRef high As Double, ByRef low As Double, ByRef close As Double, ByRef volume As Double,

                   ByRef OutP As Double) As Integer

 

where the function name is shown in blue and the function arguments in green for inputs, and orange for outputs.  Argument definitions are given in the next section.  Note that the default path is: C:\Program Files\HaikuLabs\DLLs\ and should not be modified unless the DLL is moved.  Your code needs the following components:

 

‘Input variables, the stock’s prices, volumes and dates

          Dim Clos(255) as Double                ‘ Closing prices

          Dim High(255) as Double                ‘ Highs

          Dim Low(255) as Double                ‘ lows

          Dim Vol(255) as Double                 ‘ volume

          Dim CloseDate(255) as Double        ‘ Closing dates(optional)

         

          Const Npts As Integer= 252           ‘ number of data points, one trade-year

 

‘Output variables

          Dim status As Integer                   ‘holds the function’s return value

          Dim OutP(50) As Double                ‘function output vector

 

 

'A data-input function; inputs are Symbol and Npts; outputs are the price vectors, the volume and the date vector. Return ststus is false if there is a failure to read the data file. (The complete VBA function is available in the spreadsheet.)

         

          Dim Symbol As String

          Symbol = “IBM”                             ‘for example

 

          status = Get_Data(Symbol, Npts, closedate, high, low, clos, vol)

 

'Function CwHScan; inputs are  prices and volume; status of the data returned; and details returned in the OutP vector.

 

          status = CwHScan(Npts, high(0), low(0), clos(0), vol(0), OutP(0))

 

          Debug.print  CloseDate(OutP(1))     ‘this displays the last date in VBA date format,

 

 

FUNCTION OUTPUT

The function returns an integer, called status above.  If positive it indicates the number of CwH patterns found; if negative it is a rejection code (see details here).  The function also outputs a vector (dimensioned double) containing numeric information about its search for the CwH pattern.  The first 10 entries are allocated for the pattern itself; the first five are integers indicating the slot numbers of the points A, B, C, D and K (see reference 3 above) and the second five hold their respective prices.  Slot 11 holds the same return code as status – note that if this code is not positive, then many of the vector’s entries will be empty.  The patterns Rank and its components are in slots 14-17, and the pivot ratio is in 18.  Slots 19-22 hold the lengths of the pattern’s frames.  The complete vector is as follows:

 

         

          OutP(1) = Point D

          OutP(2) = Point C

          OutP(3) = Point B

          OutP(4) = Point A

          OutP(5) = Point K

          OutP(6) = PtD price

          OutP(7) = PtC price

          OutP(8) = PtB price

          OutP(9) = PtA price

          OutP(10) = PtK price

          OutP(11) = Return code = status

'         OutP(12) = last close

          OutP(13) = last volume

          OutP(14) = Rank

          OutP(15) = R1

          OutP(16) = R2

          OutP(17) = R3

          OutP(18) = Pivot ratio

          OutP(19) = left-side length  K-A

          OutP(20) = rite side length B-C

          OutP(21) = handle length D-C

          OutP(22) = cup+handle length A-D

 

 

DISCLAIMER - This product is only intended as a tool in a market-trader’s arsenal of software products.  There are no claims made as to the ultimate performance of the market items selected using this product.