View Full Version : Error in MACD code

12-03-2015, 08:17 AM
Hello Team

I am trying to run code given in MACD oscillator in help page for server side script.
I just copy the code and try to execute, but it show technical error as shown in attached screen shot.

I need MACD value and Signal in an expert adviser script.

Please help to get them in server side code.

here is the code I take from help page:

Dim _symbolInfo As VTLGeneral.CSymbol=ClientCode.GetSymbolByName("GOLD")
Dim DB As New VTLGeneral.Database()
Dim RecordCount As Integer
Dim m_Recordset As VTLGeneral.RecordSet
Dim _historyData As object()
Dim output As String
Dim Record As Integer
Dim m_Date As VTLGeneral.Field
Dim m_Open As VTLGeneral.Field
Dim m_High As VTLGeneral.Field
Dim m_Low As VTLGeneral.Field
Dim m_Close As VTLGeneral.Field
Dim j As Integer = 0
Dim i As Integer = 0
Dim _recordCount As Integer =100

m_Recordset = DB.CreateRecord
m_Open = New VTLGeneral.Field
m_High = New VTLGeneral.Field
m_Low = New VTLGeneral.Field
m_Close = New VTLGeneral.Field

DB.RecordCount = _recordCount
RecordCount = _recordCount

'Initialize Recordsets
m_Open.initialize(_recordCount-1, "Open")
m_High.initialize(_recordCount-1, "High")
m_Low.initialize(_recordCount-1, "Low")
m_Close.initialize(_recordCount-1, "Close")

'load high, low ,open and data

_historyData = ClientCode.GetChartHistory(_symbolInfo.ID, VTLGeneral.ENUM_PERIOD.Day,VTLGeneral.ENUM_HISTORY _TYPE.HIS_HIGH, _recordCount)

For i = 0 To _recordCount-1

_historyData = ClientCode.GetChartHistory(_symbolInfo.ID, VTLGeneral.ENUM_PERIOD.Day,VTLGeneral.ENUM_HISTORY _TYPE.HIS_LOW, _recordCount)

For i = 0 To _recordCount-1

_historyData = ClientCode.GetChartHistory(_symbolInfo.ID, VTLGeneral.ENUM_PERIOD.Day,VTLGeneral.ENUM_HISTORY _TYPE.HIS_OPEN, _recordCount)

For i = 0 To _recordCount-1

_historyData = ClientCode.GetChartHistory(_symbolInfo.ID, VTLGeneral.ENUM_PERIOD.Day,VTLGeneral.ENUM_HISTORY _TYPE.HIS_CLOSE, _recordCount)

For i = 0 To _recordCount-1


'MACD indicator

Dim _indRecord As New VTLGeneral.RecordSet()
Dim osc As New VTLGeneral.Oscillator()
_indRecord = osc.MACD(DB,m_Recordset,5)

For i = 0 To DB.getRecordCount-1

output = output & CSTR(_indRecord.getValue(_indRecord.getName(1), i) ) & vbcrlf



12-06-2015, 02:20 PM
Dear nhasan

check if you are using visible symbol for your client on this line of code

Dim _symbolInfo As VTLGeneral.CSymbol=ClientCode.GetSymbolByName("GOLD")

However we have added the "Gold" to your symbol list so can check the code now .

12-07-2015, 10:57 AM
Ok, It's working now.
I wish the system will provide a clear message the the instrument is not included in the account for this type of issue instead of sowing system error.

However, I have another issue - can we connect external database from VTLS code? I try to declare a ADODB connection variable as : Dim conn As ADODB.Connection but not working.

Or can we import extern dll for database connection like MySQL connector?

12-07-2015, 01:28 PM

thanks for your suggestion we are working to enhance the system error message .
and sure you can connected with external database but before you should set up your system DSN check this article (http://webcheatsheet.com/asp/dsn.php)
and check this sample

Public Sub main()

Dim Connection
Dim Recordset


Set Connection = CreateObject("ADODB.Connection")
Set Recordset = CreateObject("ADODB.Recordset")
'open the connection to the database
Connection.Open "DSN=DSN_Name"
'Open the recordset object executing the SQL statement and return records
Recordset.Open SQL,Connection
'first of all determine whether there are any records
If Recordset.EOF Then
Alertmessage("No records returned.")
'if there are records then loop through the fields
Do While NOT Recordset.Eof
AlertMessage Recordset("FIRST_FIELD_NAME")
AlertMessage Recordset("SECOND_FIELD_NAME")
AlertMessage Recordset("THIRD_FIELD_NAME")
End If
Set Recordset=nothing
Set Connection=nothing
End Sub

12-08-2015, 03:57 AM
Thanks for the code in vbscript to run on local PC to connect MS Access database.
Actually I am looking for server side VB.Net code to connect on line MySQL database using IP address.
There is a connector dll for VB.Net to connect MySQL database server, can we Import that connector in Vertex server side script code?

12-08-2015, 11:28 AM
Dear nhasan

You can't import the DLL by VTL server side script , and we will study this feature with our development to know if we can add it or not and I will updating you .

12-10-2015, 06:10 AM
Ok, we will wait for the update.

Now, I am trying to understand the MACD code for server side script.

I have changed the code as :

Dim _symbolInfo As VTLGeneral.CSymbol=ClientCode.GetSymbolByName("GBP/USD")
_indRecord = osc.MACD(DB,m_Recordset,9,"",12,26)
For i = DB.getRecordCount-1 To DB.getRecordCount-1
output = output & CSTR(_indRecord.getValue(_indRecord.getName(1), i) ) & vbcrlf

It displays the value of MACD for the last candle of GBP/USD pair for Daily chart.

The value shows by the code is : -0.001316

But when I attach the indicator on Daily Chart of GBP/USD on client terminal the value we found -0.00389

Can you please explain what is calculating in the code other than MACD value shown by the indicator on chart?

12-10-2015, 08:09 AM
HI Hasan,

At First you should make the following variables same on the both sides (VTL Server,Client Terminal)

1-Bars Count, to know the total bars count on the VTL server use this method (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/3634), note that the script return the number of the bars that already closed.
2-Symbol Name.
3-Chart Period.
4-MACD Parameters.

let me know if you need more assistance.

I compared between the two sides and everthing look fine :)