Metastock Developer Kit

Published on March 2017 | Categories: Documents | Downloads: 188 | Comments: 0 | Views: 827
of 51
Download PDF   Embed   Report

Comments

Content

MetaStock

 ® 

 Developer’s Kit For MetaStock Solution Providers Vers Version ion 9.1 9.1

Printed in the USA  All Rights Reserved Copyright © 1985-2005

Equis International 90 South 400 West Suite 620 Salt Lake City, UT USA 84101 http://www.equis.com

The MetaStock Developer’s Kit (“Software”) and accompanying documentation (“MetaStock Developer’s Kit User's Manual”) are licensed, not sold, to you. By opening the sealed package and/or using the Software, you indicate your acceptance of the Equis Software License Agreement that is included with the original package. The DownLoader and Smart Charts are trademarks of Equis International. Equis and MetaStock are registered trademarks of Equis International. Microsoft, MS-DOS, Windows, Windows NT, Win32, Visual C++, Developer Studio, and Visual Basic are trademarks of Microsoft Corporation. Borland is a registered trademark of Inprise Corporation. Delphi is a trademark of Inprise Corporation. PowerBASIC is a registered trademark of PowerBASIC, Inc. Except as permitted by law, no part of this document may be reproduced or transmitted by any process or  means without the prior written consent of Equis International (Equis). Equis, by publishing this document, does not guarantee that any information contained herein is and will remain accurate or that use of the information will ensure correct and faultless operation of the relevant product or service. Equis provides its products and services as tools to be used by investors who are aware of the risk inherent in securities trading, not as recommendations to buy or sell. Equis, its agents, affiliates, and employees shall not be held liable to or through any user for any loss or damage whatsoever resulting from reliance on the information contained within this document or through the use of Equis products or services.

9/23/05

9

8

7

6

5

4

3

2

1

IP

Table of Contents Introduction

1

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Typography Conventions Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 System Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Supported Compilers Compilers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Installed Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Modifying the MetaStock User Interface

5

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 Using the EqCustUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7 Command Line Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12 . 12 Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12 . 12

Formula Organizer Enhancements

13

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13 Using the Formula Organizer Organizer to Export . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Using the Self-extracting Self-extracting Installation File File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

DDE Data Interface

17

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17 . 17 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18 Running EqDdeSrv.exe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18 . 18 System Topic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20 Microsoft Excel Example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Simple C Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Suggested Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24 . 24

MetaStock External Functions (MSX)

25

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25 MSX DLL Capabilities Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25 . 25 Getting Assistance Assistance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Function Prototype Prototype Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27 Initialization Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27 Calculation Functions Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31

MetaStock ® 

Tabl Table e of Cont Conten ents ts • i

Variable Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Initialization Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Calculation Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Function Argument structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Creating an MSX DLL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Microsoft Visual C++ 4.x, 5.0, and 6.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Borland C++ Builder 4.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Borland C++ 5.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Borland Delphi 3.0, 4.0, and 5.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 PowerBASIC/DLL 6.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44  Naming your DLL and Calculation Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Debugging Your MSX DLL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 General Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Microsoft Visual C++ 4.x, 5.0, and 6.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Borland C++ Builder 4.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Borland C++ 5.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Borland Delphi 3.0, 4.0, and 5.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 PowerBASIC/DLL 6.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Testing Your DLL With MSXTest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Stress Testing Your DLL Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Automating MSXTest From Your IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Testing Your DLL With MetaStock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Programming Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Data Storage and Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Things to Remember . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 User Interface Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Tech Note 1 – Using MSFL in an MSX DLL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 MSX Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

Sample DLL Programs

63

“C” Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Delphi Pascal Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 PowerBASIC/DLL Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

MetaStock File Library (MSFL)

75

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 What’s New . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Application Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Visual Basic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Delphi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 PowerBASIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Securities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Price Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Composites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Multi-user Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Reserved File Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

ii • Table of Contents

MetaStock ® 

CD-ROM Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .79 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .79 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Variable Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .81 Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Using the Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Directory Opening . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Security Locking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .87 Data Assumptions and Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88 Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88 Return Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88 Listed By Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Listed By Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Messages and Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131 Error Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131 Message Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .136 Change Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 MSFL Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .139

Index

MetaStock ® 

141

Table of Contents • iii

iv • Table of Contents

MetaStock ® 

Introduction

Overview The MetaStock ® Developer’s Kit includes applications and documentation for tools used to customize MetaStock and access MetaStock data. The Equis® Custom User Interface Utility  allows developers to add their own commands to the MetaStock Custom Toolbar, Tools menu and Help menu. The MetaStock Formula Organizer Enhancements  are installed with this toolkit. Documentation for these enhancements is included in this manual. The DDE Server is provided with MetaStock Professional (versions 7.0 and later), and MetaStock FX. Full documentation for this feature is included in this manual. The MetaStock External Function (MSX) Application Programming Interface (API) allows software developers to dynamically add externally defined functions to the MetaStock Formula Language. These functions can be called from Custom Indicators, Explorations, System Tests, and Experts. This feature is available in MetaStock, MetaStock Professional (versions 7.0 and later), as well as MetaStock FX. The MetaStock  File Library (MSFL) Application Programming Interface (API)  provides developers with the tools necessary to integrate applications with the MetaStock data format. This manual contains the instructions necessary to implement each of these applications. It assumes that the developer is an experienced programmer familiar with security price data and with creating and calling dynamic link libraries.

MetaStock ® 

Introduction • 1

Commands Toolbar.Add  Tool bar . Add( <Command>, <Ti p>[ , <Par amet er s>] ) Parameters

Command  Specifies the action to be associated with the new button. Any syntax that > Run) can be can be specified in the Windows “Run” dialog ( specified here. This includes executable files, internet URLs, and documents that are associated with a valid program on the system.

Tip

Specifies the status bar prompt and tooltip that will be associated with the new button. The pipe character ( | ) can be used to specify separate strings for the status bar prompt and the tooltip. In this case, the format of this parameter is "st at us bar prompt st r i ng"| "t ool t i p st r i ng". If this parameter does not contain the pipe character then the same string will be used for both the status bar prompt and the tooltip.

Parameters Specifies the parameter list that will be passed to the executable file when the user selects the new toolbar button. The [ and ] characters specify that this parameter is optional. These characters should not be used literally on the EqCustUI utility command line. For example,  Tool bar . Add( <Command>, <Ti p>[ , <Par amet er s>] )  can be interpreted as Tool bar . Add( <Command>, <Ti p>)  or  Tool bar . Add( <Command>, <Ti p>, <Par amet er s>) . Either method is valid.

Remarks • This adds a button to the MetaStock Custom toolbar. • The EqCustUI utility always adds the button to the MetaStock toolbar using the icon associated with Command . • There is no method for the developer to specify another icon to use, or to specify the order in which the button is placed on the custom toolbar. Note: This command does not modify existing buttons as duplicates are ignored. To modify a  button the developer must first delete it and then add it back in with the appropriate changes.

Example EqCust UI " Tool bar . Add( www. mycompany. com, Br owse our web si t e| mycompany. com) " Or  EqCust UI " Tool bar. Add( dl wi n. exe, Expr ess downl oad, / expr ess) "

MetaStock ® 

Modifying the MetaStock User Interface • 7

Toolbar.Delete  Tool bar . Del et e( <Command>) Parameters

Command  Specifies the action (executable file, internet URL, document, etc.) that is associated with the button to delete.

Remarks • This removes a button from the MetaStock Custom toolbar. • The toolbar is searched until a button is found that is associated with this file. • If a button is found it will be deleted. IMPORTANT: Third-party developers should only delete the buttons they have created on the Custom toolbar. A third-party developer should never  delete another developer's button on the toolbar. Doing so is a violation of the license agreement.

Example EqCust UI " Tool bar. Del et e( www. mycompany. com) "

Menu.AddItem Menu. AddI t em( <Locat i on>, <Menu>, <Command>) Parameters

Location

Specifies the placement of the new menu item. Please note that MetaStock uses two different and distinct menus. The first menu (Main) is used when a chart is not  opened on the screen, whereas the second menu (Chart) is used when a chart is opened on the screen. For this reason menu items must be added to both the Main menu and the Chart menu to be visible at all times. The following are the different locations available. Placement

Location (The menu is located: )

 Main-Tools

On the Tools menu when no chart is opened.

 Main-Help

On the Help menu when no chart is opened.

Chart-Tools

On the Tools menu when a chart is opened.

Chart-Help

On the Help menu when a chart is opened.

 Menu Specifies the string to be placed on the menu. Command  Specifies the action that is associated with this menu item. Any syntax that > Run) can be specified can be specified in the Windows run dialog ( here. This includes executable files, internet URLs, and documents that are associated with a valid program on the system.

MetaStock supports several predefined literals that have special meaning. These literals will be replaced with the appropriate value when the user selects the menu item. The greater-than and less-than (< >) characters must be included.

8 • Modifying the MetaStock User Interface

MetaStock ® 

The following are the literals supported by MetaStock. Literal

Description

<symbol>

This literal is replaced with the symbol name of the security on the active chart. This literal is only valid when a chart is opened in MetaStock . Therefore, the Location parameter must be Chart-Tools or Chart-Help.

<name>

This literal is replaced with the actual name of the security on the active chart. This literal is only valid when a chart is opened in MetaStock . Therefore, the Location parameter must be Chart-Tools or Chart-Help.

<periodicity>

This literal is replaced with the periodicity of the security on the active chart. Please note that this is the periodicity of the underlying security as it was created with the MSFL, not the current periodicity that the user has compressed to. Valid values for this literal are Intraday, Daily, Weekly,  Monthly, Quarterly, and Yearly. This literal is only valid when a chart is opened in MetaStock . Therefore, the  Location parameter must be Chart-Tools or Chart-Help.

Remarks • Adds a menu item to the reserved section of either the MetaStock Tools menu or the MetaStock Help menu. • As of this writing, the reserved section on the Tools menu is directly above Default colors and styles, whereas on the Help menu it is directly above  About MetaStock. The reserved sections are subject to change at any time. • There is no method for the developer to specify the order in which the menu item is  placed in the specified reserved section. • MetaStock must be restarted for menu modifications to take effect. Note: This command does not modify existing menu items. To modify a menu item the developer must first delete it and then add it back in with the appropriate changes.

Example EqCust UI " Menu. AddI t em( Mai n- Hel p, My company on t he web, www. mycompany. com) "

Menu.DeleteItem Menu. Del et eI t em( <Loc at i on>, <Menu>, <Command>) Parameters

Location

Specifies the placement of the menu item. Please note that MetaStock uses two different and distinct menus. The first menu (Main) is used when a chart is not  opened on the screen, whereas the second menu (Chart) is used when a chart is opened on the screen. The following are the different locations available. Placement

MetaStock ® 

Location (The menu is located: )

 Main-Tools

On the Tools menu when no chart is opened.

 Main-Help

On the Help menu when no chart is opened.

Chart-Tools

On the Tools menu when a chart is opened.

Chart-Help

On the Help menu when a chart is opened.

Modifying the MetaStock User Interface • 9

 Menu Specifies the string of the item that is to be deleted. Command  Specifies the action that is associated with the menu item to be deleted. Remarks • This r emoves a menu item from the reserved section of either the MetaStock Tools menu or the MetaStock Help menu. • All three command parameters must be specified to be able to delete a menu item. • MetaStock must be restarted for menu modifications to take effect. IMPORTANT: Third-party developers should only delete the menu items that they have added. A third-party developer should never  delete another developer's menu item. Doing so is a violation of the license agreement.

Example EqCust UI " Menu. Del et eI t em( Mai n- Hel p, My company on t he web, www. mycompany. com) "

Menu.AddPopupItem Menu. AddPopupI t em( <Locat i on>, <Par ent Menu>, <Menu>, <Command>) Parameters

Location

Specifies the placement of the new menu item. Please note that MetaStock uses two different and distinct menus. The first menu ( Main) is used when a chart is not  opened on the screen, whereas the second menu ( Chart) is used when a chart is opened on the screen. For this reason menu items must be added to both the Main menu and the Chart menu to be visible at all times. The following are the different locations available. Placement

Location (The menu is located: )

 Main-Tools

On the Tools menu when no chart is opened.

 Main-Help

On the Help menu when no chart is opened.

Chart-Tools

On the Tools menu when a chart is opened.

Chart-Help

On the Help menu when a chart is opened.

ParentMenu Specifies the name of the parent menu item. Multiple levels can be nested  by using the forward slash (/) character. However, parent menus may not   begin or end with the / separator character. For example, “My company/Support” would be a valid parent menu.

 Menu Specifies the string to be placed on the menu. Command  Specifies the action that is associated with this menu item. Any syntax that can be specified in the Windows run dialog ( > Run) can be specified here. This includes executable files, internet URLs, and documents that are associated with a valid program on the system. MetaStock supports several predefined literals that have special meaning. These literals will be replaced with the appropriate value when the user selects the menu item. The greater-than and less-than (< >) characters must be included.

10 • Modifying the MetaStock User Interface

MetaStock ® 

• Equis strongly  suggests that you statically link the MFC libraries to your DLL for the following reasons: • The MFC DLLs are installed as part of MetaStock, but you cannot be sure that they will be compatible with your DLL. Statically linking the MFC libraries will ensure compatibility and eliminate run-time conflicts. The additional overhead of the static MFC library will be minimal when using the lightweight MFC classes that are appropriate for use in an MSX DLL. • Using the MFC DLLs within your MSX DLL (dynamic linking) requires the correct and consistent use of the AFX_MANAGE_STATE macro in all exported functions.

F ailure to do so may corr upt MetaStock’s use of MF C, resulting i n system lock-ups and data loss. • A discussion of the AFX_MANAGE_STATE macro is beyond the scope of this manual. You may research its use in the Visual C++ on-line help. • Inclusion of the examples and TODO entries in the generated code is recommended.

Stage II  For all versions: 1. Click  to create the project. The newly created project will contain all necessary project files. Notes: • The generated files define a user function called “ EmptyFunc”. You should replace “EmptyFunc” with your own function(s). • When you change the name of “ EmptyFunc” in your source file, be sure to also change the EXPORT name in the DEF file.

Before compiling your project: Before compiling, make sure the IDE is set to find the header file MSXStruc.h. You can either copy it from the “…\MDK\MSX\C  ” install directory to your project directory, or you can set the IDE via “ Tools> Options> Directories” and add the “…\MDK\MSX\C  ” install directory to the list of include directories. If you plan to write more than one MSX DLL it would be best to use the latter approach.

Borland C++ Builder 4.0 Using the Borland C++ Builder Integrated Development Environment (IDE), create a new DLL project.

To cr eate a new DL L pr oject: 1. 2. 3. 4.

5. 6. 7. 8.

MetaStock ® 

Select File> New from the IDE main menu. Click the New tab. Click the Console Wizard icon. On the Console Application Wizard dialog screen: a. Select DLL under Execution Type.  b. Click . The IDE will create a new DLL project called “Project1”, and will fill in a  beginning DLL source file called Project1.cpp with a few comments and some startup code. Note: If you have been working in the IDE before creating this project, the  project number may be greater than 1. Delete all of the generated code in the Project1.cpp edit window except the line: “#include <condefs.h> ” Select File> Open from the IDE main menu. Select Any file (*.*) under Files of type control. Switch to the “…\MDK\MSX\C  ” install folder.

MetaStock External Functions (MSX) • 41

9. Select both the MSXTmplt.cpp and MSXTmplt.def   files. Both files can be selected by holding down the Ctrl key while left-clicking on the files. 10. Click  on the Open dialog. The two files will appear in the IDE under two new tabs. 11. Select the MSXTmplt.cpp tab. 12. Highlight the entire contents of the MSXTmplt.cpp file in the editor and copy it to the clipboard by selecting Edit> Copy from the IDE main menu (or pressing CTRL+C). 13. Switch back to the Project1.cpp tab. 14. Position the cursor below the “#i ncl ude <condef s. h>” line. 15. Select Edit> Paste from the IDE main menu (or press CTRL+V). The MSXTemplate contents will be pasted into the new project. 16. Switch back to the MSXTmplt.cpp tab and close the edit window by pressing CTRL+F4. 17. Save the project under the name you will be calling your DLL by selecting File> Save Project As… Notes: • The Save As… dialog will be pointing to the MSX Template folder, so be sure to create or select a new folder for your project before saving it. • Be sure to replace the name Project1.bpr   with the name you will be calling your DLL.

After saving your project: 1. Select the MSXTmplt.def   tab. 2. Select File> Save As…, and save MSXTmplt.def   in your project folder with the same name you gave your project. 3. Select Project> Add to Project… and select the .def   file you just saved in your  project directory. Notes: • The IDE will add a line to your .cpp file to include the definition file. For example, if you named your project Foo, the foo.cpp file will now contain the line “USEDEF( “Foo. def ”) ; ”. At this point you may edit the .cpp and  files to implement your own functions. .def  • The template files define a user function called “ EmptyFunc”. You should replace “ EmptyFunc” with your own function. • When you change the name of “ EmptyFunc” in your source file, be sure to also change the EXPORT name in the DEF file.

Before compiling your project: Before compiling your project you must make sure the MSXStruc.h file is available to your project. You can either copy the file from the …\MDK\MSX\C install directory to your project directory, or you can instruct the IDE where to search for it. To do this: 1. Select Project> Options… from the IDE main menu. 2. Select the Directories> Conditionals tab. 3. Add the …MDK/MSX/C install directory to the Include path edit window. Note: Borland C++ Builder complains about unused arguments in a function. You can suppress the compiler warning by including the following line above each function declaration: . #pragma argsused 

Look at the provided sample DLLs and printed source code in the next chapter for specific programming requirements.

42 • MetaStock External Functions (MSX)

MetaStock ® 

Borland C++ 5.0 Using the Borland C++ Integrated Development Environment (IDE), create a new Dynamic Library project.

To cr eate a new Dynamic L ibrary pr oject: 1. This is done by selecting File> New> Project… from the IDE main menu. A project definition dialog will be displayed. 2. Specify the project path and name, using the name for your DLL as the project name. 3. Select Dynamic Library (.dll) under Target Type. 4. Select Win32 under Platform, and GUI under Target Model. 5. De-select all check-box options under Frameworks, Controls, and Libraries. 6. Select Static under Libraries. A window will open showing three files: <projectname>.cpp, <projectname>.def, and <projectname>.rc. These files do not yet exist. 7. Copy MSXTmplt.cpp and MSXTmplt.def   from the …\MDK\MSX\C   install directory to your project directory, and rename them to your project name. (You can do this with Windows Explorer.) For example, if your project is called “MyFuncs” and is located at C:\MyFuncs, copy MSXTmplt.cpp and MSXTmplt.def   to C:\MyFuncs, and then rename  to MyFuncs.def  . MSXTmplt.cpp to MyFuncs.cpp, and MSXTmplt.def  8. At this point you can double click on the filenames in the IDE and edit them. Notes: • The template files define a user function called “ EmptyFunc”. You should replace “ EmptyFunc” with your own function. • When you change the name of “ EmptyFunc” in your source file, be sure to also change the EXPORT name in the DEF file. You are now ready to modify the CPP file to implement your functions.

Before compiling your project: Before compiling your project you must make sure the MSXStruc.h file is available to your project. You can either copy the file from the “…\MDK\MSX\C  ” install directory to your project directory, or you can instruct the IDE where to search for it. To do this: 1. Select Options> Project from the IDE main menu. 2. Highlight Directories under Topics. 3. Add the MSX install directory to the Source Directories> Include edit window.

Look at the provided sample DLLs and printed source code in the next chapter for specific programming requirements.

Borland Delphi 3.0, 4.0, and 5.0 Using the Borland Delphi Integrated Development Environment (IDE), create a new DLL project.

To cr eate a new DL L pr oject: 1. Select File> New from the IDE main menu. 2. Click the DLL icon. The IDE will create a new DLL project and will fill in a beginning DLL source file with a few comments and some startup code. 3. Save the project under the name you will be calling your DLL by selecting File> Save Project As….

MetaStock ® 

MetaStock External Functions (MSX) • 43

After saving your project: 1. Select File> Open from the IDE main menu. 2. Open the MSXTmplt.pas file, located in the …\MDK\MSX\Delphi install directory. 3. Highlight the entire contents of the MSXTmplt.pas file in the editor and copy it to the clipboard by selecting Edit> Copy from the IDE main menu (or pressing CTRL+C). 4. Switch back to the tab with your project name, and highlight the default comments and code that the IDE created. 5. Select Edit> Paste from the IDE main menu (or press CTRL+V) and the MSXTemplate contents will be pasted into the new project, replacing the code generated by the IDE. 6. Change “DelDll” in the “l i br ar y Del Dl l ” line to the name of your project. 7. Click the MSXTmplt tab. 8. Right-click anywhere in the text, and select “Close Page” or “Close File” (depending on the version of Delphi you are using).

Before compiling your project: Note: In order to compile your DLL you will have to ensure that the MSXStruc.inc file can be found. You can either copy it from the …\MDK\MSX\Delphi install directory to your  project directory, or you can add the …\MDK\MSX\Delphi directory to the list of files the Delphi IDE searches when compiling.

To do this: 1. Select Tools> Environment Options from the IDE main menu. 2. Click on the Library tab. 3. Add the MSX\Delphi install directory to the list of directories in the Library Path field.

PowerBASIC/DLL 6.0 1. Copy MSXTmplt.bas from the install folder …\MDK\MSX\PBasic to the folder where you are going to develop your DLL. (You can do this with Windows Explorer.) 2. Rename your new copy of MSXTmplt.bas to the name you want for your DLL. For example, if you were creating an MSX DLL called MyFuncs, you would rename MSXTmplt.bas to MyFuncs.bas. 3. Open the new file in the PowerBASIC IDE and proceed to make your changes.

Before compiling your project: In order to compile your DLL you will have to ensure that the MSXStruc.bas file can  be found. You can either copy it from the “ …\MDK\MSX\PBasic” install directory to your project directory, or you can add the “ …\MDK\MSX\PBasic” directory to the list of files the PowerBASIC IDE searches when compiling. 1. Select Window> Options…. 2. Click the Compiler  tab. 3. Type a semicolon at the end of the Paths> Include line. 4. Following the semicolon, enter the complete path to where the MSXStruc.bas file was installed (…\MDK\MSX\PBasic) . Note: This operation will only need to be done once, as the path modification will remain until you change it.

Naming your DLL and Calculation Functions Because MetaStock loads all MSX DLLs from the same folder, each MSX DLL must have a unique name. Be sure to give your DLL a descriptive name that is unlikely to conflict with a DLL name chosen by another developer. Long file names are supported,  but keep in mind that MetaStock users will have to type the entire DLL name along with the function name to reference your functions. Note: Function names must be unique only within a given DLL. Choose descriptive names for each of your functions as a courtesy to the MetaStock users who will be calling them. 44 • MetaStock External Functions (MSX)

MetaStock ® 

Stress Testing Your DLL Functions The DLL Stress Test involves calling your DLL function thousands of times with many variations in the data arguments. Three types of tests are performed: Max/Min Data Array Tests, Special Case Data Array Tests, and Argument Range Tests. Note: Most of these conditions should not  occur in practice. The stress tests ensure that your DLL can handle extreme conditions without crashing or causing a run-time exception.

 Max/Min data array tes ts Max/Min data array tests consist of calling your DLL function with all possible combinations of the following data array setups: Setup

Result

Empty

All data arrays are empty.

Max

Data arrays are either empty or filled with the maximum  float  value (FLT_MAX).

Min

 Data arrays are either empty or filled with the minimum  float  value (FLT_MIN).

NegMax

Data arrays are either empty or filled with the negative maximum  float  value.

NegMin

Data arrays are either empty or filled with the negative minimum  float  value.

Zeros

Data arrays are either empty or filled with zeroes (0.0).

Alternating

Data arrays are either empty or filled with the following repeating sequence: FLT_MAX, -FLT_MAX, FLT_MIN, -FLT_MIN, 0.0.

 S pecial C ase data array tes ts Special case data array tests consist of calling your DLL function with the following data array setups: Setup

Result Each data array is set with iFirstValid  equal to iLastValid .

One Element Illegal First/Last

 

iFirstValid  is less than zero and iLastValid  is greater than 0.

Unusual Empty

 

iLastValid  is less than iFirstValid  indicating empty, but they are set to unusual values rather than iFirstValid  = 0, iLastValid = -1.

Close GT High

The values in the Close price array are greater than the values in the High data a rray.

Close LT Low

The values in the Close price array are less than the values in the Low data array.

Y2K 

The date field in the  DateTime structure contains all dates greater than 20000101.

Y2K Transition

The date field in the  DateTime structure crosses over from dates in 1999 to 2000.

Invalid Dates

Invalid month and day components in the date field.

No Date

The date array is zero-filled.

Date Gaps

Occasional sequences of zero in the date array.

Date Sequence

Dates in date array suddenly jump back in time.

Invalid Times

Hour and minute components of time arr ay are illegal.

Time w/o Date

The time array contains valid data, but the date array is zero-f illed.

Random Ticks

The ticks component of the time f ield is set to random noncontiguous values.

Repeating High Ticks The ticks component of the time field is incremented to 999, then several entries repeat at 999 before the rest of the time changes and the tick field is reset.

52 • MetaStock External Functions (MSX)

MetaStock ® 

 A rg ument rang e tes ts Argument range tests call your function with each of the built-in data sets, and the function arguments set as follows: Setup

Result

Numeric fields

These are set from 999999999999.00 to -999999999999.00. The value is modified toward 0.0 by 20% on each call.

String fields

These are called with empty strings, large strings containing all typeable characters, and a string of blanks.

Custom fields

These are set to all legal values defined by the function, INT_MIN, and INT_MAX.

R unning a Stres s Tes t  When you highlight a function, then select “ File> Stress Test…” from the main menu you will be presented with a dialog box similar to the following:

Click

 to begin the Stress Test.

• A progress bar will indicate test activity, but is not representative of the total number of tests to be performed. The bar may be fully displayed from one to five times depending on the number of arguments defined for the function. There will be a great deal of disk activity during the test. • At the conclusion of the Stress Test a text file will be displayed with the test results. Any function calls that produce a run-time exception or return a value of MSX_ERROR will be logged in the file. • If the error is a fatal-type error, such as illegal memory writes or stack overflow, the test will be prematurely terminated. • Min/Max data array test results will include a string indicating which data arrays contain data and which are empty. For example, the string “O, , , C, V, , ” contains data in the Open, Close and Volume data arrays. •  Normally, the Stress Tests are performed wit h 1000 data points. This allows rapid testing for initial results or re-testing DLL modifications. Be sure to run the Stress Tests with the “Use Large Data Arrays” check box selected at least once before releasing your DLL. This option uses data arrays with 65500 data points. Large data arrays significantly slow the stress test, but will help to reveal floating point overflows and underflows that may be missed by the normal test. • The results from all Stress Tests are stored in a folder named “Stress” located immediately below the folder containing MSXTest.exe. The result file name consists of the DLL name, Function Name, and “ Stress.Txt”. For example, the results for ColdFront.MyMov would be found in the file “ ColdFront.MyMov.Stress.Txt”. CAUTION: E ach time a stress test is run for a given function, the previous results for that

 function will be overwritten.

MetaStock ® 

MetaStock External Functions (MSX) • 53

Cons iderations for making s ure your functions pas s the stress tes t: • Your function should never produce a math exception, such as overflow, underflow, or division by zero. In practice, your function should not receive values that would cause overflow or underflow conditions to occur, but because your function may receive as input the output of another external function you must be prepared to handle extreme values. The supplied template files, MSXTmplt.cpp, MSXTmplt.pas, and MSXTmplt.bas, contain a function that forces the passed value to lie within the minimum and maximum values for a single precision floating point number. If you  perform your floating point calculations using doubles (double precision fl oating  point), and then force the results into the required range, you can avoid most overflow and underflow conditions. See the sample DLLs for examples of using this approach. • Test the value of the divisor before any mathematical division to avoid division by zero exceptions. • Test all arguments for valid ranges. Return MSX_ERROR in the cases where a clearly defined argument type is out of bounds (such as an out-of-range Custom ID). • Make sure you never access a data array with a negative index. • Be careful about returning the MSX_ERROR result from your external functions. When MetaStock encounters that return type it will display an extended error message in a dialog box that will require user response. Report only errors that are significant problems the user needs to know about – not just exceptional situations your DLL wasn’t equipped to handle.

Automating MSXTest From Your IDE If the compiler IDE you are using supports user-defined tools you may find it useful to define MSXTest in the tool list. Using the specific IDE tool macros, specify the target directory of the project as a command line argument for MSXTest. When MSXTest starts up, it checks its command line arguments for a directory. If one is found, it sets that directory as the location to search for MSX DLLs. For example, using Microsoft Visual C++ 6.0, you could define MSXTest as a tool by selecting “Tools> Customize” from the main menu. Select the “Tools” tab, and click the “New” icon. Enter  MSXTest and press Enter. Fill in the Command field with the full path to where you installed MSXTest (e.g.  C:\Program Files\Equis\MDK\MSX\MSXTest.exe). Fill in the “Arguments” field with “$( Tar get Di r ) ”, and leave the “Initial Directory” field blank. Click “ ”. Now when you select “Tools” from the main menu, you will see “MSXTest” as an entry. Most other compiler IDEs have similar capabilities. Refer to your IDE documentation for specifics.

54 • MetaStock External Functions (MSX)

MetaStock ® 

Testing Your DLL With MetaStock CAUTION: Be sure you have fully tested your DLL with the MSXTest program before loading it with MetaStock.

To test your MSX DLL with MetaStock, copy it to the “External Function DLLs” folder located below the folder defined for Custom Indicators, System Tests, and Explorations. If the “External Function DLLs” folder does not already exist, you must first create it. (The default location is “C:\Program Files\Equis\MetaStock \External Function DLLs”.) Note: If you are replacing an MSX DLL that already exists in the “External Function DLLs” folder you must first shut down MetaStock . Because MetaStock  loads all available MSX DLLs at startup, they cannot be deleted or replaced until MetaStock  shuts down and releases the DLLs.

Perform at least the following minimum tests: • Verify that the correct text appears in the Paste Functions dialog and that the parser is correctly compiling the syntax for all external functions. This includes the display of meaningful error messages when a syntax error is detected in the use of an external function. • Use Indicator Builder to write a sample indicator that calls a function in your DLL. • Plot the indicator and check the values. Make sure that calculation results are correctly displayed in charts. • Edit the plot via right-click. • Repeat for each function in the DLL.

MetaStock ® 

MetaStock External Functions (MSX) • 55

it is applied. Since the input array had a first valid of 3, the 3-period moving average average did not come up to speed until until the fifth data element. Again, the last valid value is set to 7 because the input data array array had a last valid of 7.

 S ecur ecu r ity P ri ce Data When MetaStock calls a calculation function in an MSX DLL, it automatically gives the DLL access to security price data. The DLL does not have to explicitly explicitly declare an argument in the external function for access to the security data. This means that even if an external function has no arguments, the calculation functions in the DLL will still be given security price and detail data to work with. MSX DLL calculation • An MSX DLL calculation function has no way of knowing which type of formula function (e.g., Custom Indicator, Indicator, System Test, etc.) etc.) is calling the external function. function. The external external function calculation process only knows that it is given a set of data arrays that define the price data for the target security. The external calculation function simply performs the appropriate calculations and returns the resulting data array to MetaStock. the MSXDataRec structure  structure ( page 36) 36) to supply security price and MSXDataRec structure • MetaStock uses the MSXDataRec detail data to an MSX DLL. • In the case of an external function used in an Indicator, the MSXDataRec the  MSXDataRec structure  structure will contain the price and detail data for the base security of the chart where the custom indicator is being calculated. • For System Tests, the structure is loaded with base security data for the active chart when the system test was launched. • For Explorations, the structure is loaded with security data for the security currently being explored. • For Experts, the structure is loaded with the base security data for the chart where the expert is attached. • The MSXDataRe The MSXDataRecc structure contains seven data arrays stored in MSXDataIn in MSXDataInfoRec foRec structures ( page  page 35). 35). These data arrays store all relevant price data for the security. Some of these arrays may be empty (see the discussion of empty data arrays in the  MSXDataInfoRec  MSXDataInfoRec section  section ( page 35) 35) if the security does not have data for that price field. • Also contained in the MSXDataRec the MSXDataRec structure  structure is a pointer to an array of MSXDateTime of MSXDateTime structures. This array contains contains date and and time information for each data point. If a calculation function needs to access the date and time for the Nth bar of the security, it would reference the Nth element of the psDate the  psDate array. Note that this is not a data array like the sHigh the sHigh,, sLow,  sLow, etc. sInd data array  • The data array sInd  array sInd  contains  contains data for a user-selected indicator. In the case of a Custom Indicator this data array will contain the value for the chart object on which the indicator was dropped. For System Tests and Explorations, this array contains the selected plot (if there is one) of the active chart when the system Test or Exploration was started. For Experts, this array contains the selected plot (if there is one) of the chart when the Expert was attached. In all cases, if no plot is selected the sInd  the sInd  data  data array will be empty. •  Notice that the location of the data in these arrays is synchronized. The Nth element of each array corresponds to the same time frame. The sClose data  data array always contains the maximum data data points. All other data sClose data array  • The sClose arrays will contain equal to or less than the value of sClose.iLastV of  sClose.iLastValid  alid . iFirstValid, iLastValid  • The iFirstValid  and  and iLastValid  settings  settings in the sClose the sClose data  data array are significant. settings Typically the number of data elements in this data array defines the maximum number of data elements stored in the other price arrays. This is important for determining the number of valid elements contained in the psDate the  psDate   array. For example, if the sClose.iFirstV the sClose.iFirstValid  alid field field contains 100 and the sClose.iLastV the sClose.iLastValid  alid  field  field contains 200, you can be certain that the psDate the  psDate array  array contains valid data at  psDate[100] through  psDate[100] through psDate[200]  psDate[200]..  should Note: After a calculation is performed, the a_psResultRec->psResultArray ’s iLastValid  should never be greater than the iLastValid  value  value of the  sClose data array.

58 • MetaSto MetaStock ck Exte Externa rnall Funct Function ions s (MSX) (MSX)

MetaStock ® 

• The iFirstValid  and  and iLastValid  of sClose  of sClose should  should be used to determine how much storage is available for all data arrays. All arrays have enough memory allocated to store up to sClose.iLastV to sClose.iLastValid  alid data data points. Data returned in a_psResultRec->  psResultArray from  psResultArray from an MSX DLL must keep within these same storage constraints. Note: The a_psResultRec->psResultArray  data array returned from an MSX DLL must never  sClose.iFirstValid . The a_psResultRec-> have an iFirstValid that is less than  sClose.iFirstValid   that is  psResultArray data array returned from an MSX DLL must never have an iLastValid  that greater than sClose.iLastValid   sClose.iLastValid .

Things to Remember  • Calculation functions must never modify any incoming arguments, wit h the exception of the result record (a_psResultRec ( a_psResultRec). ). Incoming arguments are defined as ‘const’, where possible, in the provided templates to help ensure that no illegal modifications take place. • Be sure to set a_psResultRec->psResultArray->iFirstValid  and  and a_psResultRec->psResultArray->iLastValid  in  in the returned MSXResultRec returned MSXResultRec before  before returning from your function. • If your function is returning MSX_ERROR indicating an internal error, be sure to copy an extended string message describing the cause of the error to a_psResultRec->pszExtendedError . Make sure your message string does not exceed MSX_MAXSTRING bytes.

 less than sClose.iFirstV than sClose.iFirstValid  alid . •  Never set a_psResultRec->psResultArray->iFirstValid  less •  Never set a_psResultRec->psResultArray->iLastValid  greater  greater than  sClose.iLastValid   sClose.iLastValid . Writing to a_psResultRec->psResultArray->pfValue a_psResultRec->psResultArray->pfValue beyond  beyond the value of sClose.iLastV of sClose.iLastValid  alid  will  will corrupt MetaStock’s heap. • Be sure to check the iFirstValid  and  and iLastValid  of  of any MSXDataInfoRec any MSXDataInfoRec arguments  arguments or a_psDataRec members a_psDataRec members you intend to use. Never assume that data will be available in any data array. If data is not available for your function to process, set a_psResultRec->psResultArray->iFirstValid  to  to 0 and a_psResultRec->  psResultArray->iLastValid   psResultArray->iLastV alid  to  to –1 to indicate that there is no valid data in the returning array. This method allows processing to continue in the most robust way possible.

User Interface Restrictions While an MSX DLL calculation function is active, all other formula processing in MetaStock is suspended. F or this re r eason, son, an MSX D L L must NOT, unde under any cir ci r cumstance cumstances, s, r equest equest user user i nput through throug h message message boxes boxes or dialogs. This includes the reporting of error conditions. Users routinely leave MetaStock running for extended periods unattended. MSX DLLs cannot assume that a user is available available to respond to a message of any kind. MSX DLLs must refrain refrain from implementing implementing any user any user interface.

MetaStock ® 

MetaSt MetaStock ock Extern External al Func Functio tions ns (MSX (MSX)) • 59

Tech Note 1 – Using MSFL in an MSX DLL If you use MSFL calls from your MSX DLL, there are a few issues you must consider. MetaStock loads and initializes initializes the release version of the MSFL DLL at startup. If your • MetaStock MSX DLL is also using the release version of MSFL, it must not call MSFL1_Initialize call MSFL1_Initialize ( page  page 115 115)). MSFL’s initialization routine should be called only once during the lifetime of an application. If your MSX DLL calls MSFL1_Shutdown calls MSFL1_Shutdown (  ( page  page 124 124)), then  MSFL1_Initialize  MSFL1_Initialize,, the MSFL operations that MetaStock is performing will be corrupted.  Again, this this is only if your MSX MSX DLL is using using the release version of the MSFL MSFL DLL. • If your MSX DLL uses the debug version of the MSFL DLL that was shipped with the MDK, you will need to call MSFL1_Initialize call  MSFL1_Initialize once  once from within your MSX DLL, and you will also need to call MSFL1_Shutdown call  MSFL1_Shutdown when  when your MSX DLL is unloaded. • The recommended approach is to make your MSX DLL respond correctly under both conditions by calling MSFL1_GetMSFLState calling MSFL1_GetMSFLState (  ( page  page 107 107)) to determine if the MSFL DLL your MSX DLL uses is already loaded and initialized. If  MSFL1_GetMSFLState returns   MSFL1_GetMSFLState returns MSFL_STATE_INITIALIZED, your MSX DLL is using the same MSFL DLL as MetaStock. If MSFL1_Ge If  MSFL1_GetMSFLS tMSFLState tate returns  returns MSFL_STATE_UNINITALIZED, your MSX DLL is using a different version of the MSFL DLL, and it must be initialized via a call to MSFL1_Initia to MSFL1_Initialize lize.. If this is the case, set a flag in your MSX DLL code that can be checked during the DLLMain’s DLL_PROCESS_DETACH logic that will indicate that MSFL1_Sh that MSFL1_Shutdown utdown is  is required. Note: The MSFL1_GetMSFLS  MSFL1_GetMSFLState tate logic cannot be performed during the DLLMain DLL_PROCESS_ATTACH, as MetaStock  loads  loads all MSX DLLs before it initializes the MSFL DLL. If your MSX DLL DLL initializes the release version of MSFL before MetaStock  gets  gets a chance to, MetaStock  will  will fail to load. Make the check from somewhere inside one of your exported user functions, setting a flag to ensure that the Initialize call is not made more than once. • If you plan to distribute your MSX DLL (containing (containing MSFL logic) to other MetaStock MetaStock users: • Other MetaStock MetaStock users users must have have the same version version of the MSFL DLL that your your MSX DLL is expecting to use. It is essential that your MSX DLL references the release build of MSFL if your MSX DLL will be executed by another MetaStock user. The debug version of MSFL DLL will (almost certainly) not be present on their system. • Realize Realize that this approach approach may require require a new version version of your MSX DLL for each new version of MSFL that may be released in the future. For example, as of this writing, the current version of MSFL is MSFL72.DLL. If a future version of MetaStock is shipped with MSFL73.DLL, your MSX DLL will not find the MSFL72.DLL it expects, and will fail to load. • The recommende recommended d approach approach is to update your MSX DLL with each each release release of a new version of MSFL. This approach will ensure that your MSX DLL is tested with each new release, and that it will not attempt to load an untested version of the MSFL MSFL DLL. DLL. • An alternative alternative approach approach is to dynamically dynamically load load the MSFL library library via the “LoadLibrary” system call, and then resolve each MSFL function you use via the “GetProcAddress” system call. This will allow you to make a minimal change to your MSX DLL to maintain compatibility compatibility with future MSFL releases. releases. Attempt to load the most recent MSFL DLL first. If that fails, attempt to load the next most recent, etc. Your DLL must have a method of obtaining the current current MSFL DLL name. You can hard-code hard-code the names of all the potential MSFL DLLs that may be present, retrieve the names from an external file that you can provide or document for your user to maintain, or search the windows system folder for “MSFL*.DLL” files. Searching for the file name in the system folder carries the potential risk of eventually encountering a future version of the MSFL DLL that is incompatible with older older MetaStock files. In that case, case, your MSX DLL would fail fail to load or to operate operate correctly. correctly.

60 • MetaSto MetaStock ck Exte Externa rnall Funct Function ions s (MSX) (MSX)

MetaStock ® 

MSX Index A

H

Argument range tests 53

Help 26

B

I

Borland C++ 5.0 Creating an MSX DLL 43 Debugging an MSX DLL 46 Borland C++ Builder 4.0 Creating an MSX DLL 41 Debugging an MSX DLL 46 Borland Delphi Pascal Creating an MSX DLL 43 Debugging an MSX DLL 46

iFirstValid 30, 35 defined 35 iFirstValid setting 58 iLastValid 30, 35 defined 35 iLastValid setting 58 iLastValue indexes 30 Initialization Functions 27 MSXInfo 27 MSXNthArg 28 MSXNthCustomString 29 MSXNthFunction 28 Initialization Structures 32 MSXDLLDef  32 MSXFuncArgDef  33 MSXFuncCustomString 34 MSXFuncDef  32

C C Creating an MSX DLL 40, 41, 43 Debugging an MSX DLL 45, 46 Calculation Functions 30

Calculation Structures 35 MSXDataInfoRec 35 MSXDataRec 36 MSXDateTime 35 custom strings, and partial matches 34

L lTime 35

D

M

Data Data Array 56 Price Data 58 Sample Sample 48 Types 31 data array Argument range 53 tests Max/Min 52 Special Case 52 Data Types 31 Dates 31 Strings 31 Times 31 distributing your MSX DLL 60

Max/Min data array tests 52 MetaStock External Function (MSX) defined 25 Microsoft Visual C++ Creating an MSX DLL 40 Debugging an MSX DLL 45 MSFL, using in an MSX DLL 60 MSX DLL, distributing 60 MSX_ERROR 39 MSX_ERROR  39 MSX_MAXARGS 33, 38 MSX_MAXSTRING 32 MSX_MAXSTRING, defined 31 MSX_VERSION 32 MSXCustom 34 MSXCustomArgsArray structure 39 MSXDataInfoRec 36 MSXDataInfoRec structure 35 MSXDataInfoRecArgsArray structure 38 MSXDataRec 35 MSXDataRec structure 58 described 36 MSXDateTime 35, 36 MSXDLLDef structure 27 MSXFuncArgDef data structure 29 MSXFuncCustomString data structure 29 MSXFuncDef data structure 28

E ExtFml 26, 32, 34

F Function Argument Structures 38 MSXCustomArgsArray 39 MSXDataInfoRecArgsAr ray ray 38 MSXNumericArgsArray 39 MSXResultRec 39 MSXStringArgsArray 39

61 • MetaStock External Functions (MSX) (MSX)

MetaStock ® 

MSXNthCustomString 34 MSXNumeric arguments 38 MSXNumericArgsArray argument array 38 MSXNumericArgsArray structure 39 MSXResultRec structure 39 MSXStringArgsArray structure 39 MSXStruc.bas 32 MSXStruc.pas 32

P  partial match on custom strings 34 PowerBASIC Creating an MSX DLL 44 Debugging an MSX DLL 47 Programming Considerations UI Restrictions 59

S sClose data array 58 sInd structure 36 Special Case data array tests 52 strings, and partial matches 34

T Tech Notes Using MSFL in an MSX DLL 60 Technical support 26 Testing MSXTest 48 Stress Testing 52 Testing your DLL with MetaStock  55

V Variable Notation 31 Visual Basic 25

W Win32 43 Win32 DLL 25

62 • MetaStock External Functions (MSX)

MetaStock ® 

Sample DLL Programs

The following three programs demonstrate complete source code for implementing a moving average in C, Delphi Pascal, and PowerBASIC/DLL.

“C” Example / / ================================================================== #i ncl ude <st r i ng. h> #i ncl ude <st dl i b. h> #i ncl ude <mat h. h> #i ncl ude " MSXSt r uc. h" / / we don' t want C++ name- mangl i ng #i f def _ _cpl uspl us ext ern "C" { #endi f  / / - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -BOOL _ _s t dcal l MSXI nf o ( MSXDLLDef *a_psDLLDef ) { / / copy i n your copyr i ght i nf or mat i on. . . st r ncpy ( a_psDLLDef - >szCopyri ght , "Copyri ght ( c) Col dFront Logi c, I nc. , 2000", si zeof ( a_psDLLDef - >szCopyri ght ) - 1) ; a_psDLLDef - >i NFuncs = 1; / / One cal cul ati on f unct i on; a_psDLLDef - >i Ver si on = MSX_VERSI ON; r et ur n MSX_SUCCESS; } / / - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -BOOL __ st dcal l MSXNt hFunct i on ( i nt a_i Nt hFunc, MSXFuncDef *a_ psFuncDef ) { BOOL l _bRt r n = MSX_SUCCESS; swi t ch ( a_i Nt hFunc) { case 0: / / a_i Nt hFunc i s zer o- based st r cpy ( a_psFuncDef - >szFunct i onName, " MyMov" ) ; st r cpy ( a_psFuncDef - >szFunct i onDescr i pti on, " My Movi ng Aver age") ; a_psFuncDef - >i NAr gument s = 3; / / 3 argument s: dat a ar r ay, peri ods, met hod   br eak;   def aul t : l _bRt r n = MSX_ERROR;   br eak; } r et ur n l _bRt r n; } / / - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -BOOL _ _st dcal l MSXNt hAr g ( i nt a_i Nt hFunc, i nt a_i Nt hAr g, MSXFuncAr gDef *a_psFuncAr gDef ) { BOOL l _bRt r n = MSX_SUCCESS; a_psFuncAr gDef - >i NCust omSt r i ngs = 0; swi t ch ( a_i Nt hFunc) { case 0: swi t ch ( a_i Nt hAr g) { MetaStock ® 

Sample DLL Programs • 63

 

 

           

case 0: a_psFuncAr gDef - >i Ar gType = MSXDat aAr r ay; / / dat a arr ay st r cpy ( a_psFuncAr gDef - >sz Ar gName, " Dat aAr r ay" ) ; br eak; case 1: a_psFuncAr gDef - >i Ar gType = MSXNumer i c; / / Numer i c st r cpy ( a_psFuncAr gDef - >szAr gName, "Per i od" ) ; br eak; case 2: a_psFuncAr gDef - >i Ar gType = MSXCust om; / / Cust omType a_psFuncAr gDef - >i NCust omSt r i ngs = 4; st r cpy ( a_psFuncAr gDef - >sz Ar gName, " Met hod") ; br eak; def aul t : l _bRt r n = MSX_ERROR; br eak; } br eak; def aul t : l _bRt r n = MSX_ERROR; br eak; } r et ur n l _bRt r n;

} / / - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - BOOL __s t dcal l MSXNt hCust omSt r i ng ( i nt a_i Nt hFunc, i nt a_i Nt hAr g, i nt a_i Nt hSt ri ng, MSXFuncCust omSt r i ng *a_psCust omSt r i ng) { BOOL l _bRt r n = MSX_SUCCESS; t ypedef st r uct { char *szSt r i ng; i nt i I D; } Local St r i ngEl ement ; Local St r i ngEl ement l _sTheSt r i ngs[ ] = { {"Si mpl e", 0}, {"S", 0}, {"Wei ght ed" , 1}, {"W" , 1} };

            }

swi t ch ( a_i Nt hFunc) { case 0: swi t ch ( a_i Nt hAr g) { case 2: i f ( a_i Nt hSt r i ng >= 0 && a_i Nt hSt r i ng < NMyMovCust St r i ngs) { st r ncpy ( a_psCust omSt r i ng- >szSt r i ng, l _sTheSt r i ngs[a_i Nt hSt ri ng] . szSt r i ng, MSX_MAXSTRI NG- 1) ; a_psCust omSt r i ng- >i I D = l _sTheSt r i ngs[ a_i Nt hSt r i ng] . i I D; } br eak; def aul t : l _bRt r n = MSX_ERROR; br eak; } br eak; def aul t : l _bRt r n = MSX_ERROR; br eak; } r et ur n l _bRt r n;

/ / *********************************************************************** / / Thi s l ocal ut i l i t y f uncti on i s used t o hel p ensur e t hat no over f l ows // or under f l ows wi l l occur dur i ng cal cul ati ons. The MSXTest pr ogr am // St r ess Test f unct i on wi l l cal l your DLL wi t h a wi de r ange of val ues, // i ncl udi ng posi t i ve and negat i ve val ues of FLT_MAX and FLT_MI N. / / Per f or m al l i nt er medi at e cal cul at i ons usi ng doubl es and t hen f or ce t he 64 • Sample DLL Programs

MetaStock ® 

var l _i I ndex : I nt eger ; l _i MaxI ndex: I nt eger ; l _l f Sum : Doubl e; i : I nt e ge ger ; begi egi n l _ i I ndex : = a_ p ps s Sr Sr c . i Fi r s t Val i d; l _i MaxI ndex : = a_psS _psSrr c. i Last Last Val i d; l _ l f Sum : = 0. 0;

a_i Peri od : I nt eger ) ;

f or i : = 0 t o a_ i Per i od- 1 do l _l f Sum : = For ceS ceSi ngl eRange( l _l f Sum + a_psS _psSrr c. pf Val ue[ l _i I ndex+i ] ) ; l _l f Sum : = For For ceS ceSi ngl eRange ( l _l f Sum) ; l _ i I ndex : = l _ i I ndex + a_ i Per i od - 1; 1; whi l e l _i I ndex <= l _i MaxI ndex do   beg begi n a_psR _psRe esul sul t . pf Val ue[ l _i I ndex] : = For For ceS ceSi ngl eRange( l _l f Sum / a_i Per i od) ; l _ i I ndex : = l _ i I ndex + 1; l _ l f Sum : = l _ l f Sum - a_ p ps s Sr Sr c . pf Val ue[ l _ i I ndex- a_ i Per i od] ; i f l _i I ndex <= l _i MaxI ndex t hen   l _l f Sum : = Force ForceS Si ngl eRange( l _l f Sum + a_psS _psSrr c. pf Val ue[ l _i I ndex] ) ;   end; a_ p ps s Re Res ul ul t . i Fi r s t Val i d : = a_ p ps s Sr Sr c . i Fi r s t Val i d + ( a _ i Per i od - 1) 1) ; a_psR _psRe esul sul t . i Last Last Val i d : = l _i MaxI ndex; end; / / *********************************** ***************************************************** ************************************ *********************** ***** / / Thi s i s an an exampl e of a l ocal cal pr oced cedur e used sed f or cal cal cul cul at i ons. Thi s on one // cal cul cul at es a wei ght ed movi ovi ng average average on t he sour sour ce dat dat a ar r ay, ay, and and put s t he // r esul sul t s i n t he r esul sul t ar r ay. / / *********************************** ***************************************************** ************************************ ********************** **** pr ocedur ocedur e Wei ght ght edMovi ngA ngAver age ( const a_psSr c: PMSXD SXDat aI nf oRec; oRec; var var a_psResul a_psResul t : MSXD SXDat aI nf oRec; oRec; a_i Per i od : I nt eger) ; var l _i I ndex : I nt eger ; l _i MaxI ndex: I nt eger ; l _l f Sum : Doubl e; l _l f Di vi sor sor : Doubl e; i : I nt e ge ger ; begi egi n l _ i I ndex : = a_ p ps s Sr Sr c . i Fi r s t Val i d; l _i MaxI ndex : = a_psS _psSrr c. i Last Last Val i d; / / Su Sum of Di Di gi t s f ormul a l _l f Di vi sor sor : = For For ceS ceSi ngl eRange( a_i Peri od * (a_i Per i od+1. 0) / 2. 0) ; whi l e ( ( l _i I ndex + a_i Per i od - 1) <= l _i MaxI ndex) do beg begi n l _ l f Su Sum : = 0. 0; f or i : = 0 t o a_ i Per i od- 1 do l _l f Sum : = Force ForceS Si ngl eRange( l _l f Sum + a_psS _psSrr c. pf Val ue[ l _i I ndex+i ] * ( i + 1. 0) ) ; a_psR _psRe esul sul t . pf Val ue[ l _i I ndex + a_i Per i od - 1] : = Force ForceS Si ngl eRange( l _l f Sum / l _l f Di vi sor) sor) ; l _ i I ndex : = l _ i I ndex + 1;   end; a_ p ps s Re Res ul ul t . i Fi r s t Val i d : = a_ p ps s Sr Sr c . i Fi r s t Val i d + a_ i Per i od - 1; 1; a_psR _psRe esul sul t . i Last Last Val i d : = l _i MaxI ndex; end;  

/ / - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -- - - / / The The f ol l owi ng f uncti on demonst onst r at es t he use of t hree ar ar gum gument ent t ypes: ypes: // MSXD SXDat aAr aAr r ay, MSXN SXNumer i c and MSXC SXCust om. // A Movi ovi ng Aver ver age i s ca cal cul cul ated on t he i nput Da Dat aAr aAr r ay f or i nput Peri ods. ods. // Two movi ovi ng average average met hods hods are avai avai l abl abl e, s peci peci f i ed t he t he Cust om I D. / / - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -- - - f unct unct i on MyMov ( const a_psDat a_psDat aRec: aRec: PMSXD SXDat aRec; aRec; const const a_psDat a_psDat aI nf oAr oAr gs: PMSXD SXDat aI nf oRecA oRecArr gsAr gsAr r ay; ay; const a_psNum a_psNumer i cAr cAr gs: PMSXN SXNumer i cAr cAr gsAr gsAr r ay; const const a_psSt a_psSt r i ngAr gAr gs: PMSXS SXSt r i ngA ngAr gsAr sAr r ay; ay; const a_psC a_ psCust ust omAr gs: PMSXC SXCust omAr gsAr r ay; var var a_psR a_psResu esull t Rec: ec: MSXResul t Rec) : Lon LongBool ool ; st dcal cal l ;   var var l _bRt _bRt r n MetaStock ® 

: Lon LongBool ; Samp Sample le DLL DLL Pro Progr gram ams s • 69

l _psDat _psDat a : l _ i Per i od : l _i Met hod : l _i I ndex : l _i MaxI ndex: l _ sTmpRec pRec :

PMSXD SXDat aI nf oRec; oRec; I nt e ge ger ; I nt eger ; I nt eger ; I nt eger ; MSXD SXDat aI nf oRec; oRec;

begi egi n / / We e expe xpect ct 3 ar ar gum gument ent s, 1 Dat aAr aAr r ay, 1 Numer i c and and 1 Cust om. / / The The ar gument ent s wi l l be f ound ound at : // Dat aAr aAr r ay: a_psD a_psDataI ataI nf oAr gs- >psDataI sDataI nf oRe oRecs[ 0]   // Numer i c : a_psNum a_psNumer i cAr cAr gs- >f Numer i cs[ 0]   // Cust om : a_psCust a_psCust omAr gs- >i Cust omI Ds[ 0] i f ( ( a_psD _psDa at aI nf oAr gs. i NRecs = 1) an and ( a_psN a_psNum umeri cAr cAr gs. i NRecs = 1) and and ( a_psC a_psCust ust omAr gs. i NRecs = 1)) t hen hen   beg begi n l _ bRt bRt r n : = MSX_ SX_ SUCCESS; ESS; l _psDat a : = a_psD a_psDataI ataI nf oAr gs. psDataI sDataI nf oRecs[ ecs[ 0] ; l _i Per Per i od : = Tr unc ( a_psN _psNumer i cAr cAr gs. f Numer i cs[ 0] ) ; l _i Met hod hod : = a_psC a_psCust ust omAr gs. i Cust omI Ds[ 0] ; l _ i I ndex : = l _ p ps s Dat a. i Fi r s t Val i d; l _i MaxI ndex : = l _psD _psDa at a. i Last Last Val i d;

       

   

     

i f ( l _ i Per i od > 0) and ( ( l _ i I ndex + l _ i Per i od - 1) <= l _ i MaxI ndex) t hen case l _i Met hod hod of  0: Si mpl eMovi ovi ngAver ver age age ( l _psDat _psDat a, a_psR a_psResu esull t Rec. psResu sResull t Ar r ay^ ay^, l _ i Per i od) ; 2: Wei ght ght edM edMovi ovi ngA ngAver ver age age ( l _psDat _psDat a, a_psResul a_psResul t Rec. psResul psResul t Ar r ay^, l _ i Per i od) ; e ell s e beg begi n St r LCo LCopy( a_psRe _psResul t Rec- >szExt szExt endedEr r or, ‘ I nval val i d method ethod’ , MSX_MAXSTRI AXSTRI NG- 1) ; l _bRt _bRt r n : = MSX_ER SX_ERR ROR; end end end end el el s e beg begi n a_psR _psRe esul sul t Rec. psRe sResul sul t Ar r ay. i Fi r st Val i d : = 1; a_psR _psRe esul sul t Rec. psRe sResul sul t Ar r ay. i Last Last Val i d : = 0; end end end el se / / wr ong num number of ar gum gument ent s passed! passed! beg begi n St r LCop LCopy y ( a_psR a_psResu esull t Rec. szExt end endedErr edErr or, ' I ncor ncor r ect num number ber of argument ent s' , MSX_MAXSTRI AXSTRI NG- 1) ; l _ bRt bRt r n : = MSX_ SX_ ERR ERROR; end;

i f ( l _bRt _bRt r n <> MSX_SU SX_SUC CCESS) ESS) t hen hen beg begi n a_psR _psRe esul sul t Rec. psRe sResul sul t Ar r ay. i Fi r st Val i d : = 0; a_psR _psRe esul sul t Rec. psRe sResul sul t Ar r ay. i Last Last Val i d : = - 1;   end;  

MyMov : = l _bRt _bRt r n; end; exp export s   MSXI SXI nf o,   MSXN SXNt hFunct hFunct i on,   MSXNt hArg, hAr g,   MSXN SXNt hCust hCust omSt r i ng,   MyMov; begi egi n end.

70 • Samp Sample le DLL DLL Pro Progr gram ams s

MetaStock ® 

PowerBASIC/DLL Example #COMPI LE DLL OPTI PTI ON EXPLI PLI CI T #I NCLUD LUDE " WI N32A 32API . I NC" #I NCLUD LUDE " MSXSt SXSt r uc. BAS"

' ' ' '

cr eat e a dl l r equ equi r e al l var var i abl abl es t o be decl ecl ared r equi equi r ed equa equatt es and wi ndow ndows pr ot ot ypes ypes MSX Dat a St r uct ur es

FUN FUNCTI ON MSXI SXI nf o SDECL ECL ALI AS " MSXI SXI nf o" ( a_psDLLD a_psDLLDef ef AS MSXD SXDLLDef LLDef PTR) PTR) _  EXPORT AS LON LONG ' cop copy i n you your cop copyri ght i nf or mat i on. . . @a_psD a_psDLLD LLDef ef . szCop szCopyr yr i ght ght = " Copyr opyr i ght ( c) PBD PBDemo I nc. , 2000 000" ' Set Set t he num number of f unct unct i ons ons we are exp export ort i ng @a_psDLLDef . i NFun Funcs = 1 ' One cal cal cul cul ati on f unct i on @a_psD a_ps DLLDef LLDef . i Ver si on = %MSX_ SX_ VERSI ERSI ON MSXI nf o = %MSX_SUCCE SX_SUCCESS SS END FUNCTI ON FUN FUNCTI ON MSXN SXNt hFunct hFunct i on SD SDECL ECL ALI AS " MSXN SXNt hFunct hFunct i on" on" ( _  BYVA YVAL a_i Nt hFunc hFunc AS LON LONG, _  a_psFuncD a_ psFuncDef ef AS MSXFuncD SXFuncDef ef PTR) PTR) EXPO EXPORT AS AS LON LONG MSXNt hFunct hFunc t i on = %MSX_SUCCESS SX_SUCCESS SELECT SELECT CASE a_i Nt hFunc CASE 0 ' a_i Nt hFun hFunc c i s zer o- based based @a_ps FuncDef FuncDef . sz Funct i onName = " MyMov" @a_psFuncD a_psFuncDef ef . szFunct i onD onDescr i pt i on = " My Movi ng Aver ver age" age" ' 3 argum argument ent s: dat dat a arr ay, ay, peri peri ods, ods, met hod hod @a_psFuncDef a_psFuncDef . i NAr gum gument ent s = 3 CASE ELSE MSXNt hFunct hFunc t i on = %MSX_ERROR END SELECT SEL ECT END FUNCTI ON FUN FUNCTI ON MSXN SXNt hAr hAr g SDEC SDECL L ALI AS " MSXN SXNt hAr hAr g" ( _  BYVA YVAL a_i Nt hFunc hFunc AS LON LONG, _  BYVA YVAL a_i Nt hAr hAr g AS LON LONG, _  a_psFuncAr a_ psFuncAr gDef AS MSXFuncA SXFuncArr gDef PTR) PTR) EXPO EXPORT AS AS LON LONG MSXNt SXNt hAr g = %MSX_SUC SX_ SUCCESS CESS @a_psFuncA a_psFuncArr gDef . i NCust omSt r i ngs ngs = 0 SELECT SELECT CASE a_i Nt hFunc CASE CASE 0 SELECT SELECT CASE a_i a_ i Nt hAr hAr g CASE 0 @a_psFuncAr a_psFuncAr gDef . i Ar gType gType = %MSXD SXDat aAr aAr r ay ' Dat aAr aAr r ay; @a_psFuncAr a_psFuncAr gDef . sz Ar gName = " Dat aAr aAr r ay" CASE 1 @a_psFuncAr a_ psFuncAr gDef . i Ar gType gType = %MSXN SXNumer i c ' Numer i c @a_psFuncAr a_psFuncAr gDef . sz Ar gName = " Per i od" od" CASE 2 @a_psFuncAr a_ psFuncAr gDef . i Ar gType gType = %MSXC SXCust om ' Cust omType @a_psFuncA a_psFuncArr gDef . i NCust omSt r i ngs ngs = 4 @a_psFuncAr a_ psFuncAr gDef . sz Ar gName = " Met hod" hod" CASE CASE ELSE ELSE MSXNt SXNt hAr g = %MSX_ERRO SX_ ERROR END SELECT SEL ECT CASE CASE ELSE EL SE MSXNt SXNt hAr g = %MSX_ERRO SX_ ERROR END SELECT SEL ECT END FUNCTI ON FUN FUNCTI ON MSXN SXNt hCust hCust omSt r i ng SDECL ECL ALI ALI AS " MSXN SXNt hCust hCust omSt r i ng" ( _  BYVA YVAL a_i Nt hFunc hFunc AS LON LONG, _  BYVA YVAL a_i Nt hAr hAr g AS LON LONG, _  BYVA YVAL a_i Nt hSt hSt r i ng AS LONG, _  a_psCust a_psCust omSt r i ng AS AS MSXFun SXFuncC cCust ust omSt r i ng PTR PTR) EXPO EXPORT AS AS LON LONG MSXNt hCus hCus t omSt r i ng = %MSX_SUCCES SX_SUCCESS S @a_psCu _psCust omSt r i ng. szStr i ng = "" @a_psCu _psCust omSt r i ng. i I D = - 1

MetaStock ® 

Samp Sample le DLL DLL Pro Progr gram ams s • 71

SELECT CASE a_i Nt hFunc CASE 0 SELECT CASE a_i Nt hAr g CASE 2 SELECT CASE a_i Nt hSt r i ng CASE 0 @a_psCust omSt r i ng. szSt r i ng = "Si mpl e" @a_psCust omSt r i ng. i I D = 0 CASE 1 @a_psCust omSt r i ng. szSt r i ng = "S" @a_psCust omSt r i ng. i I D = 0 CASE 2 @a_psCust omSt r i ng. szSt r i ng = "Wei ght ed" @a_psCust omSt r i ng. i I D = 1 CASE 3 @a_psCust omSt r i ng. szSt r i ng = "W" @a_psCust omSt r i ng. i I D = 1 CASE ELSE MSXNt hCust omSt r i ng = %MSX_ERROR END SEL ECT CASE ELSE MSXNt hCust omSt r i ng = %MSX_ERROR END SELECT CASE ELSE MSXNt hCust omSt r i ng = %MSX_ERROR END SELECT END FUNCTI ON ' ' ' ' ' ' ' '

*********************************************************************** Thi s l ocal ut i l i t y f uncti on i s used t o hel p ensur e t hat no over f l ows or underf l ows wi l l occur dur i ng cal cul ati ons. The MSXTest pr ogr am St r ess Test f unct i on wi l l cal l your DLL wi t h a wi de r ange of val ues, i ncl udi ng posi t i ve and negat i ve val ues of FLT_MAX AND FLT_MI N. Per f or m al l i nt er medi at e cal cul at i ons usi ng doubl es and t hen f or ce t he r esul t s i nt o t he r ange of a si ngl e. ***********************************************************************

FUNCTI ON For ceFl oat Range ( BYVAL a_ l f Dbl AS DOUBLE) AS DOUBLE LOCAL s_ MaxSi ngl e AS DOUBLE LOCAL s_ Mi nSi ngl e AS DOUBLE s_ MaxSi ngl e = 3. 371E+38 s_Mi nSi ngl e = 8. 431E- 37 I F a_l f Dbl > 0. 0 THEN ' f orce pos num <= s_MaxSi ngl e a_l f Dbl = MI N ( a_l f Dbl , s_MaxSi ngl e) ' f or ce pos num >= s_Mi nSi ngl e a_l f Dbl = MAX ( a_l f Dbl , s_Mi nSi ngl e) ELSE I F a_l f Dbl < 0. 0 THEN ' f orce neg num >= - s_MaxSi ngl e a_l f Dbl = MAX ( a_l f Dbl , - s_MaxSi ngl e) ' f or ce neg num <= - s_Mi nSi ngl e a_l f Dbl = MI N ( a_l f Dbl , - s_Mi nSi ngl e) END I F END I F For ceFl oatRange = a_l f Dbl END FUNCTI ON ' - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - -' Thi s i s an exampl e of a l ocal f unct i on used f or cal cul at i ons. Thi s ' one cal cul at es a movi ng aver age on t he sour ce dat a arr ay, and put s ' t he r e sul t s i n t he r e sul t ar r ay. I t di f f er e nt i at e s i t s pr o ces si ng ' based on whet her t he movi ng aver age i s t o be wei ght ed or not . ' - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - SUB Movi ngAver age ( a_psSr c AS MSXDat aI nf oRec PTR, _  a_psRsl t AS MSXDat aI nf oRec PTR, _  BYVAL a_i Per i od AS LONG, _  BYVAL a_bI sWei ght ed AS LONG) LOCAL l _i I ndex AS LONG LOCAL l _i MaxI ndex AS LONG LOCAL l _l f Sum AS DOUBLE 72 • Sample DLL Programs

MetaStock ® 

LOCAL l _l f Dbl AS DOUBLE LOCAL l _f Di vi sor AS DOUBLE LOCAL i AS I NTEGER l _i I ndex = @a_psSr c. i Fi r stVal i d l _i MaxI ndex = @a_psSr c. i Last Val i d   l _ l f Sum = 0. 0 I F a_bI sWei ght ed = %TRUE THEN ' sum of t he di gi t s f or mul a l _f Di vi sor = CDBL(a_i Per i od) * ( CDBL(a_i Per i od) +1. 0) / 2. 0   ELSE l _f Di vi sor = CDBL(a_i Per i od) END I F l _f Di vi sor = CSNG( For ceFl oat Range ( l _f Di vi sor ) ) I F l _f Di vi sor = 0. 0 THEN l _ f Di vi sor = 1. 0 END I F WHI LE ( ( l _i I ndex + a_i Per i od - 1) <= l _i MaxI ndex)   l _ l f Sum = 0. 0 FOR i = 0 TO a_i Per i od- 1 I F a_bI sWei ght ed = %TRUE THEN   ' wei ght ed l _l f Sum = l _l f Sum + @a_psSr c. @pf Val ue[ l _i I ndex+i ] * ( i + 1. 0)   ELSE   ' si mpl e l _l f Sum = l _l f Sum + @a_psSr c. @pf Val ue[ l _i I ndex+i ] END I F NEXT i l _l f Sum = For ceFl oat Range( l _l f Sum) l _ l f Dbl = For c eFl oat Range( l _ l f Sum / l _ f Di vi s or ) @a_psRsl t . @pf Val ue[ l _i I ndex + a_i Per i od - 1] = CSNG( l _l f Dbl ) l _ i I ndex = l _ i I ndex + 1   WEND @a_psRsl t . i Fi rst Val i d = @a_psSr c. i Fi r stVal i d + a_i Peri od - 1 @a_psRsl t . i Last Val i d = l _i MaxI ndex END SUB ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - -- - - - - - ' The f ol l owi ng f unct i on demonst r at es use of t hree ar gument t ypes: ' MSXDat aAr r ay, MSXNumer i c and MSXCust om. ' A Movi ngAver age i s cal cul ated on t he i nput DataAr r ay f or i nput Peri ods. ' Thr ee movi ng aver age met hods ar e avai l abl e, s peci f i ed by t he Cust om I D. ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - -- - - - - - FUNCTI ON MyMov SDECL ALI AS " MyMov" ( _  a_psDat aRec AS MSXDat aRec PTR, _  a_psDat aI nf oAr gs AS MSXDat aI nf oRecAr gsAr r ay PTR, _  a_psNumer i cAr gs AS MSXNumer i cAr gsAr r ay PTR, _  a_psStr i ngAr gs AS MSXSt r i ngAr gsAr r ay PTR, _  a_psCust omAr gs AS MSXCust omAr gsAr r ay PTR, _  a_psResul t Rec AS MSXResul t Rec PTR) EXPORT AS LONG LOCAL l _bRt r n AS LONG ' We expect 3 ar gument s, 1 Dat aAr r ay, 1 Numer i c and 1 Cust om, i n t hat or der ' The argument s wi l l be f ound at :   ' Dat aAr r ay: @a_psDat aI nf oAr gs. psDat aI nf oRecs( 0)   ' Numer i c : @a_psNumer i cAr gs. f Numer i cs( 0) ;   ' Cust om : @a_psCust omAr gs. i Cust omI Ds( 0) ; LOCAL LOCAL LOCAL LOCAL LOCAL

l _psDat a AS MSXDat aI nf oRec PTR l _i Per i od AS LONG l _i Met hod AS LONG l _i I ndex AS LONG l _i MaxI ndex AS LONG

l _bRt r n = %MSX_SUCCESS I F ( @a_psDat aI nf oAr gs. i NRecs = 1 AND _  @a_psNumer i cAr gs. i NRecs = 1 AND _  @a_psCust omAr gs. i NRecs = 1) THEN l _psDat a = @a_psDat aI nf oAr gs. psDat aI nf oRecs( 0) ' t r uncat e any f r acti onal per i od l _i Per i od = FI X( @a_psNumeri cAr gs. f Numeri cs( 0) ) l _i Met hod = @a_psCust omAr gs. i Cust omI Ds( 0) MetaStock ® 

Sample DLL Programs • 73

l _i I ndex = @l _psDat a. i Fi r stVal i d l _i MaxI ndex = @l _psDat a. i Last Val i d I F ( l _i Per i od > 0 AND ( l _i I ndex + l _i Per i od - 1) <= l _i MaxI ndex) THEN SELECT CASE l _i Met hod CASE 0 ' Si mpl e CALL Movi ngAver age ( @l _psDat a, @a_psResul t Rec. @psResul t Ar r ay, _  l _i Per i od, %FALSE) CASE 1 ' Wei ght ed CALL Movi ngAver age ( @l _psDat a, @a_psResul t Rec. @psResul t Ar r ay, _  l _i Per i od, %TRUE) CASE ELSE ' Somehow we got cal l ed wi t h an i nval i d ar gument @a_psResul t Rec. sz Ext endedEr r or = " Undef i ned met hod ar gument " l _bRt r n = %MSX_ERROR ' r epor t t hi s AS an ERROR END SEL ECT   ELSE @a_psResul t Rec. @psResul t Ar r ay. i Fi r st Val i d = 0 @a_psResul t Rec. @psResul t Ar r ay. i Last Val i d = - 1 END I F ELSE ' wr ong number of ar gument s! @a_psResul t Rec. sz Ext endedEr r or = " Wr ong number of ar gument s" l _bRt r n = %MSX_ERROR END I F I F ( l _bRt r n <> %MSX_SUCCESS) THEN ' onl y f or ser i ous er r or s. . . @a_psResul t Rec. @psResul t Ar r ay. i Fi r st Val i d = 0 @a_psResul t Rec. @psResul t Ar r ay. i Last Val i d = - 1 END I F MyMov = l _bRt r n END FUNCTI ON

References See the following included source files for data structure definitions and additional examples: MSXStruc.h, MSXTmplt.cpp, CSampleDLL.c, MSXStruc.inc, MSXTmplt.pas, DelphiSampleDLL.pas, MSXStruc.bas, MSXTmplt.bas, and PBSampleDLL.bas.

74 • Sample DLL Programs

MetaStock ® 

MetaStock File Library (MSFL)

Introduction The MetaStock File Library (MSFL) Application Programming Interface (API)  provides developers with the tools necessary to integrate applications with the MetaStock data format. The MSFL API provides support for reading security names and price data. This manual contains the function descriptions and instructions necessary to access MetaStock data files using the MSFL. It assumes that the user is an experienced  programmer familiar with security price data and calling dynamic link library (DLL) functions. The primary function of the MSFL is to remove many of the complexities of accessing MetaStock data files from the application program through a set of easy-to-use functions.

What’s New The 9.0 version of the MSFL has only minor changes. The PowerBasic sample app for the MSFL and MSX uses the latest version (i.e. version 7.03). See the section titled “Change Record” on page 137 for details of all other changes.

Application Integration Using the MSFL DLL in your application is different for each development environment. Common to all development platforms is the need for Windows to locate and load the MSFL DLL. The MSFL DLL, in order of preference, should be copied to the Windows system directory, application directory, or other directory in the search  path. Note: The version of the MSFL DLL should be checked before overwriting an existing copy. Refer to the GetFileVersionInfo  function in the Win32™ SDK.

Below are basic instructions for several of the most common development environments. Refer to the development documentation for specifics on using it with third-party DLL’s.

C/C++ The following steps must be taken to create a C/C++ application that uses the MSFL DLL. 1. Set the include path for the msfl.h header file. Refer to the compiler documentation for the specifics of setting an include path. 2. Add the link library to the project. Link libraries for Microsoft Visual C++ 6.0 and Borland C++ Builder 4 are  provided. Refer to the compiler documentation for t he specifics of adding a library to the project. 3. If you are using a different compiler or the link libraries provided are incompatible with the compiler version you are using, you should be able to build the link libraries using the definition file (i.e. msfl.def ) and the tools provided with the compiler. For example, Visual C++ uses LI B with the / DEF switch, while Borland C++ Builder uses the I MPLI B utility program.

MetaStock ® 

MetaStock File Library (MSFL) • 75

Parameters ID

Description

cDirNumber  Identifies the directory. If zero, the path pointed to by  pszDirectory is used instead. The cDirNumber  is typically used to obtain the status of an open directory, while pszDirectory is typically used to obtain the status of a closed directory.

 pszDi rectory  Points to a null-terminated string that contains the directory. This pointer can be left null if the directory is specified by cDirNumber .

 psDirStatus

Points to an  MSFLDirectoryStatus_struct  structure ( page 101) that receives the directory status. The dwTotalSize  member must be set to the structure size before calling MSFL1_GetDirectoryStatus ( page 100).

Remarks • Gets the directory status information. • The directory can be specified either by cDirNumber or pszDirector y. For example, if the directory is open, the directory status can be retrieved by making the following call: MSFL1_Get Di r ect or ySt at us( cDi r Number , NULL, &sDi r St at us) . If the directory is not open, the directory status can be retrieved by making the following call: MSFL1_Get Di r ect or ySt at us( 0, szDi r ector y, &sDi r St at us) . • The MSFLDirectoryStatus_struct  structure is defined as follows: t ypedef st r uct { DWORD dwTot al Si ze; BOOL bExi st s; BOOL bI nUse; BOOL bMet aSt ockDi r ; WORD wDr i veType; BOOL bOpen; BOOL bReadOnl y; BOOL bUser I nval i d; char cDi r Number ; DWORD dwNumOf Secur i t i es ; } MSFLDi r ect or ySt at us_st r uct ; Fields ID

MetaStock ® 

Description

dwTotalSize bE xists bI nUse

The size of the structure, in bytes.

bMetaStockDir 

Boolean value indicating if the directory contains MetaStock files.

Boolean value indicating if the directory exists. Boolean value indicating if the directory is in use by one or more MSFL users.

MetaStock File Library (MSFL) • 101

ID

Description

wDriveType

The drive type, which can be any one of the following: • MSFL_DRIVE_TYPE_UNKNOWN The drive type is unknown. • MSFL_DRIVE_TYPE_REMOVABLE The drive is removable media. • MSFL_DRIVE_TYPE_FIXED The drive is fixed (i.e. a hard drive). • MSFL_DRIVE_TYPE_REMOTE The drive is remote (i.e. a network drive). • MSFL_DRIVE_TYPE_CD_ROM The drive is a local CD-ROM drive – network CD-ROM drives are reported as remote drives. • MSFL_DRIVE_TYPE_RAM_DISK The drive is a RAM disk.

bOpen bReadOnly

Boolean value indicating if the directory is open.

bUserI nvalid 

Boolean value indicating if the user is invalid. A user is invalid when another user with the same user ID is forced into the directory already in use by the current user. This field is only defined if the directory is open.

cDirNumber  dwNumOfSecurities

The directory number, if the directory is open.

Boolean value indicating if the directory is on read-only media. This field is only defined if the directory is open.

The number of securities in the directory, if the directory is open. Remember if the directory is not open, bReadOnly, bUserInvalid , cDirNumber , and dwNumOfSecurities are undefined. In other words, the directory must be open to determine if the directory is read-only.

See Also •   MSFL1_GetDataPath ( page 97), •   MSFL1_GetDirectoryNumber  ( page 99), •   MSFL1_GetSecurityCount  ( page 111) •   MSFL1_OpenDirectory ( page 119)

MSFL1_GetErrorMessage C LPSTR MSFL1_Get Er r or Message( i nt i Err , LPSTR psz Er r or Mess age, WORD wMaxMsgL engt h) Visual Basic MSFL1_Get Er r or Message( ByVal i Er r As Long, ByVal pszErr or Message As St r i ng, ByVal wMaxMsgLengt h As I nt eger ) As St r i ng Delphi MSFL1_Get Er r or Message( i Er r : i nt eger ; pszEr r or Message : LPSTR; wMaxMsgLengt h : WORD ) : LPSTR; PowerBASIC MSFL1_Get Err or Message( BYVAL i Err As Long, pszEr r or Message AS ASCI I Z, BYVAL wMaxMsgLengt h As Wor d) AS STRI NG Locking •  None

102 • MetaStock File Library (MSFL)

MetaStock ® 

Return Values • A pointer to the error message string. The pointer returned is the same as the pointer passed as the input argument  pszErrorMessage Parameters ID

Description

Indicates the MSFL error. iErr   pszE rr orM essage Points to a null-terminated string that receives the err or message. wMaxMsgLength Indicates the maximum message length that  pszErrorMessage  can receive, not including the terminating null. The maximum length error message that the MSFL will return is defined by MSFL_MAX_ERR_MSG_LENGTH.

Remarks • Returns a string error message for the specified MSFL error code. See Also •   MSFL1_GetLastFailedLockInfo ( page 105) •   MSFL1_GetLastFailedOpenDirInfo ( page 106)

MSFL1_GetFirstSecurityInfo C i nt MSFL1_Get Fi r st Secur i t yI nf o( char cDi r Number , MSFLSecur i t yI nf o_st r uct *psSecur i t yI nf o) Visual Basic MSFL1_Get Fi r st Secur i t yI nf o( ByVal cDi r Number As Byt e, psSecur i t yI nf o As MSFLSecur i t yI nf o_st r uct ) As Long Delphi MSFL1_Get Fi r st Secur i t yI nf o( cDi r Number : char; Var psSecur i t yI nf o : MSFLSecur i t yI nf o_st r uct ) : i nt eger ; PowerBASIC MSFL1_Get Fi r st Secur i t yI nf o( BYVAL cDi r Number AS BYTE, psSecur i t yI nf o AS MSFLSecur i t yI nf o_st r uct ) As Long Locking •  None Return Values • MSFL_MSG_LAST_SECURITY_IN_DIR  if successful and this security is the last security in the directory • MSFL_NO_ERR  if successful • MSFL_ERR_SECURITY_NOT_FOUND if the directory is empty

Parameters ID

cDirNumber   psSecurityI nfo

Description Identifies the directory. Points to an MSFLSecurityInfo_struct  structure ( page 82) that receives the security information. The  dwTotalSize member must be set to the structure size before calling MSFL1_GetFirstSecurityInfo .

Remarks • Gets the security information for the first security in the directory. Note: If the security is not locked when calling this function, the security information returned may not reflect changes made by another user. In addition, the starting and ending dates and times for composite securities may not reflect changes made to the primary or secondary securities.

MetaStock ® 

MetaStock File Library (MSFL) • 103

See Also •   MSFL1_GetLastSecurityInfo ( page 106) •   MSFL1_GetNextSecurityInfo ( page 108) •   MSFL1_GetPrevSecurityInfo ( page 109) •   MSFL1_GetSecurityInfo ( page 113) •   MSFL2_GetSecurityHandles ( page 125)

MSFL1_GetHourMinTicks C i nt MSFL1_ Get Hour Mi nTi cks ( WORD * pwHour , WORD * pwMi n, WORD * pwTi cks , l ong l Ti me) ; Visual Basic MSFL1_Get Hour Mi nTi cks( pwHour As I nt eger, pwMi n As I nt eger , pwTi cks As I nt eger, ByVal l Ti me As Long) As Long Delphi MSFL1_Get Hour Mi nTi cks( Var pwHour : wor d; Var pwMi n : wor d; Var pwTi cks : wor d; l Ti me : l ongi nt ) : i nt eger ; PowerBASIC MSFL1_Get Hour Mi nTi cks( pwHour As Word, pwMi n As Wor d, pwTi cks As Wor d, BYVAL l Ti me As Long) As Long Locking •  None Return Values • MSFL_NO_ERR  if successful • MSFL_ERR_INVALID_TIME if the time is invalid

Parameters ID

Description

 pwH our 

Points to a WORD that receives the hour. The hour is always in 24-hour format.

 pwMi n  pwTicks lTime

Points to a WORD that receives the minutes. Points to a WORD that receives the ticks. The MSFL time to be extracted.

Remarks • Extracts an MSFL time into its components: hour, minutes and ticks. See Also •   MSFL1_FormatTime ( page 95) •  MSFL1_GetDayMonthYear  ( page 98) •   MSFL1_MakeMSFLTime ( page 118)

104 • MetaStock File Library (MSFL)

MetaStock ® 

Parameters ID

Description

hSecurity   piL ockStatus

Identifies the security.

 puiL ockType

Points to an UINT that receives the lock type. Following are the possible lock types. • MSFL_LOCK_PREV_WRITE_LOCK The security is prevent write locked. • MSFL_LOCK_WRITE_LOCK The security is write locked. • MSFL_LOCK_FULL_LOCK The security is full locked.

Points to an integer that receives the lock status. Following are the possible lock status codes. • MSFL_LOCK_STATUS_UNLOCKED The security is not locked by this user or any other user. • MSFL_LOCK_STATUS_LOCKED_CURRENT The security is locked by this user. • MSFL_LOCK_STATUS_LOCKED_OTHER The security is locked by another user. • MSFL_LOCK_STATUS_LOCKED_COMP_CUR The security is locked as part of a composite security by this u ser. • MSFL_LOCK_STATUS_LOCKED_COMP_OTH The security is locked as part of a composite security by another user.

Remarks • Gets the lock status of the specified security. See Also •   MSFL1_LockSecurity ( page 116) •   MSFL1_UnlockSecurity ( page 124)

MSFL1_Initialize C i nt MSFL1_I ni t i al i ze( LPCSTR pszAppName, LPCSTR pszUser Name, i nt i I nt er f ac eVer s i on) Visual Basic MSFL1_ I ni t i al i ze( ByVal ps zAppName As St r i ng, ByVal psz User Name As St r i ng, ByVal i I nt er f aceVer si on As Long) As Long Delphi MSFL1_ I ni t i al i ze( ps zAppName : LPCSTR; pszUser Name : LPCSTR; i I nt er f ac eVer s i on: i nt eger ) : i nt eger ; PowerBASIC MSFL1_ I ni t i al i ze( ps zAppName AS ASCI I Z, pszUser Name AS ASCI I Z, BYVAL i I nt er f aceVer si on As Long) As Long Locking •  None Return Values • MSFL_NO_ERR  if successful • MSFL_ERR_ALREADY_INITIALIZED if the MSFL is currently initialized • MSFL_ERR_INSUFFICIENT_MEM if there is insufficient memory to initialize the MSFL • MSFL_ERR_INVALID_USER_ID if the application name and/or user name are invalid MetaStock ® 

MetaStock File Library (MSFL) • 115

Parameters ID

Description

 pszAppName

Points to a null-terminated string that contains the application name. The maximum length of the application name is defined by MSFL_MAX_APP_NAME_LENGTH.

 pszUserN ame

Points to a null-terminated string that contains the user name. The maximum length of the user name is defined by MSFL_MAX_USER_NAME_LENGTH.

iI nterfaceVersi on Indicates the MSFL DLL interface version. The current DLL interface version is defined by MSFL_DLL_INTERFACE_VERSION and can simply be passed into the MSFL1_Initialize function.

Remarks • Initializes the MetaStock File Library by creating the internal tables and buffers. Once the MSFL is successfully initialized, it cannot be initialized again without first shutting down. Also, if the application successfully initializes the MSFL, it must shut down the MSFL (via MSFL1_Shutdown ( page 124)  before exiting. Failure to do so may cause corruption of files and memory leaks. It may also keep directories open and securities locked. • The application and user names constitute the MSFL user ID. The MSFL user ID is used to distinguish between users in a data directory. By including the application name, the same user can access the same directory with two different applications (e.g. MetaStock and The DownLoader). Note: Before calling this function, you must setup the key structure as documented in the Initialization section ( page 87).

See Also •   MSFL1_GetMSFLState ( page 107) •   MSFL1_Shutdown ( page 124)

MSFL1_LockSecurity C i nt MSFL1_LockSecur i t y( HSECURI TY hSecur i t y, UI NT ui LockType) Visual Basic MSFL1_ Loc kSec ur i t y( ByVal hSec ur i t y As Long, ByVal ui LockType As Long) As Long Delphi MSFL 1_ Loc kSec ur i t y( hSec ur i t y : HSECURI TY; ui LockType : UI NT) : i nt eger ; PowerBASIC MSFL1_LockSecur i t y( BYVAL hSecur i t y AS DWORD, BYVAL ui Loc kType AS DWORD) As Long Locking •  None Return Values • MSFL_NO_ERR  if successful • MSFL_ERR_TOO_MANY_SEC_LOCKED if the application attempted to lock more than the maximum number of securities (i.e. MSFL_MAX_LOCKED_SECURITIES) • MSFL_ERR_SECURITY_LOCKED if the security is locked by this or another application

116 • MetaStock File Library (MSFL)

MetaStock ® 

Parameters ID

Description

hSecurity  uiLockType

Identifies the security to lock. Specifies the lock type. Applications reading MetaStock price data can simply pass MSFL_LOCK_PREV_WRITE_LOCK.

Remarks • Locks the specified security. For more information on security locking and the lock types, see Security Locking ( page 87). • An application cannot concurrently lock the same security multiple times. Nor can an application lock more than the maximum number of locked securities per application (i.e. MSFL_MAX_LOCKED_SECURITIES). Note: When locking composite securities, the primary and se condary securities are also locked. In addition, composite securities cannot be write locked.

See Also •   MSFL1_GetLastFailedLockInfo ( page 105) •   MSFL1_GetSecurityLockedStatus ( page 114) •   MSFL1_UnlockSecurity ( page 124)

MSFL1_MakeMSFLDate C i nt MSFL1_MakeMSFLDat e( l ong * pl Dat e, WORD wMont h, WORD wDay, WORD wYear ) ; Visual Basic MSFL1_MakeMSFLDat e( pl Dat e As Long, ByVal wMont h As I nt eger , ByVal wDay As I nt eger , ByVal wYear As I nt eger) As Long Delphi MSFL 1_ MakeMSFL Dat e( Var pl Dat e : l ongi nt ; wMont h : wor d; wDay : wor d; wYear : wor d) : i nt eger ; PowerBASIC MSFL1_MakeMSFLDat e( pl Dat e As Long, BYVAL wMont h As Wor d, BYVAL wDay As Wor d, BYVAL wYear As Wor d) As Long Locking •  None Return Values • MSFL_NO_ERR  if successful • MSFL_ERR_INVALID_DATE if the constructed date is invalid

Parameters ID

 plDate wMonth wDay 

MetaStock ® 

Description Points to a long that receives the MSFL date. The month; January = 1, February = 2, and so on. The day of the month.

MetaStock File Library (MSFL) • 117

ID

Description

wYear 

The year. The year can be two or four digits. If the year is two digits, the Windows cutoff year is used to determine the century. If the Windows cutoff year is not found in the registry, a default cutoff year of twenty-nine is used. In other words, if the two-digit year is less than or equal to twenty-nine,  MSFL1_MakeMSFLDate ( page 117) will assume the century to be 2000. If the two-digit year is greater than twenty-nine, a century of 1900 will be assumed.

Remarks • Constructs an MSFL date from its components: day, month and year. See Also •   MSFL1_FormatDate ( page 94) •  MSFL1_GetDayMonthYear  ( page 98) •   MSFL1_MakeMSFLTime ( page 118) , •   MSFL1_ParseDateString  ( page 120)

MSFL1_MakeMSFLTime C i nt MSFL1_MakeMSFLTi me( l ong *pl Ti me, WORD wHour , WORD wMi n, WORD wTi cks ) ; Visual Basic MSFL1_MakeMSFLTi me( pl Ti me As Long, ByVal wHour As I nt eger , ByVal wMi n As I nt eger , ByVal wTi cks As I nt eger ) As Long Delphi MSFL1_MakeMSFLTi me( Var pl Ti me : l ongi nt ; wHour : wor d; wMi n : wor d; wTi cks : wor d) : i nt eger ; PowerBASIC MSFL1_MakeMSFLTi me( pl Ti me As Long, BYVAL wHour As Wor d, BYVAL wMi n As Wor d, BYVAL wTi cks As Word) As Long Locking •  None Return Values • MSFL_NO_ERR  if successful • MSFL_ERR_INVALID_TIME if the constructed time is invalid

Parameters ID

 plTime wHour  wMin wTicks

Description Points to a long that receives the MSFL time. The hour; must be in 24-hour format. The minutes. The ticks. In cases where the ticks are unknown or not relevant, pass in zero for the ticks.

Remarks • Constructs an MSFL time from its components: hour, minutes and ticks.

118 • MetaStock File Library (MSFL)

MetaStock ® 

See Also •   MSFL1_FormatTime ( page 95) •   MSFL1_GetHourMinTicks ( page 104) •   MSFL1_MakeMSFLDate ( page 117) •  MSFL1_ParseTimeString  ( page 121)

MSFL1_OpenDirectory C i nt MSFL1_OpenDi r ect or y( LPCSTR pszDi r ect or y, char * pcDi r Number , i nt i Di r OpenFl ags) Visual Basic MSFL 1_ OpenDi r e ct or y ( ByVal ps z Di r e ct or y As St r i ng, pcDi r Number As Byt e, ByVal i Di r OpenFl ags As Long) As Long Delphi MSFL1_OpenDi r ectory( pszDi r ectory : LPCSTR; Var pcDi r Number : char ; i Di r OpenFl ags : i nt eger ) : i nt eger ; PowerBASIC MSFL 1_ OpenDi r e ct or y ( ps z Di r e ct or y AS ASCI I Z, pcDi r Number AS BYTE, BYVAL i Di r OpenFl ags As Long) As Long Locking •  None Return Values • MSFL_MSG_NOT_A_METASTOCK_DIR  if successful, but the directory does not contain MetaStock files • MSFL_NO_ERR  if successful • MSFL_ERR_DIR_ALREADY_OPEN if the application has the directory open and the MSFL_DIR_ALLOW_MULTI_OPEN flag was not passed to the open file • MSFL_ERR_DIR_DOES_NOT_EXIST if the directory does not exist • MSFL_ERR_DUPLICATE_SECURITIES if there are duplicate securities in the directory and the MSFL_DIR_MERGE_DUP_SECS flag was not passed to the open • MSFL_ERR_INVALID_DIR  if the directory is invalid • MSFL_ERR_TOO_MANY_DIRS_OPEN if the application has opened the maximum number of directories (i.e. MSFL_MAX_OPEN_DIRECTORIES) • MSFL_ERR_USER_ID_ALREADY_IN_DIR  if a user with the same application and user name has the directory open and the MSFL_DIR_FORCE_USER_IN flag was not passed to the open

Parameters ID

 pszDi rectory   pcDirN umber 

MetaStock ® 

Description Points to a null-terminated string that contains the directory to open. Points to a character that r eceives the directory number. The directory number can be thought of a handle to the open directory. If the open fails, the directory number is set to zero.

MetaStock File Library (MSFL) • 119

-172: MSFL_ERR_INVALID_PERIODICITY The periodicity is invalid. -171: MSFL_ERR_INVALID_OPERATOR The composite operator is invalid. -170: MSFL_ERR_INVALID_FIELD_ORDER The data fields used are not in the same order as documented on page 80. -169: MSFL_ERR_INVALID_RECORDS The record numbers are not within a valid range for the operation. -168: MSFL_ERR_INVALID_DISPLAY_UNITS The display units are outside the valid range. -167: MSFL_ERR_INVALID_SECURITY_HANDLE The security handle is not valid. -150: MSFL_ERR_ADDING_WOULD_OVERFLOW Inserting or adding records would exceed the maxi mum number of records that can  be stored. -149: MSFL_ERR_DATA_FILE_IS_FULL The price data file is full. -148: MSFL_ERR_DATA_RECORD_NOT_FOUND A matching price record was not found for the date/time. -147: MSFL_ERR_DATA_NOT_SORTED The price data is not in date/time sort order. -146: MSFL_ERR_DATE_AFTER_LAST_REC The date/time requested is after the date/time of the last price record. -145: MSFL_ERR_DATE_BEFORE_FIRST_REC The date/time requested is before the date/time of the first price record. -144: MSFL_ERR_RECORD_IS_A_DUPLICATE The record duplicates an existing record. -143: MSFL_ERR_RECORD_OUT_OF_RANGE The record number is out of range. -142: MSFL_ERR_RECORD_NOT_FOUND The security record was not found – most likely an invalid security handle. -125: MSFL_ERR_BUFFER_NOT_ATTACHED A composite buffer was not attached to the locked composite. -124: MSFL_ERR_INVALID_FUNC_PARMS One or more of the function parameters are invalid. -123: MSFL_ERR_UNKNOWN_FIELDS_REQ The number of data fields used is below the minimum or above the maximum. -100: MSFL_ERR_INVALID_FUNCTION_CALL The MSFL DLL is not initialized correctly to perform the request function call. Refer to the “Initialization” section ( page 87) for details on initializing the MSFL DLL. 0: MSFL_NO_ERR Operation completed successfully.

MetaStock ® 

MetaStock File Library (MSFL) • 135

Message Codes The following is list of the possible message codes that can be returned from some MSFL functions. The message codes are positive return codes; whereas the error codes are negative return codes. Thus, if an MSFL function is successful the error will be equal to or greater than MSFL_NO_ERR.

0: MSFL_NO_MSG  No message. 1: MSFL_MSG_NOT_A_MetaStock_DIR  Not a MetaStock data directory. 2: MSFL_MSG_CREATED_DIR Created directory. 3: MSFL_MSG_BUILT_MetaStock_DIR Created empty MetaStock files in the directory. 4: MSFL_MSG_CREATED_N_BUILT_DIR Created directory and empty MetaStock files. 5: MSFL_MSG_FIRST_SECURITY_IN_DIR This is the first security in the directory. 6: MSFL_MSG_LAST_SECURITY_IN_DIR This is the last security in the directory. 25: MSFL_MSG_NOT_AN_EXACT_MATCH The record found was not an exact match. 50: MSFL_MSG_OVERWROTE_RECORDS Overwrote existing records. 51: MSFL_MSG_LESS_RECORDS_DEL Fewer records were deleted than requested. 52: MSFL_MSG_LESS_RECORDS_READ Fewer records were read than requested. 53: MSFL_MSG_MORE_RECORDS_IN_RANGE There are more records within the specified date range.

136 • MetaStock File Library (MSFL)

MetaStock ® 

Change Record The following section lists (in reverse version order) a short description of all changes made in earlier versions of the MSFL and the MSFL Developer’s Kit.

Changes in Vers ion 9.0 The 9.0 version of the MSFL has only minor changes. • The PowerBasic sample app for the MSFL and MSX uses the latest version (i.e., version 7.03).

Changes in Vers ion 8.0 • The maximum number of securities per directory (i.e. MSFL_MAX_NUM_OF_SECURITIES) was increased from 2,000 to 6,000. • A few minor problems were fixed.

Changes in Vers ion 7.2 • The performance was increased for many operations. • The following functions were added:

•   MSFL1_FormatDate ( page 94) •   MSFL1_FormatTime ( page 95) •  MSFL1_GetDayMonthYear  ( page 98) •   MSFL1_GetHourMinTicks ( page 104) •   MSFL1_MakeMSFLDate ( page 117) •  MSFL1_MakeMSFLTime ( page 118) •   MSFL1_ParseDateString  ( page 120) •  MSFL1_ParseTimeString  ( page 121) • A PowerBASIC sample was added. • A C console sample was added. • Project/make files are provided for the Visual C++ 6.0, Borland C++ Builder 4, and gcc 2.95.2 compilers. • A few minor problems were fixed.

Changes in Vers ion 7.0 • A Borland C++ Builder sample was added. • A few minor problems were fixed.

Changes i n Versi on 6.51 • The allowed date range was expanded from the 1900’s to include the 1800’s and up to 31 December 2200. The new valid date range is from 1 January 1800 to 31 December 2200. • The tick count for all times was increased from two digits to three digits. See the Formats section ( page 79) for details on the new time format. • The maximum number of price records per security (i.e. MSFL_MAX_DATA_RECORDS) was increased from 32,766 to 65,500. • The maximum number of price records per read/write (i.e. MSFL_MAX_READ_WRITE_RECORDS) was increased from 32,766 to 65,500. • A new flag (i.e. MSFL_DIR_ALLOW_MULTI_OPEN) was added to the “MSFL1_OpenDirectory” function allowing a folder to be opened more than once. See MSFL1_OpenDirectory ( page 119) for details. • The Visual Basic types and Delphi records were changed to match t he documentation as well as the C/C++ structures.

MetaStock ® 

MetaStock File Library (MSFL) • 137

Changes in Vers ion 6.5 • The maximum number of securities per directory (i.e. MSFL_MAX_NUM_OF_SECURITIES) was increased from 255 to 2,000. • The maximum length of a security name (i.e. MSFL_MAX_NAME_LENGTH) was increased from 16 to 45 characters. • The maximum number of price records per read/write (i.e. MSFL_MAX_READ_WRITE_RECORDS) was increased from 1,927 to 32,766. • Universal naming convention (UNC) and long file names support was added. • The library was converted from a C l ibrary to a 32-bit DLL t o allow access via Visual Basic, Delphi, and other development environments. • Security handles replaced data requests and extended symbols. • String error messages were added. • Structure types where changed for 32-bit. • A total size member was added to many of the structures. • The following functions were added:

•   MSFL1_GetDirNumberFromHandle ( page 100) •   MSFL1_GetErrorMessage ( page 102) •   MSFL1_GetSecurityHandle ( page 111) •   MSFL1_GetSecurityID ( page 112) •   MSFL2_GetSecurityHandles ( page 125)

138 • MetaStock File Library (MSFL)

MetaStock ® 

MSFL Index A

MSFL1_GetDirectoryNumber  99 MSFL1_GetDirectoryNumber 99 MSFL1_GetDirectoryStatus 100 MSFL1_GetDirNumberFromHandle 100 MSFL1_GetErrorMessage 102 MSFL1_GetFirstSecurityInfo 103 MSFL1_GetHourMinTicks 104 MSFL1_GetLastFailedLockInfo 87, 105 MSFL1_GetLastFailedOpenDirInfo 106 MSFL1_GetLastSecurityInfo 106 MSFL1_GetMSFLState 107 MSFL1_GetNextSecurityInfo 108 MSFL1_GetPrevSecurityInfo 109 MSFL1_GetRecordCountForDateRange 110 MSFL1_GetSecurityCount 111 MSFL1_GetSecurityHandle 111 MSFL1_GetSecurityID 112 MSFL1_GetSecurityInfo 113 MSFL1_GetSecurityLockedStatus 114 MSFL1_Initialize 115 MSFL1_LockSecurity 116 MSFL1_MakeMSFLDate 117 MSFL1_MakeMSFLTime 118 MSFL1_OpenDirectory 119 MSFL1_ParseDateString 120 MSFL1_ParseTimeString 121 MSFL1_ReadDataRec 122 MSFL1_SeekBeginData 123 MSFL1_SeekEndData 123 MSFL1_Shutdown 87, 124 MSFL1_UnlockSecurity 124 MSFL2_GetSecurityHandles 125 MSFL2_ReadBackMultipleRecs 126 MSFL2_ReadDataRec 127 MSFL2_ReadMultipleRecs 128 MSFL2_ReadMultipleRecsByDates 129

Application development C/C++ 75 Delphi 76 PowerBASIC 76 Visual Basic 76

C CD-ROM support 79 Composite 78  primary security 78 record numbers 78 secondary security 78

D data field mnemonics 80, 84 Data Types in MSFL 81

Date Time structure 81 Dates 79 Directory closing 87 number 87 number  87 opening 87 DOP files 79

Duplicate securities 120

duplicate securities 88

E Error  codes 88, 131 handling 88

H HSECURITY 81, 112

F

I

Field combinations 80 File

Initialize 87, 116

reserved names 79 types 79

function levels in MSFL 77 Functions MSFL1_CloseDirectory 92 MSFL1_FindDataDate 92 MSFL1_FindDataRec 93 MSFL1_FormatDate 94 MSFL1_FormatTime 95 MSFL1_GetCurrentDataPos 96 MSFL1_GetDataPath 97 MSFL1_GetDataRecordCount 97 MSFL1_GetDayMonthYear 98 MSFL1_GetDayMonthYear  98 MetaStock ® 

key 87

L Library key 87 Lock types 87 full 78, 87  prevent write 78, 87 write 78, 87

Locking composite 87 directory 78 security 78, 87 lTime 81

MetaStock etaStock File Library Library (MSFL) (MSFL) • 139

M

Return codes. See Error codes.

Message codes 88, 136 MSFL data types 81 MSFL function levels 77 MSFL functions

Secondary security 78 Securities

listed by name 89 listed by type 90 MSFL notations 81

composite 78 duplicate 88, 120 Security handle 81

MSFL_DISPLAY_UNITS_DECIMAL 83 MSFL_DLL_INTERFACE_VERSION 116 MSFL_ERR_MSFL_CORRUPT 88 MSFL_ERR_NON_MSFL_USER_IN_DIR 106 MSFL_LOCK_FULL_LOCK 87 MSFL_LOCK_PREV_WRITE_LOCK 87 MSFL_LOCK_WRITE_LOCK 87 MSFL_MAX_APP_NAME_LENGTH 116 MSFL_MAX_DISPLAY_UNITS 83 MSFL_MAX_INTERVAL 83 MSFL_MAX_NAME_LENGTH 83 MSFL_MAX_READ_WRITE_RECORDS 129 MSFL_MAX_SYMBOL_LENGTH 80, 83 MSFL_MAX_USER_NAME_LENGTH 116 MSFL_MIN_DISPLAY_UNITS 83 MSFL_MIN_INTERVAL 83 MSFL_MSG_NOT_A_METASTOCK_DIR 120 MSFL_NO_ERR 88 MSFL_VALID_OPERATORS 83 MSFL_VALID_PERIODICITIES 83 MSFL1_GetErrorMessage 102 MSFL1_Initialize, described 115 MSFLDirectoryStatus_struct 101

Security identifier structure 112 Security information structure 82 Shutdown 87, 124 Structures

S

date time 81  price record 84 security information 82 Symbol 80

T Technical support 77 Times 79

V variable notation 81

W wDataAvailable 80, 84, 85

defined 101

MSFLSecurityIdentifier_struct 112 defined 112

Multi-user 78

N notations used by the MSFL 81

P Price data 80 field combinations 80 mnemonics 80 Price record structure 84

Primary security 78  psLastDate 130

R Removable media 77 140 • MetaSto MetaStock ck File Libra Library ry (MSFL) (MSFL)

MetaStock ® 

Index Symbols ~MSXIMPORTDLLS~ 16

A Advise Callbacks, DDE 19 Advise Requests, DDE 19 Application development C/C++ 75 Delphi 76 PowerBASIC 76 samples 3 Visual Basic 76 Application, DDE 17, 18

Argument range tests 53 Ask, DDE Item 18 Asksize, DDE Item 18

B Bid, DDE Item 18 Bidsize, DDE Item 18 Borland C++ 5.0 Creating an MSX DLL 43 Debugging an MSX DLL 46

Borland C++ Builder 4.0 Creating an MSX DLL 41 Debugging an MSX DLL 46

Borland Delphi Pascal Creating an MSX DLL 43 Debugging an MSX DLL 46

C C Creating an MSX DLL 40, 41, 43 Debugging an MSX DLL 45, 46 Sample DLL Program 63 Calculation Functions 30

Calculation Structures 35 MSXDataInfoRec 35 MSXDataRec 36 MSXDateTime 35 CD-ROM support 79

CF_TEXT 18, 20 Change, DDE Item 18 closing EqDdeSrv with active conversations 19 MetaStock ® 

Cold-link 17, 19 Command line switches in EqCustUI 12 compatibility of Formula Organizer  14 compilers supported 2 Composite 78  primary security 78 record numbers 78 secondary security 78 Connections, DDE 19

Copyright information 13, 15 custom strings, and partial matches 34 Custom toolbar  5

D Data Data Array 56 Price Data 58 Sample 48 Types 31

data array Argument range 53 tests Max/Min 52

Special Case 52 data field mnemonics 80, 84 Data Requests, DDE 19 Data Server 17 Data Types 31 Dates 31 in MSFL 81 Strings 31 Times 31

Date Time structure 81 Date, DDE Item 18 Dates 79 DDE Advise Callbacks 19 DDE Advise Requests 19 DDE Application 17, 18 DDE Connections 19 DDE Data Requests 19 DDE Item 17 Ask 18 Asksize 18 Bid 18 Bidsize 18 Index • 141

Change 18 Date 18 High 18 Last 18 Low 18 Open 18 Openint 18 Prevclose 18 Time 18 Totalvol 18 Tradevol 18 Ydtotalvol 18 DDE Server 17

External Function DLL folder  16 ExtFml 26, 32, 34

DDE Service 17 DDE System Requests 19 DDE System Topic 19, 20

Formats, DDE System Topic 20 Formorg.exe, detecting multiple versions 16 Formula organizer  13

Formats 20 Status 20 SysItems 20 TopicItemList 20 DDE Topic 17, 18

Directory closing 87 number 87 opening 87

distributing your MSX DLL 60 DOP files 79 Duplicate securities 120

duplicate securities 88

E EqCustUI 5 C/C++ example 6 locking MetaStock files 5 EqCustUI utility 5

EqDatSrv 17 EqDatSrv Updates 19 EqDatSrv.exe 17 EqDdeSrv, closing with active conversations 19 EqDdeSrv.exe 17 Equis Data Server  17 Equis Dynamic Data Exchange Server  17 Error  codes 88, 131 codes in EqCustUI 12 handling 88 Excel 17 DDE Example for 20

Export DLLs 13 formula-based tools 13 templates 13

142 • Index

F Field combinations 80 File reserved names 79 types 79

Folder  ~MSXIMPORTDLLS~ 16 External Function DLLs 16

exporting 14

Formula Organizer compatibility 14 FOSetup.exe 15, 16 Function Argument Structures 38 MSXCustomArgsArray 39 MSXDataInfoRecArgsArray 38 MSXNumericArgsArray 39 MSXResultRec 39 MSXStringArgsArray 39 function levels in MSFL 77

Functions MSFL1_CloseDirectory 92 MSFL1_FindDataDate 92 MSFL1_FindDataRec 93 MSFL1_FormatDate 94 MSFL1_FormatTime 95 MSFL1_GetCurrentDataPos 96 MSFL1_GetDataPath 97 MSFL1_GetDataRecordCount 97 MSFL1_GetDayMonthYear 98 MSFL1_GetDirectoryNumber 99 MSFL1_GetDirectoryStatus 100 MSFL1_GetDirNumberFromHandle 100 MSFL1_GetErrorMessage 102 MSFL1_GetFirstSecurityInfo 103 MSFL1_GetHourMinTicks 104 MSFL1_GetLastFailedLockInfo 87, 105 MSFL1_GetLastFailedOpenDirInfo 106 MSFL1_GetLastSecurityInfo 106 MSFL1_GetMSFLState 107 MSFL1_GetNextSecurityInfo 108 MSFL1_GetPrevSecurityInfo 109 MSFL1_GetRecordCountForDateRange 110 MSFL1_GetSecurityCount 111 MSFL1_GetSecurityHandle 111 MSFL1_GetSecurityID 112 MSFL1_GetSecurityInfo 113 MSFL1_GetSecurityLockedStatus 114 MSFL1_Initialize 115 MSFL1_LockSecurity 116 MSFL1_MakeMSFLDate 117 MSFL1_MakeMSFLTime 118

MetaStock ® 

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close