PureBytes Links
Trading Reference Links
|
William,
I have taken the liberty of copying my reply to the list as it might just
help others.
Power Basic has a user manual that is downloadable or at least I think it
is. They also have a number of examples on their web site. There is also a
book available for free - PC Magazine's BASIC Techniques and Utilities.
Can't remember if this is downloaded separately or comes when you purchase
Power Basic 32 bit DLL. Can't say I've really needed either - It's truly
that straight forward.
I'd also have a look at Kaufman's book Trading systems and methods - this
will give you a good source of formulae etc. They are often laid out for
TradeStation so they will translate fairly easily into PowerBasic. For
mathematical methods, I'd heartily recommend Numerical Recipes from
Cambridge University Press http://www.nr.com/. Mathematical purists often
quibble over some of the implementations, but for the sums I do it's fine.
Years ago, there used to be a version of it for basic. You might find one on
e-Bay or similar and it would be worth purchasing if you are thinking of
serious computation.
I have attached a copy of the code for the 32 bit version of the T3 moving
average as a straightforward example. I use the code as as a template for my
own work as some of the bits are standard e.g. Libmain and Wep
You'll notice, that there are two calls to the DLL - the first is the
initialisation, and the second does the calculation on each bar.
Shout if I can help further.
' ============================
' DLL Compiler Directives =
' ============================
$DEBUG ERROR ON ' No compile time symbolic debug.
$COMPILE DLL ' Compile to DLL rather than EXE.
' $HUGE ' Let arrays be > 64K.
$DIM ALL ' Declare variables before use.
$OPTION VERSION4 ' Compatible with Windows NT, 2000.
' =============================
' Declare Global Variables =
' =============================
GLOBAL INDAT AS SINGLE ' Price.
GLOBAL T3PER AS SINGLE ' T3 period.
GLOBAL T3SMO AS SINGLE ' T3 smoothing coefficient.
' Working variables for the T3 MA.
GLOBAL B2 AS DOUBLE
GLOBAL B3 AS DOUBLE
GLOBAL E1 AS DOUBLE
GLOBAL E1P AS DOUBLE ' E1 on previous pass.
GLOBAL E2 AS DOUBLE
GLOBAL E2P AS DOUBLE ' E2 on previous pass.
GLOBAL E3 AS DOUBLE
GLOBAL E3P AS DOUBLE ' E3 on previous pass.
GLOBAL E4 AS DOUBLE
GLOBAL E4P AS DOUBLE ' E4 on previous pass.
GLOBAL E5 AS DOUBLE
GLOBAL E5P AS DOUBLE ' E5 on previous pass.
GLOBAL E6 AS DOUBLE
GLOBAL E6P AS DOUBLE ' E6 on previous pass.
GLOBAL C1 AS DOUBLE
GLOBAL C2 AS DOUBLE
GLOBAL C3 AS DOUBLE
GLOBAL C4 AS DOUBLE
GLOBAL F1 AS DOUBLE
GLOBAL F2 AS DOUBLE
GLOBAL T3AVE AS DOUBLE ' Final calculated T3 MA.
GLOBAL T3ADR AS DWORD ' Addr. of T3AVE in calling prog.
GLOBAL SINPTR AS SINGLE PTR ' Pointer for a 4 byte float.
' =====================
' Function LibMain =
' =====================
' Function LibMain is run once by Windows when it loads this DLL.
' This function definition is the same for any DLL. Certain other
' run-once code can be put here as well, like initializing global
' objects.
FUNCTION LIBMAIN(BYVAL hInstance AS LONG, _
BYVAL Reason AS LONG, _
BYVAL Reserved AS LONG) _
EXPORT AS LONG
LIBMAIN = 1 ' 1 tells WIN that load
' was a success.
END FUNCTION
' ====================
' Function T3INIT =
' ====================
FUNCTION T3INIT (BYVAL T3PER AS SINGLE, BYVAL T3SMO AS SINGLE)_
EXPORT AS INTEGER
' Init the MA variables.
B2 = T3SMO * T3SMO
B3 = T3SMO * T3SMO * T3SMO
C1 = -B3
C2 = 3 * B2 + 3 * B3
C3 = -6 * B2 - 3 * T3SMO - 3 * B3
C4 = 1 + 3 * T3SMO + B3 + 3 * B2
F1 = 2 / (T3PER + 1)
F2 = 1 - F1
FUNCTION = 1 ' Return a dummy integer value.
END FUNCTION
' ====================
' Function T3CALC =
' ====================
FUNCTION T3CALC (BYVAL INDAT AS SINGLE, BYVAL T3PER AS SINGLE,_
BYVAL T3SMO AS SINGLE, BYVAL T3ADR AS DWORD)_
EXPORT AS INTEGER
' Do the MA calculation.
E1 = F1 * INDAT + F2 * E1P
E2 = F1 * E1 + F2 * E2P
E3 = F1 * E2 + F2 * E3P
E4 = F1 * E3 + F2 * E4P
E5 = F1 * E4 + F2 * E5P
E6 = F1 * E5 + F2 * E6P
T3AVE = C1 * E6 + C2 * E5 + C3 * E4 + C4 * E3
SINPTR = T3ADR ' Copy EL float address to pointer variable.
@SINPTR = T3AVE ' Send the float to the EL calling program.
' This is previous bar values for next pass.
E1P = E1
E2P = E2
E3P = E3
E4P = E4
E5P = E5
E6P = E6
FUNCTION = 1 ' Return a dummy integer value.
END FUNCTION
' =================
' Function Wep =
' =================
' Function WEP tells Windows to unload this DLL. This function
' definition is the same for any DLL. Certain other run-once
' code can be put here as well, like de-allocating objects.
FUNCTION Wep (BYVAL nParameter AS INTEGER) EXPORT AS WORD
Wep = 1 ' Tells WIN that unload
' was a success.
END FUNCTION
' ===============
' End Of DLL =
' ===============
|