All Open Positions
Posted by Yousef Ibrahim, Last modified by Abdullah Almasharfah on 14 December 2018 10:16 PM

'''################################################################################################
'''####   
Script Name: All Open Positions                                                     ##### 
'''####   Author: Salah Abu-Ghalyon                                                           #####
'''####   Website: www.Hybrid-solutions.com                                                   #####
'''####   Date: 19/06/2013 09:53:44                                                           #####
'''####   Description: This VTL Server Script will show you all open positions in a list view #####
'''################################################################################################

Dim lbl as VTLGeneral.VTLControls. CChartObjectLabelDim lbl2 as VTLGeneral.VTLControls. CChartObjectLabelDim colvalues as System.Collections.Generic.List(Of VTLGeneral.VTLControls.ListViewcolumn)Dim colvalue as VTLGeneral.VTLControls.ListViewcolumnDim _position as VTLGeneral.CPositionDim lst as VTLGeneral.VTLControls.VTLListViewDim itemvalues as New System.Collections.Generic.List(Of VTLGeneral.VTLControls.ListViewItem)Dim frm as VTLGeneral.VTLFormDim itemvalue as VTLGeneral.VTLControls.ListViewItemPublic Sub main()colvalues = New System.Collections.Generic.List(Of VTLGeneral.VTLControls.ListViewcolumn)Dim listOfcolumns as New VTLGeneral.VTLControls.ListViewcolumnsDim _index as integerlst= New VTLGeneral.VTLControls.VTLListView("lst1") frm= New VTLGeneral.VTLForm("frm1")frm.AddVTLControl(lst)lst.Height="2000"lst.Width ="10000"lst.Top   ="2000"lst.left  ="500"colvalue= New VTLGeneral.VTLControls.ListViewcolumncolvalue.Text="Symbol Name"colvalue.Key ="SymbolName"colvalue.Index=cstr(1)colvalues.add(colvalue)colvalue= New VTLGeneral.VTLControls.ListViewcolumncolvalue.Text="Ticket"colvalue.Key="Ticket"colvalue.Index=cstr(2)colvalues.add(colvalue)colvalue= New VTLGeneral.VTLControls.ListViewcolumncolvalue.Text="Type"colvalue.Key="BuySell"colvalue.Index=cstr(3)colvalues.add(colvalue)colvalue= New VTLGeneral.VTLControls.ListViewcolumncolvalue.Text="Amount"colvalue.Key="Amount"colvalue.Index=cstr(4)colvalues.add(colvalue)colvalue= New VTLGeneral.VTLControls.ListViewcolumncolvalue.Text="OpenPrice"colvalue.Key ="OpenPrice"colvalue.Index=cstr(5)colvalues.add(colvalue)colvalue= New VTLGeneral.VTLControls.ListViewcolumncolvalue.Text="CurrentPrice"colvalue.Key ="CurrentPrice"colvalue.Index=cstr(6)colvalues.add(colvalue)colvalue= New VTLGeneral.VTLControls.ListViewcolumncolvalue.Text="Commission"colvalue.Key="Commission"colvalue.Index=cstr(7)colvalues.add(colvalue)colvalue = New VTLGeneral.VTLControls.ListViewcolumncolvalue.Text="Interest"colvalue.Key="Interest"colvalue.Index=cstr(8)colvalues.add(colvalue)lst.AddHeader(colvalues)colvalues.clear()lbl  = New VTLGeneral.VTLControls.CChartObjectLabel("lbl1")lbl2 = New VTLGeneral.VTLControls.CChartObjectLabel("lbl2")Dim btn  as VTLGeneral.VTLControls.CChartObjectButtonDim btn2 as VTLGeneral.VTLControls.CChartObjectButtonDim btn3 as VTLGeneral.VTLControls.CChartObjectButtonDim btn4 as VTLGeneral.VTLControls.CChartObjectButtonbtn = New VTLGeneral.VTLControls.CChartObjectButton("btn1")btn2= New VTLGeneral.VTLControls.CChartObjectButton("btn2")btn3= New VTLGeneral.VTLControls.CChartObjectButton("btn3")btn4= New VTLGeneral.VTLControls.CChartObjectButton("btn4")btn.Width ="700"btn2.Width="700"btn3.Width="700"btn4.Width="700"frm.AddVTLControl(btn)frm.AddVTLControl(btn2)frm.AddVTLControl(btn3)frm.AddVTLControl(btn4)frm.AddVTLControl(lbl)frm.AddVTLControl(lbl2)btn.Height ="300"btn2.Height="300"btn3.Height="300"btn4.Height="300"btn.Top  = "500"btn2.Top = "500"btn3.Top = "500"btn4.Top = "500"btn.left  = "500"btn2.left = "2500"btn3.left = "4500"btn4.left = "6500"lbl.top  = "1000"lbl2.Top = "1500"lbl.left  = "2000"lbl2.left = "2000"btn.caption  = "Acc Balance"btn2.caption = "Acc Summary"btn3.caption = "All Open Positions"btn4.caption = "Account Name"frm.width  = "12000"frm.Height = "5000"lbl.width  = "5000"lbl2.width = "10000"frm.show()End SubPublic Sub frm1_btn1_click()Dim property_id as VTLGeneral.ENUM_ACCOUNT_INFO_DOUBLE property_id=VTLGeneral.ENUM_ACCOUNT_INFO_DOUBLE.ACCOUNT_BALANCEDim x as integerlbl.caption=("Balance is:" & ClientCode.AccountInfoDouble(x).ToString())End SubPublic Sub frm1_btn2_click()Dim balance, FltPL, credite, equity, marginReq, marginLevel, EFFmargine As DoubleDim result as VTLGeneral.CallingResultsEnumresult=ClientCode.AccountSummaries(balance, FltPL, credite, equity, marginReq, marginLevel, EFFmargine )If result=1 Thenlbl2.caption=("Balance : " & balance.Tostring & " , FltPL : " & FltPL.Tostring & " , Credite : " & credite.Tostring & " , Equity : " & equity.Tostring & " , MarginReq : " & marginReq.Tostring & " , MarginLevel : " & marginLevel.Tostring & " , EFFmargine" & EFFmargine.Tostring)End IfEnd SubPublic Sub frm1_btn3_click()Dim type as stringDim i as integerFor i = 1 To ClientCode.PositionsTotal()itemvalue = New VTLGeneral.VTLControls.ListViewItem_position=ClientCode.OpenPositionByIndex(i)itemvalue.Text=_position.SymbolNameitemvalue.Key="S" & _position.Ticketitemvalue.Index=CSTR(i)itemvalue.AddSubItem(_position.Ticket)IF _position.BuySell=1 Then           Type ="Buy"ElseIF _position.BuySell=-1 Then          Type ="Sell"ElseIF _position.BuySell=2 Then          Type ="BuyStop"ElseIF _position.BuySell=-2 Then          Type ="SellStop"End IFitemvalue.AddSubItem(Type)itemvalue.AddSubItem(_position.Lots)itemvalue.AddSubItem(_position.Price)itemvalue.AddSubItem(_position.ClosePrice)itemvalue.AddSubItem(_position.Commission)itemvalue.AddSubItem(_position.Interest)itemvalues.add(itemvalue)Nextlst.AddListItem(itemvalues)End SubPublic Sub frm1_btn4_click()GUI.MsgDialog (Clientcode.AccountInfoString (2 ) ) End Sub

See Also

Back to VTL Server Script Index
(3 vote(s))
Helpful
Not helpful

Comments (2)
Naeem Hasan
01 July 2013 06:51 AM
This code has may errors. I just copy/paste it in a server side script and try to compile. First error was -
At line No 189: End of Statement Expected
This line is: itemvalue.AddSubItem(Type)itemvalue.AddSubItem(_position.Lots)

I make it two lines as
itemvalue.AddSubItem(Type)
itemvalue.AddSubItem(_position.Lots)

Then error is : at line 189: Type is a type and can not be used as expression

I change the variable Type > PType that resolvee this problem.

But new problem arise at line 179 as: Ticketitemvalue is not a member of VTLServerapplication.CPosition

After correcting a lot of problem finally I can compile and run the script. But it's not showing correct information from account. Specially 'All Open Position' button shows nothing in the list view.

I open three types of position to test - 1 Buy, 1 Sell and 1 Buy Stop. But the function ClientCode.PositionsTotal() returns -1, so it can't show open positions correctly.

Please help me to resolve this issue.
Hassan Abu Krayem
02 July 2013 11:03 AM
Dear,
I fix the Issue
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).

Help Desk Software by Hybrid Solutions