PDA

View Full Version : Error in Update SL/TP



Birju
02-11-2014, 01:28 PM
Dear All,

I am updating SL/TP by "UpdateSLTPOrder" but it gives me "Invalid_Order_Id" error. I tried to display Order id and it shows perfectly. Please help me.

My code:
Dim SL
Dim OpenPrice
Dim pLot
Dim xticket
Dim TP
For i=1 to (PositionTotal())

IF (PositionSelect(PositionGetTicket(Cint(i)))) then
IF PositionGetSymbol(Cint(i)) = ChartSymbol(0) then

IF GetPositionType() = TRADE_ACTION_SELL then

PositionGetDouble POSITION_PRICE_OPEN,OpenPrice
PositionGetDouble POSITION_TP,TP
PositionGetDouble POSITION_SL,SL
PositionGetDouble POSITION_AMOUNT, pLot
xticket = PositionGetTicket(Cint(i))
if UpdateSLTPOrder (cLng(xticket),Cdbl(pLot),Cdbl(OpenPrice+StopLoss* Point),TP) then
MsgBox "Order has been Updated. Ticket : "&xticket
else
MsgBox ErrorDescription(GetLastError())
end if

End IF

IF GetPositionType() = TRADE_ACTION_BUY then

PositionGetDouble POSITION_PRICE_OPEN,OpenPrice
PositionGetDouble POSITION_TP,TP
PositionGetDouble POSITION_SL,SL
PositionGetDouble POSITION_AMOUNT, pLot

xticket = PositionGetTicket(Cint(i))
if UpdateSLTPOrder (cLng(xticket),Cdbl(pLot),Cdbl(OpenPrice-StopLoss*Point), TP) then
MsgBox "Order has been Updated. Ticket : "&xticket
Else
MsgBox ErrorDescription(GetLastError())

End If
End IF

End IF

End IF

Next



Stoploss & TakeProfit variable define globally.

Hassan-HS
02-11-2014, 03:26 PM
Hello Sir,



If you want to create SL or TP for a positions that do not have a SL and TP,you have to use NewSLTPOrder (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/3622)


In this function you have to pass the position ID



================================================== ==



If you want to create SL or TP for a specific positions that already have SL or TP, you have to use UpdateSLTPOrder (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/3632)



In this function you have to pass the manage order ID not the position ID...



This sample will help you to get the manage orders IDs that related to a specific position ID




Public Sub main()
Dim PositionID
PositionID=3666
If AccountInfoInteger(ACCOUNT_LOGIN) Then

If RequestManageOrders (Clng(PositionID)) Then

MsgBox "The Request has been sent to the server to get all manage orders related to ticket number 3666 "

Else

MsgBox ErrorDescription(GetLastError())

End If

End If

End Sub

'This event raised when calling RequestManageOrders method successfully

Public Sub OnManageOrdersReceived(manageOrders)

Dim i

' Receiving Manage Order related to Ticket 3666

For i = 1 To manageOrders.Count()

MsgBox CSTR(manageOrders. Orders(i))

Next

End Sub