PDA

View Full Version : Request for VTL Auto trade Script with capability to read from excel file



haider.ali
09-07-2015, 11:23 AM
Sir our some clients want VTL Auto trade Script linked with Excel file to read from specific cell of excel file for auto buy/sell execution with automatic trailing stop at their desired gap.
Waiting for your valuable comments & guidance.

Hassan-HS
09-08-2015, 08:29 AM
Dear Sir,

Sorry we just assist developers about how to use the VTL, but we can not write full script as you ask.

at first you may find some VTL client scripts with the same functionality at vstore.co (http://vstore.co/)
if you don't find such script you can use our portal VFXLancer.com (http://vfxlancer.com/) to post your own projects easily, then you will receive many bids from Freelancers and development companies that have interest in developing your projects.
For more info:
http://www.vfxlancer.com (http://www.vfxlancer.com/)
To register please check this link:
http://www.vfxlancer.com/component/jblance/guest/showfront.html


Feel free to let us know if you have any further inquiries.

haider.ali
09-08-2015, 08:30 AM
Here is my script. when i try to launch but it gives errors

'''############################################### ######################################
'''#### Script Name: Autotrading ######
'''#### Author : Haider Ali ######
'''#### Website : www.Hybrid-solutions.com ######
'''#### Date : 07/09/2015 17:04:18 ######
'''#### Description: Description ######
'''############################################### ######################################

''' <summary>
''' The main function is the entry point for any Script program
''' </summary>

Public Sub main()
Dim filename
Dim fileMode
fileMode = FILE_APPEND
fileName = "C:\Vertex.xlsx"
msgbox GetEntry (Cstr(fileName),sheet1, d5)
'L means the line number
End Sub

sub main()

if d5 = 2, ("C:\Vertex.xlsx") then
'NewMarketOrder 1',"MININQU5",0.5 '(1 = Buy, SymbolName, Lots)'
End if

End Sub

''' <summary>
''' The function is generated when a new tick is received for any symbol
''' </summary>

Public Sub OnTick(symbolName)
End Sub

''' <summary>
''' The function is generated when initialization script
''' </summary>

Public Sub OnInit()
'''TODO: initialization method
End Sub

''' <summary>
''' The function is generated when deinitialization script
''' </summary>

Public Sub OnDeInit()
'''TODO: deinitialization method
End Sub

''' <summary>
''' The OnTimer function called when the timer event occurs
''' </summary>

Public Sub OnTimer()
'''TODO: Timer Function
End Sub

Rawan-HS
09-08-2015, 10:26 AM
Dear

try this code , it to read from excel file for cell (1,1)
let me know if you need any things .




Public Sub main()
''''TODO: Script program start method


Dim xlApp
Dim xlBook
Dim xlSheet

Set xlApp = CreateObject("Excel.Application")
xlApp.visible = false
Set xlBook = xlApp.Workbooks.open("C:\Vertex.xlsx" )
Set xlSheet = xlBook.Worksheets("Sheet1")

AlertMessage xlSheet.Cells(1,1).Value

if xlSheet.Cells(1, 1).Value = 2 then
NewMarketOrder 1,"EUR/USD",1
End if




End Sub

haider.ali
09-09-2015, 05:34 AM
Brother thanks for your attention: Following issues related to script provided may please be clarified.

1. In this script, where i can mentioned that it is VTL client script or VTL Server side script?
2. If xls sheet is active then can i modify code to "xlapp.visible = true"
3. Can i specify cell description i.e "B4" or "D8", etc in the script.
4. Can i add description of new market order whether sell or buy like (1/-1 = Buy / Sell, SymbolName, Lots)
5. How to add strong auto desired SL/TP in this script.

Thanking you in anticipation.

Rawan-HS
09-09-2015, 07:07 AM
Dear sir ,

first of all we are not expert about windows API so we can't help you about how to get the cell description

- please read this course to know the differences between VTL Client (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/2567) and VTL Server (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/2566)
- you can modify the code to be xlapp.visible=true , this line it just to make the sheet visible to you or not
and yes you can add description for the market order by using ENUM_TRADE_ACTION (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/2596) to be like this



NewMarketOrder TRADE_ACTION_BUY,"EUR/USD",1



try this code to open the SLTP order




Public Sub main()




Dim xlApp
Dim xlBook
Dim xlSheet

Set xlApp = CreateObject("Excel.Application")
xlApp.visible = true
Set xlBook = xlApp.Workbooks.open("C:\Vertex.xlsx" )
Set xlSheet = xlBook.Worksheets("Sheet1")


if xlSheet.Cells(1, 1).Value = 2 then
NewMarketOrder TRADE_ACTION_BUY,"EUR/USD",1
End if


End Sub


Public Sub OnPositionTrade (actionType ,ticketID)
If actionType= 5 then


NewSLTPOrder Clng(ticketID), 1, 1.11502 , 1.11632


end if
End Sub

haider.ali
09-09-2015, 07:11 AM
Dear Rawan, Thanks for your kind attention.

Rawan-HS
09-09-2015, 09:56 AM
you are welcome , and tell me if you need any things else :)

haider.ali
09-09-2015, 01:53 PM
Sir i tried the code but neither the script read .xl sheet1/cell nor any order executed. plz guide.

Rawan-HS
09-09-2015, 05:06 PM
Dear

this is the Full VTL Client Code just copy it to VTL and attach to chart after select Account
and be notice it executed the order if the value of the Cell number (1,1) equal 2
this code is working fine in my side




'''############################################### ######################################
'''#### Script Name: Script Name ######
'''#### Author : Author Name ######
'''#### Website : www.Hybrid-solutions.com ######
'''#### Date : 09/09/2015 19:51:11 ######
'''#### Description: Description ######
'''############################################### ######################################

''' <summary>
''' The main function is the entry point for any Script program
''' </summary>


Public Sub main()

''''TODO: Script program start method


Dim xlApp
Dim xlBook
Dim xlSheet

Set xlApp = CreateObject("Excel.Application")
xlApp.visible = true
Set xlBook = xlApp.Workbooks.open("C:\Vertex.xlsx" )
Set xlSheet = xlBook.Worksheets("Sheet1")


if xlSheet.Cells(1, 1).Value = 2 then
NewMarketOrder TRADE_ACTION_BUY,"EUR/USD",1
End if


End Sub


Public Sub OnPositionTrade (actionType ,ticketID)
If actionType= 5 then


NewSLTPOrder Clng(ticketID), 1, 1.11502 , 1.11632


end if
End Sub



''' <summary>
''' The function is generated when a new tick is received for any symbol
''' </summary>

Public Sub OnTick(symbolName)

End Sub


''' <summary>
''' The function is generated when initialization script
''' </summary>

Public Sub OnInit()
''''TODO: initialization method

End Sub


''' <summary>
''' The function is generated when deinitialization script
''' </summary>

Public Sub OnDeInit()
''''TODO: deinitialization method

End Sub


''' <summary>
''' The OnTimer function called when the timer event occurs
''' </summary>

Public Sub OnTimer()
''''TODO: Timer Function
End Sub

''' <summary>
''' The OnCalculate function called when a new candle received
''' </summary>

Public Sub OnCalculate(symbol, symbolPeriod, openVal, highVal, lowVal, closeVal)

End Sub
''' <summary>
''' Raise when all data are loaded after Login
''' </summary>

Public Sub AllDataLoaded()

End Sub
''' <summary>
''' Raise when Account Selected
''' </summary>

Public Sub AccountSelected(accountNumber)

End Sub
''' <summary>
''' Raise when the server returns order result
''' </summary>

Public Sub OnOrderTrade(actionType ,orderID , returnValue)

End Sub


public sub OnManageOrdersReceived(manageOrders)

End Sub

haider.ali
09-14-2015, 02:18 PM
I tried the below code as you advised, i.e attached the vtl script to chart but it won't wok. Error report is enclosed. (Furthermore, also guide to get data from a already opened / active excel file)

Public Sub main()

''''TODO: Script program start method


Dim xlApp
Dim xlBook
Dim xlSheet

Set xlApp = CreateObject("Excel.Application")
xlApp.visible = false
Set xlBook = xlApp.Workbooks.open("D:\ali.xlsx" )
Set xlSheet = xlBook.Worksheets("Sheet1")


if xlSheet.Cells(1, a).Value = 2 then

NewMarketOrder TRADE_ACTION_BUY,"MINI_NQ_U5",1

End if


End Sub

Rawan-HS
09-15-2015, 07:41 AM
Dear Sir ,


the error appeared on the calls coordinate the script can't read the coordinate as (1,a) .
so (1,a) it equal to Cell (1, 1) , and cell (1, b ) it equal to (1,2 ) and so on

so according to this just change the line




if xlSheet.Cells(1, a).Value = 2 then



to this




if xlSheet.Cells(1, 1).Value = 2 then

haider.ali
09-16-2015, 07:14 AM
Dear Rawan Sir, this script is to read an closed excel file. If i want to read or continuously read an already opened /active worksheet, then what will be the change in this script. Thanks for your kind attention.

haider.ali
09-16-2015, 08:41 AM
I following your guidelines but this time recieved following error.
392

code: (5, 4) stands for (5, d)

Public Sub main()

''''TODO: Script program start method


Dim xlApp
Dim xlBook
Dim xlSheet

Set xlApp = CreateObject("Excel.Application")
xlApp.visible = false
Set xlBook = xlApp.Workbooks.open("D:\vertex.xlsx" )
Set xlSheet = xlBook.Worksheets("Sheet1")


if xlSheet.Cells(5, 4).Value = 1 then

NewMarketOrder TRADE_ACTION_BUY,"MINI_NQ_U5",1

End if


End Sub

Rawan-HS
09-16-2015, 11:37 AM
Dear

I have tested your code and there is no error

is this your fully code ??

haider.ali
09-16-2015, 11:44 AM
Yes. it is fully code. This script launches multiple instances of Excel.
I just want that VTL Script only continuously read my
active / already opened excel file in background and execute buy/sell orders. but still stuck in the script

Thanks

Rawan-HS
09-17-2015, 10:27 AM
Dear

try to change this




xlApp.visible = false


to this




xlApp.visible = true


but be notice the file will open in each time you attach the script in chart

haider.ali
09-18-2015, 09:11 AM
Respected Sir, May it work with "GetObject" command.

Rawan-HS
09-20-2015, 07:39 AM
Dear sir ,

we are not expert about windows API so we can't help you more about it .