Display the Closeout price (margin call) routine

 

I'm trying to write a routine that will display the Margin Call Closeout price (margin call) for the current trade. I got this far but something tells me is just not this easy. I've compared my results to the OANDA Margin Closeout Calculator, http://fxtrade.oanda.com/analysis/margin-call-calculator and my results don't match. Anybody have an idea of what I'm doing wrong?

int start()
  {
      double unitAmount = 6000; // $0.60
      double midPrice = (Ask+Bid)/2; // close enough
      string buySell = "Sell"; // Buy or Sell for direction
      
      Print("======= Start of Margin CloseOut Calculation =======");
      if (buySell == "Buy")
         Print("Buy Margin CloseOut at price: " + ((AccountFreeMargin() / unitAmount) + midPrice) );
      if (buySell == "Sell")
         Print("Sell Margin CloseOut at price: " + (midPrice - (AccountFreeMargin() / unitAmount)) );
      Print("AccountFreeMargin: "+AccountFreeMargin());
      Print("unitAmount: "+unitAmount);
      Print("midPrice: "+midPrice);
       
      return(0);
  }
 
MisterDog:

I'm trying to write a routine that will display the Margin Call Closeout price (margin call) for the current trade. I got this far but something tells me is just not this easy. I've compared my results to the OANDA Margin Closeout Calculator, http://fxtrade.oanda.com/analysis/margin-call-calculator and my results don't match. Anybody have an idea of what I'm doing wrong?

I highly recommend searching for articles on mql.com which discuss Margins. There might be some which gives you the formula directly. Or will provide you with enough info to find what you're missing.

In order for me to answer this question for you, I'll have to find those articles, find the formula or figure them out. Then compare them to Oanda. If it doesn't match, I'll have to figure out how Oanda_Calculates their StopOut. Example in_Percentage vs in_AbsoluteValue etc then fix.

 

I am beginning to see the complexity of this project. I think I will pursue something easier for now. -- thanks.

For OANDA here are the instructions to calculate a Margin Callout, http://fxtrade.oanda.co.uk/help/how-to-calculate-margin-call

And here is the OANDA Margin Callout calculator, http://fxtrade.oanda.ca/analysis/margin-call-calculator

At least I got that far ;-) 

Reason: