PDA

View Full Version : Help on Basics of Server Side Script



Edakad
02-23-2015, 08:05 AM
Hello

1. I have a server script that sends an order, I though it will be visible in the client terminal but it is not appearing on client terminal. But querying the server with ordersTotal shows the order is there

2. What is the proper method to start and stop a server script from client terminal

Thanks

Hassan-HS
02-23-2015, 02:53 PM
Dear Edakad,

1- Please check the all accounts of your client.
2-You can Start/Stop the VTL server scripts only using VTL editor.

Edakad
02-23-2015, 06:18 PM
Thanks Hassan

can u guide on this, where is this option available on client terminal, I am using demo account.


1- Please check the all accounts of your client.

Hassan-HS
02-24-2015, 04:50 PM
Dear Edkad,

Send me the code that you run, if you use demo account that means you have one account for your client.

Edakad
02-24-2015, 06:19 PM
Dear Hassn

This is the code, it is part of a work in progress script. It sends a stop limit buy order from main. The result of the order is shown as suscessful but now I am not getting the order in ordersTotal()


dim closeAtDayEnd as Boolean = false
dim distance as double = 5
dim stoploss as double = 50
dim takeProfit as double = 100
dim lot as double = 0.1
dim trailingStop as double = 50
dim slippage as integer = 5
dim hoursStart as integer = 19
dim ocoSymbol as string = "EUR/USD"

dim Point as Double = 0.0001 ''' Point Value, set as per number of decimal places for the Symbol



private function OpenPendingOrder(pType,pLots,pLevel,sl, tp)

dim xAsk as double
dim xBid as double

ClientCode.SymbolInfoDouble(ocoSymbol, VTLGeneral.ENUM_SYMBOL_INFO_DOUBLE.SYMBOL_BID , xAsk)
ClientCode.SymbolInfoDouble(ocoSymbol, VTLGeneral.ENUM_SYMBOL_INFO_DOUBLE.SYMBOL_BID , xBid)

Select case pType

case VTLServerApplication.OperationTypeEnum.BuyType

OpenPendingOrder = ClientCode.NewLimitOrder( VTLServerApplication.OperationTypeEnum.BuyType , ClientCode.GetSymbolByName(ocoSymbol).ID, CDBL(pLots), CDBL(xAsk-pLevel*point), CDBL((xAsk-pLevel*Point)-sl*Point), CDBL((xAsk-pLevel*Point)+tp*Point))
GUI.msgDialog(openPendingOrder.tostring())
if OpenPendingOrder <> 1 then
'''PrintData("OCO NEW LIMIT BUY ORDER ERROR: " & ErrorDescription(GetLastError()))
end if
exit function


end select


end function





Public Sub main()


OpenPendingOrder(VTLServerApplication.OperationTyp eEnum.BuyType ,lot,distance,stopLoss, takeprofit)



GUI.MsgDialog ( ClientCode.OrdersTotal() )

dim i as integer
for i = 1 to ClientCode.ordersTotal()
ClientCode.DeleteSLTPOrder(ClientCode.OrderByIndex (i).OrderId)

next




End Sub

Hassan-HS
02-25-2015, 08:47 AM
Dear Edkad,


Please use this code....




dim closeAtDayEnd as Boolean = false
dim distance as double = 5
dim stoploss as double = 50
dim takeProfit as double = 100
dim lot as double = 0.1
dim trailingStop as double = 50
dim slippage as integer = 5
dim hoursStart as integer = 19
dim ocoSymbol as string = "EUR/USD"

dim Point as Double = 0.0001 ''' Point Value, set as per number of decimal places for the Symbol



private function OpenPendingOrder(pType,pLots,pLevel,sl, tp)

dim xAsk as double
dim xBid as double

xAsk=ClientCode.SymbolInfoDouble(ocoSymbol, VTLGeneral.ENUM_SYMBOL_INFO_DOUBLE.SYMBOL_Ask )
xBid=ClientCode.SymbolInfoDouble(ocoSymbol, VTLGeneral.ENUM_SYMBOL_INFO_DOUBLE.SYMBOL_BID )

Select case pType

case VTLServerApplication.OperationTypeEnum.BuyType

OpenPendingOrder = ClientCode.NewLimitOrder( VTLServerApplication.OperationTypeEnum.BuyType , ClientCode.GetSymbolByName(ocoSymbol).ID, CDBL(pLots), CDBL(xAsk-pLevel*point), CDBL((xAsk-pLevel*Point)-sl*Point), CDBL((xAsk-pLevel*Point)+tp*Point))
GUI.msgDialog(openPendingOrder.tostring())
if OpenPendingOrder <> 1 then
'''PrintData("OCO NEW LIMIT BUY ORDER ERROR: " & ErrorDescription(GetLastError()))
end if
exit function


end select


end function





Public Sub main()


OpenPendingOrder(VTLServerApplication.OperationTyp eEnum.BuyType ,lot,distance,stopLoss, takeprofit)



GUI.MsgDialog ( ClientCode.OrdersTotal() )

dim i as integer
for i = 1 to ClientCode.ordersTotal()
ClientCode.DeleteSLTPOrder(ClientCode.OrderByIndex (i).OrderId)

next




End Sub

Edakad
02-25-2015, 06:30 PM
Hassan, Thank You Dude

Edakad
02-25-2015, 06:48 PM
Hassan,

Another clarification.

Modified the main() like this and run


Public Sub main()


OpenPendingOrder(VTLServerApplication.OperationTyp eEnum.BuyType ,lot,distance,stopLoss, takeprofit)

GUI.MsgDialog("KKK")


GUI.MsgDialog ( ClientCode.OrdersTotal() )

dim i as integer
for i = 1 to ClientCode.ordersTotal()
ClientCode.DeleteSLTPOrder(ClientCode.OrderByIndex (i).OrderId)

next


GUI.MsgDialog("xxx")

End Sub


Now the first message I got was xxx,

To test further just simply run this code


Public Sub main()


gui.msgDialog ("XXX")
gui.msgDialog ("YYY")

End Sub


first message is YYY and then XXX, it appears the excution in main happens from the last line upward. Pls check this and guide

:confused:

Hassan-HS
02-26-2015, 11:54 AM
Dear Edkad,

Be advised that "GUI.MSGDialog()" method shows a window in non-modal state that's means the code following will continue executing even the dialog box is not closed, So you will see the latest dialog on the top.

Edakad
02-26-2015, 06:21 PM
Hello Hassan,

That is gr8, and it is useful to show messages in the GUI

Thanks a lot

Edakad
02-26-2015, 07:43 PM
Dear Hassan,

Another questions

1. Is it possible to run more than one instance of a Server Script at the same time. I mean, to run script1 on symbol EUR/USD with certain parameters and at the same time run another instance of same script1 with same or different set of parameters os GBP/USD. If possible please explain the methodology. (The alternative in my mind is copy script1 to another name and run with the second symbol). This is similar to attaching the same indicator to 2 charts.

Thanking you

Hassan-HS
02-27-2015, 04:27 PM
Hello Edkad,


Yes you can run many scripts in the same time and have to make multiple copies of the same script.

Edakad
03-01-2015, 11:13 AM
Thank you Hassan