PDA

View Full Version : NewSLTPOrder retruns 9 in result



nhasan
09-10-2013, 09:46 AM
Dear Team

I am trying to open a SLTP order for each open position with following function -

Private Function SetManageOrder ( mTicket as Integer, tLot as Double )
Dim m as Integer
Dim hasOrder as Boolean = False
Dim Result As VTLServerApplication.NewOrderResultEnum
For m = 1 to ClientCode.OrdersTotal()
IF ( ClientCode.OrderByIndex(m).OrderTicket = mTicket ) Then
hasOrder = True
End IF
Next m

IF hasOrder = False Then
Result = ClientCode.NewSLTPOrder ( mTicket, tLot )
End IF
End Function

But it fails with return code '9' in Result variable.
Can you please explain what is happening here?

Thanks
Naeem Hasan

Hassan-HS
09-10-2013, 12:29 PM
Welcome hasan,

The "9" means that you have entered wrong SL or TP price, please check the following link (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/1901)

You have invoked NewSLTPOrder (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/1850) without passing a value for the SL or the TP.

I have made some changes to your code, now it's work fine.



Public Sub main()
'''TODO: Script program start method
Dim TktID = 429235 ' GOLD (Buy postion)
Dim Lots = 1
SetManageOrder (TktID ,Lots)
End Sub

Private Function SetManageOrder ( mTicket as Integer, tLot as Double )
Dim m as Integer
Dim hasOrder as Boolean = False
Dim Result As VTLServerApplication.CallingResultsEnum

For m = 1 to ClientCode.OrdersTotal()
IF ( ClientCode.OrderByIndex(m).OrderTicket = mTicket ) Then
hasOrder = True
End IF
Next m
Dim SL,TP as double
SL=1100
TP=1500
IF hasOrder = False Then
Result = ClientCode.NewSLTPOrder (mTicket,tLot,SL,TP)
GUI.MSGDialog(Result)
End IF
End Function

nhasan
09-10-2013, 11:04 PM
Thanks

But as shown in SLTP function SL and TP is optional -

Public Function NewSLTPOrder(ByVal Ticket As Integer, ByVal Lots As Double, Optional ByVal SL As Object = "", Optional ByVal TP As Object = "") As CallingResultsEnum

Is there any way to open managed position without SL and TP?

In this EA SL and TP will be updated later based on market condition.

Thanks

b_morar
09-11-2013, 07:02 AM
Dear Hasan,

Yes the SL and TP are optional, But you must at least pass one of them.
So use this function when you have at least value for one of them.:o