Exiting a specific trade

Posted By: mustang

Exiting a specific trade - 10/13/14 19:51

------- The documentation below -------------
exitTrade (TRADE* trade, var price, int lots)
Exits a particular trade at market or at a given price limit.
Parameters:
algo Optional algorithm identifier of the trade, or 0 for the current Algo, or "*" for exiting all open trade positions with the current asset regardless of their identifiers.
trade The patricular trade to be closed.
-------------- My question below ------------
Could someone please post an example of code for achieving this?
I have multiple assets and I want to exit a specific asset under specific conditions. Example: Exit USD/JPY of size 1 but keep USD/JPY of size 2 open.
Posted By: jcl

Re: Exiting a specific trade - 10/14/14 13:28

The simplest way is enumerating all open trades and closing the trades that fulfil the condition, like this:

Code:
for(open_trades) {
   if(TradeAsset == "USD/JPY" and TradeLots == 1)
      exitTrade(ThisTrade);
}

Posted By: mustang

Re: Exiting a specific trade - 10/14/14 16:31

Thank you very much JCL and Zorro team, I love the simplicity!
© 2024 lite-C Forums