Friday, November 2, 2007

Forex Trading System- Visual Basic source code for forex traders

Option Explicit

Global Const MAX_QUOTES = 8000
Global Const MAX_CLOSES = MAX_QUOTES * 4
Global Const UP = 1
Global Const DOWN = -1
Global Const vbLightGray = &HC0C0C0
Global Const vbGray = &H808080
Global Const vbLightYellow = &HC0FFFF

Type QUOTE_TYPE
Date As String
Time As String
O As Double
H As Double
L As Double
C As Double
U As Double
D As Double
End Type
331
Global NumQuotes As Long
Global NumCloses As Long
Global NumColumns As Long
Global Pair$, StartDate$, EndDate$
Global BoxSize As Double, RevAmt As Double
Global Q(MAX_QUOTES) As QUOTE_TYPE
Global C(MAX_QUOTES) As Double
Global Column(MAX_CLOSES) As Integer

Public Function CalculateColumns(C#(), NumCloses&, BoxSize#, RevAmt#) As Integer
Dim i&, col&, start#, last#, direction%

On Error GoTo Err_CalculateColumns

' initialize the global column array

For i = 1 To NumCloses
Column(i) = 0
Next i
last = C(1)

' calculate first value of column array

For i = 2 To NumCloses
If C(i) - last >= RevAmt * BoxSize Then
Do
If last + BoxSize > C(i) Then
Exit Do
End If
last = last + BoxSize
Column(1) = Column(1) + 1
Loop
direction = UP
start = i + 1
Exit For
ElseIf last - C(i) >= RevAmt * BoxSize Then
Do
If last - BoxSize < C(i) Then
Exit Do
End If
last = last - BoxSize
Column(1) = Column(1) - 1
Loop
332
INNTRODU C
direction = DOWN
start = i + 1
Exit For
Else
' Do nothing if Q(i).C = Q(1).C
End If
Next i

' loop through remainder of closes filling the column array

col = 1
For i = start To NumCloses
If direction = UP Then
If C(i) - last >= BoxSize Then
Do
If last + BoxSize > C(i) Then
Exit Do
End If
last = last + BoxSize
Column(col) = Column(col) + 1
Loop
ElseIf last - C(i) >= RevAmt * BoxSize Then
col = col + 1
Do
If last - BoxSize < C(i) Then
Exit Do
End If
last = last - BoxSize
Column(col) = Column(col) - 1
Loop
direction = DOWN
End If
ElseIf direction = DOWN Then
If last - C(i) >= BoxSize Then
Do
If last - BoxSize < C(i) Then
Exit Do
End If
last = last - BoxSize
Column(col) = Column(col) - 1
Loop
ElseIf C(i) - last >= RevAmt * BoxSize Then
col = col + 1
Visual Basic Source Code (Point and Figure)
333
Do
If last + BoxSize > C(i) Then
Exit Do
End If
last = last + BoxSize
Column(col) = Column(col) + 1
Loop
direction = UP
End If
End If
Next i
CalculateColumns = col
Exit Function
Err_CalculateColumns:
MsgBox Err.Description
End Function

Public Sub PlotPafChart(obj As Object)
Dim Xinc# ' width of each graph paper square in twips
Dim Yinc# ' height of each graph paper square in twips
Dim Xmrg# ' left margin of plotting zone
Dim Ymrg# ' top margin of plotting zone
Dim PipFactor# ' converts prices to integers, ie, 10000 for EURUSD
Dim Fmt$ ' format string for PipFactor
Dim dnum# ' floating point loop index
Dim st$ ' local discard string
Dim i&, j& ' integer loop indexes
Dim max# ' maximum high
Dim start# ' first close in raw data
Dim last# ' last plotted X or Y
Dim x1#, x2# ' x-axis coordinates
Dim y1#, y2# ' y-axis coordinates
Dim HdrMrg# ' header margin

On Error GoTo Err_PlotPafChart

' Initialize variables ===============================

Xinc = 150
Yinc = Xinc
Xmrg = 5.5 * Xinc
Ymrg = 10 * Yinc
PipFactor = 100 '10000
334
INNTRODU C
' Plot background graph paper ========================

obj.Cls
For dnum = 0 To obj.Height Step Xinc
obj.Line (0, dnum)-(obj.Width, dnum), vbGray
Next dnum
For dnum = 0 To obj.Width Step Yinc
obj.Line (dnum, 0)-(dnum, obj.Height), vbGray
Next dnum

' Print two-line header ==============================

HdrMrg = 0.21
obj.Line (HdrMrg * obj.Width, 80)-((1# - HdrMrg) * obj.Width, 650), vbLightYellow, BF
For i = 0 To 12
obj.Line (0.21 * obj.Width + i, 100 - i)-(0.79 * obj.Width - i, 650 + i), vbBlack, B
Next i

obj.FontName = ''Times New Roman''
obj.ForeColor = vbBlack
obj.FontSize = 10
obj.FontBold = True
st = ''USDJPY December 2004''
obj.CurrentX = (obj.Width - obj.TextWidth(st)) / 2
obj.CurrentY = 150
obj.Print st

obj.FontSize = 9
st = ''P&F Chart Box Size = '' + CStr(BoxSize) + '' Rev Amt = ''
st = st + CStr(RevAmt) + '' Boxes''
obj.CurrentX = (obj.Width - obj.TextWidth(st)) / 2
obj.Print st

' Find maximum close ====================================

max = 0
For i = 1 To NumCloses
If C(i) > max Then max = C(i)
Next i
' Adjust max to be a multiple of boxsize units from C(1)
' This ensures Xs and Os land in center of squares

last = C(1)
Do
Visual Basic Source Code (Point and Figure)
335
last = last + BoxSize
Loop While last < max
max = last
Debug.Print max

' Print vertical scale ================

x1 = 1
y1 = Yinc * (Ymrg / Yinc - 3)
x2 = Xmrg
y2 = obj.Height - 2 * Yinc
obj.Line (x1, y1)-(x2, y2), vbWhite, BF
obj.FontSize = 8
obj.FontBold = True
i = -1
Do
i = i + 1
dnum = max - i * BoxSize
st = Format(dnum - 0.0001, ''##0.00'')
obj.CurrentX = (Xmrg - obj.TextWidth(st)) / 2
obj.CurrentY = Ymrg + (i - 3) * Yinc + 10
If obj.CurrentY > obj.Height - 3 * Yinc Then Exit Do
obj.Print st
Loop While obj.CurrentY <= 0.98 * obj.Height

' Plot Xs and Os columns =================

last = -4 + (max - C(1)) / BoxSize
For i = 1 To NumColumns
x1 = Xmrg + (i * Xinc)
If Column(i) > 0 Then
For j = 1 To Column(i)
y1 = Ymrg + (last - j + 0.45) * Yinc
PrintX obj, x1, y1, 0.3 * Xinc
Next j
Else
For j = -1 To Column(i) Step -1
y1 = Ymrg + (last - j + 0.45) * Yinc
PrintO obj, x1, y1, 0.3 * Xinc
Next j
End If
last = last - Column(i)
Next i
336
INNTRODU C
Exit Sub
Err_PlotPafChart:
MsgBox Err.Description
Resume
End Sub

Public Sub PrintX(obj As Object, cx#, cy#, side#)
Dim i%
cy = cy + 5
For i = 0 To 15
obj.Line (cx - 0.7 * side + i, cy - side)-(cx + 0.7 * side + i, cy + side), vbBlack
obj.Line (cx + 0.7 * side - i, cy - side)-(cx - 0.7 * side - i, cy + side), vbBlack
Next i
End Sub

Public Sub PrintO(obj As Object, cx#, cy#, radius#)
Dim i%
cy = cy + 5
For i = 0 To 15
obj.Circle (cx + i, cy), radius, vbBlack, , , 1.85
Next i
End Sub

Forex Trading System- Global Banking Hours

Despite all the fundamental and technical influences on the foreign exchange mar-
ket, one major constant in determining periods of high volatility is the hours of opera-
tion for the central banks of each major currency country.
Figure D.1 emphasizes the importance of the effect of time of day on forex mar-
ket activity and volatility based on hours of operation around the globe. Because
banking hours vary from country to country, we have arbitrarily set hours of opera-
tion from 9:00 A.M.to 5:00 P.M.for consistency. The top row is expressed as central
european time (Greenwich mean time + 1 hour), which aligns with the Central Bank
of Europe in Frankfurt, the most prestigious central bank in the European Monetary
Union.
The table allows traders to view overlapping time periods when central banks
for different currencies are operating and thus guarantee a certain degree of mutual
activity.
For example, when banks open in New York City at 9:00 A.M.EST, the Frankfurt
bank has already been operating for six hours. So there is a two-hour overlap of trading
in the EURUSD currency pair on both sides of the Atlantic Ocean (9:00 A.M. to 11:00 A.M.
EST). This can be readily recognized in the time of day activity chart for the EURUSD
pair (Figure 2.4 in Chapter 2).

Dedicated currency traders may have to adjust their sleeping schedules to take
advantage of increased activity and volatility when trading non-USD cross-rate cur-
rency pairs.

Forex Trading System- World Currencies

This is a list of global currencies and the three-character currency codes that we
have found are generally used to represent them. Often, but not always, this code
is the same as the ISO 4217 standard. (The ISO, or International Organization for
Standardization, is a worldwide federation of national standards.)
In most cases, the currency code is composed of the country’s two-character Inter-
net country code plus an extra character to denote the currency unit. For example, the
code for Canadian dollars is simply Canada’s two-character Internet country code (CA)
plus a one-character currency designator (D).
We have endeavored to list the codes that, in our experience, are actually in general
industry use to represent the currencies. Currency names are given in the plural form.
This list does not contain obsolete euro-zone currencies.

WORLD CURRENCIES
Symbol
Region
Currency Name
AED
United Arab Emirates
Dirhams
AFA
Afghanistan
Afghanis
ALL
Albania
Leke
AMD
Armenia
Drams
ANG
Netherlands Antilles
Guilders
AOA
Angola
Kwanza
ARS
Argentina
Pesos
AUD
Australia
Dollars
AWG
Aruba
Guilders
(continues)
259
Symbol
Region
Currency Name
AZM
Azerbaijan
Manats
BAM
Bosnia and Herzegovina
Convertible marka
BBD
Barbados
Dollars
BDT
Bangladesh
Taka
BGN
Bulgaria
Leva
BHD
Bahrain
Dinars
BIF
Burundi
Francs
BMD
Bermuda
Dollars
BND
Brunei Darussalam
Dollars
BOB
Bolivia
Bolivianos
BRL
Brazil
Brazil real
BSD
Bahamas
Dollars
BTN
Bhutan
Ngultrum
BWP
Botswana
Pulas
BYR
Belarus
Rubles
BZD
Belize
Dollars
CAD
Canada
Dollars
CDF
Congo/Kinshasa
Congolese francs
CHF
Switzerland
Francs
CLP
Chile
Pesos
CNY
China
Renminbi
COP
Colombia
Pesos
CRC
Costa Rica
Colones
CUP
Cuba
Pesos
CVE
Cape Verde
Escudos
CYP
Cyprus
Pounds
CZK
Czech Republic
Koruny
DJF
Djibouti
Francs
DKK
Denmark
Kroner
DOP
Dominican Republic
Pesos
DZD
Algeria
Algeria dinars
EEK
Estonia
Krooni
EGP
Egypt
Pounds
ERN
Eritrea
Nakfa
ETB
Ethiopia
Birr
EUR
Euro member countries
Euro
FJD
Fiji
Dollars
FKP
Falkland Islands
Pounds
GBP
United Kingdom
Pounds
GEL
Georgia
Lari
GGP
Guernsey
Pounds
260
APPENDIX A
GHC
Ghana
Cedis
GIP
Gibraltar
Pounds
GMD
Gambia
Dalasi
GNF
Guinea
Francs
GTQ
Guatemala
Quetzales
GYD
Guyana
Dollars
HKD
Hong Kong
Dollars
HNL
Honduras
Lempiras
HRK
Croatia
Kuna
HTG
Haiti
Gourdes
HUF
Hungary
Forint
IDR
Indonesia
Rupiahs
ILS
Israel
New shekels
IMP
Isle of Man
Pounds
INR
India
Rupees
IQD
Iraq
Dinars
IRR
Iran
Rials
ISK
Iceland
Kronur
JEP
Jersey
Pounds
JMD
Jamaica
Dollars
JOD
Jordan
Dinars
JPY
Japan
Yen
KES
Kenya
Shillings
KGS
Kyrgyzstan
Soms
KHR
Cambodia
Riels
KMF
Comoros
Francs
KPW
Korea (North)
Won
KRW
Korea (South)
Won
KWD
Kuwait
Dinars
KYD
Cayman Islands
Dollars
KZT
Kazakstan
Tenge
LAK
Laos
Kips
LBP
Lebanon
Pounds
LKR
Sri Lanka
Rupees
LRD
Liberia
Dollars
LSL
Lesotho
Maloti
LTL
Lithuania
Litai
LVL
Latvia
Lati
LYD
Libya
Dinars
MAD
Morocco
Dirhams
MDL
Moldova
Lei
MGA
Madagascar
Ariary
(continues)
Pater nFttquciqs
261
Symbol
Region
Currency Name
MKD
Macedonia
Denars
MMK
Myanmar (Burma)
Kyats
MNT
Mongolia
Tugriks
MOP
Macau
Patacas
MRO
Mauritania
Ouguiyas
MTL
Malta
Liri
MUR
Mauritius
Rupees
MVR
Maldives
Rufiyaa
MWK
Malawi
Kwachas
MXN
Mexico
Pesos
MYR
Malaysia
Ringgits
MZM
Mozambique
Meticais
NAD
Namibia
Dollars
NGN
Nigeria
Nairas
NIO
Nicaragua
Gold cordobas
NOK
Norway
Krone
NPR
Nepal
Nepal rupees
NZD
New Zealand
Dollars
OMR
Oman
Rials
PAB
Panama
Balboa
PEN
Peru
Nuevos soles
PGK
Papua New Guinea
Kina
PHP
Philippines
Pesos
PKR
Pakistan
Rupees
PLN
Poland
Zlotych
PYG
Paraguay
Guarani
QAR
Qatar
Rials
ROL
Romania
Lei
RUR
Russia
Rubles
RWF
Rwanda
Rwanda francs
SAR
Saudi Arabia
Riyals
SBD
Solomon Islands
Dollars
SCR
Seychelles
Rupees
SDD
Sudan
Dinars
SEK
Sweden
Kronor
SGD
Singapore
Dollars
SHP
Saint Helena
Pounds
SIT
Slovenia
Tolars
SKK
Slovakia
Koruny
SLL
Sierra Leone
Leones
SOS
Somalia
Shillings
262
APPENDIX A
SPL
Seborga
Luigini
SRG
Suriname
Guilders
STD
São Tomé, Principe
Dobras
SVC
El Salvador
Colones
SYP
Syria
Pounds
SZL
Swaziland
Emalangeni
THB
Thailand
Baht
TJS
Tajikistan
Somoni
TMM
Turkmenistan
Manats
TND
Tunisia
Dinars
TOP
Tonga
Pa’anga
TRL
Turkey
Liras
TTD
Trinidad, Tobago
Dollars
TVD
Tuvalu
Tuvalu dollars
TWD
Taiwan
New dollars
TZS
Tanzania
Shillings
UAH
Ukraine
Hryvnia
UGX
Uganda
Shillings
USD
United States of America
Dollars
UYU
Uruguay
Pesos
UZS
Uzbekistan
Sums
VEB
Venezuela
Bolivares
VND
Vietnam
Dong
VUV
Vanuatu
Vatu
WST
Samoa
Tala
YER
Yemen
Rials
YUM
Yugoslavia
New dinars
ZAR
South Africa
Rand
ZMK
Zambia
Kwacha
ZWD
Zimbabwe
Zimbabwe dollars