Hi All,

 

I need a help to find a way to calculate Margin Closeout Value dynamically for OANDA live trading to close some ill position when it comes to margin close out condition

In Oanda live trading If your Margin Closeout Value falls to less than half of your Margin Used, all open positions will be automatically closed using the current fxTrade rates at the time of closing. 

The Margin Closeout Value is equal to your balance plus your unrealized P/L from all open positions, converted into the currency of the account, all calculated using the current midpoint rates. 

I would like to check every minute or second if Margin Closeout Value( Balance+TotalUnrealised Profit) < Margin Used*0.6 and start to close some bad positions to avoid margin closeout. I can access to Unrealised profit (self.Portfolio.TotalUnrealisedProfit) and Total Margin Used (self.Portfolio.TotalMarginUsed), however I could not find a way to access dynamically the account balance, since it changes every downsizing of ill positions. Any advice ?

 

Best Regards

M.YILDIZ

Author