PDA

View Full Version : Close all orders on specific pair Script



tjdm1980
11-22-2013, 02:34 PM
Are you able to create a script that closes all orders on a specific pair?

thanks much

Hassan-HS
11-22-2013, 03:26 PM
Dear sir,

The following code delete all orders for specific symbol, that you are entered it.




Sub Main ()


Dim Symbol
Dim ID
Symbol = InputBox("Please enter the symbol name?", "Close all positions")
If Symbol <> "" then
StringToUpper Symbol
For i=1 to OrdersTotal
OrderSelectByIndex(Cint(i))
ID=OrderGetID(Cint(i))
if OrderSymbol() = Symbol then
DeleteLimitOrder Clng(ID)
end if

Next
End If
End Sub




And this for all open positions:




Sub Main ()


Dim Symbol
Dim ID
Symbol = InputBox("Please enter the symbol name?", "Close all positions")
If Symbol <> "" then
StringToUpper Symbol
For i=1 to PositionTotal
ID=PositionGetTicket(Cint(i))
PositionSelect(Clng(ID))
if PositionGetSymbol(Cint(i)) = Symbol then
Dim Amount
PositionGetDouble 8,Amount
CloseMarketOrder Clng(ID) , Cdbl(Amount)
end if

Next
End If
End Sub



Note:

If you interest on V TL local script you can learn it

VTL course (http://www.hybrid-solutions.com/VTL%20Course.pdf)

VTL Docs:

VTL Server (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/2566)

VTL Client
(http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/2567)

tjdm1980
11-25-2013, 08:58 PM
thanks as always!

tjdm1980
11-25-2013, 09:21 PM
I copy and paste code, created script. The message box shows, I enter symbol (let's say "NZD/USD") and press OK, box disappears but nothing happens... please advise. thanks

Hassan-HS
11-26-2013, 07:26 AM
Dear Sir,

Make sure that your account is selected, and enter the symbol name without quotations.

Hassan-HS
01-09-2014, 10:05 AM
Dear Sir


Please update us if every thing is clear now or not, and let me know if you need any further assistance.