Margin used to open a position.

 

I am working an a indicator that gives me certain information about the currencies I trade.

One part of this is the amount of Margin Used to open a trade.

Market Info(NULL,MODE_MARGIN REQUIRED) works just fine as long as the "quote" part of the symbol is USD but it does nothing if USD is the "base" part of the symbol.

Anyone know how to calculate the amount of Margin needed to open a trade if the base is USD?

 
4x_Gypsy:

I am working an a indicator that gives me certain information about the currencies I trade.

One part of this is the amount of Margin Used to open a trade.

Market Info(NULL,MODE_MARGIN REQUIRED) works just fine as long as the "quote" part of the symbol is USD but it does nothing if USD is the "base" part of the symbol.

Anyone know how to calculate the amount of Margin needed to open a trade if the base is USD?

Wow nobody knows?
 
It works perfectly ok for me whether USD is the first or second currency in the pair.
 
GumRai:
It works perfectly ok for me whether USD is the first or second currency in the pair.
When USD is the first pair I get $2000 for a Standard Lot , but when I place a trade the Margin Used to open the trade varies wildly.
 
Use AccountFreeMarginCheck and you don't care.
  • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
  • Account Balance * percent = RISK = (OrderOpenPrice - OrderStopLoss)*DIR * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)
  • Do NOT use TickValue by itself - DeltaPerlot
  • You must normalize lots properly and check against min and max.
  • You must also check FreeMargin to avoid stop out
     
    4x_Gypsy:
    When USD is the first pair I get $2000 for a Standard Lot , but when I place a trade the Margin Used to open the trade varies wildly.
    You are wrong.
     
    WHRoeder:
    Use AccountFreeMarginCheck and you don't care.

    Here is the code I am using.

    I only won't the see what the Margin Used to open a trade is, it has nothing to do with a stoploss.

    Please excuse the messy code, I am still working on it.

    //Margin Required
       double MarginRequired=NormalizeDouble(MarketInfo(NULL,MODE_MARGINREQUIRED),Digits);
    
       double Pip_Value=0;
       if(Digits==2 || Digits==3) Pip_Value=(0.0001/Bid)*100000;
       if(Digits==4 || Digits==5) Pip_Value=((0.0001/Bid)*100000)*Bid;
    
       ObjectCreate("MarginRequired L",OBJ_LABEL,SubWindow,0,0);
       ObjectSetText("MarginRequired L","MarginRequired",FontSize,Font,FontColor);
       ObjectSet("MarginRequired L",OBJPROP_CORNER,Corner);
       ObjectSet("MarginRequired L",OBJPROP_XDISTANCE,625);
       ObjectSet("MarginRequired L",OBJPROP_YDISTANCE,15);
    
       ObjectCreate("PipValue L",OBJ_LABEL,SubWindow,0,0);
       ObjectSetText("PipValue L","PipValue",FontSize,Font,FontColor);
       ObjectSet("PipValue L",OBJPROP_CORNER,Corner);
       ObjectSet("PipValue L",OBJPROP_XDISTANCE,800);
       ObjectSet("PipValue L",OBJPROP_YDISTANCE,15);
    
    //Margin Required Standard Lot
       ObjectCreate("Margin Required Standard Lot L",OBJ_LABEL,SubWindow,0,0);
       ObjectSetText("Margin Required Standard Lot L","Standard Lot",FontSize,Font,FontColor);
       ObjectSet("Margin Required Standard Lot L",OBJPROP_CORNER,Corner);
       ObjectSet("Margin Required Standard Lot L",OBJPROP_XDISTANCE,600);
       ObjectSet("Margin Required Standard Lot L",OBJPROP_YDISTANCE,30);
    
       ObjectCreate("Margin Required Standard Lot C",OBJ_LABEL,SubWindow,0,0);
       ObjectSetText("Margin Required Standard Lot C",DoubleToStr(MarginRequired,2),FontSize,Font,FontColor);
       ObjectSet("Margin Required Standard Lot C",OBJPROP_CORNER,Corner);
       ObjectSet("Margin Required Standard Lot C",OBJPROP_XDISTANCE,700);
       ObjectSet("Margin Required Standard Lot C",OBJPROP_YDISTANCE,30);
    
       ObjectCreate("Pip Value Standard Lot C",OBJ_LABEL,SubWindow,0,0);
       ObjectSetText("Pip Value Standard Lot C",DoubleToStr(Pip_Value,2),FontSize,Font,FontColor);
       ObjectSet("Pip Value Standard Lot C",OBJPROP_CORNER,Corner);
       ObjectSet("Pip Value Standard Lot C",OBJPROP_XDISTANCE,800);
       ObjectSet("Pip Value Standard Lot C",OBJPROP_YDISTANCE,30);
    
    //Margin Required Mini Lot
       ObjectCreate("Margin Required Mini Lot L",OBJ_LABEL,SubWindow,0,0);
       ObjectSetText("Margin Required Mini Lot L"," Mini Lot",FontSize,Font,FontColor);
       ObjectSet("Margin Required Mini Lot L",OBJPROP_CORNER,Corner);
       ObjectSet("Margin Required Mini Lot L",OBJPROP_XDISTANCE,600);
       ObjectSet("Margin Required Mini Lot L",OBJPROP_YDISTANCE,45);
    
       ObjectCreate("Margin Required Mini Lot C",OBJ_LABEL,SubWindow,0,0);
       ObjectSetText("Margin Required Mini Lot C",DoubleToStr(MarginRequired/10,2),FontSize,Font,FontColor);
       ObjectSet("Margin Required Mini Lot C",OBJPROP_CORNER,Corner);
       ObjectSet("Margin Required Mini Lot C",OBJPROP_XDISTANCE,700);
       ObjectSet("Margin Required Mini Lot C",OBJPROP_YDISTANCE,45);
    
       ObjectCreate("Pip Value Mini Lot C",OBJ_LABEL,SubWindow,0,0);
       ObjectSetText("Pip Value Mini Lot C",DoubleToStr(Pip_Value/10,2),FontSize,Font,FontColor);
       ObjectSet("Pip Value Mini Lot C",OBJPROP_CORNER,Corner);
       ObjectSet("Pip Value Mini Lot C",OBJPROP_XDISTANCE,800);
       ObjectSet("Pip Value Mini Lot C",OBJPROP_YDISTANCE,45);
    
    //Margin Required Micro Lot
       ObjectCreate("Margin Required Micro Lot L",OBJ_LABEL,SubWindow,0,0);
       ObjectSetText("Margin Required Micro Lot L"," Micro Lot",FontSize,Font,FontColor);
       ObjectSet("Margin Required Micro Lot L",OBJPROP_CORNER,Corner);
       ObjectSet("Margin Required Micro Lot L",OBJPROP_XDISTANCE,600);
       ObjectSet("Margin Required Micro Lot L",OBJPROP_YDISTANCE,60);
    
       ObjectCreate("Margin Required Micro Lot C",OBJ_LABEL,SubWindow,0,0);
       ObjectSetText("Margin Required Micro Lot C",DoubleToStr(MarginRequired/100,2),FontSize,Font,FontColor);
       ObjectSet("Margin Required Micro Lot C",OBJPROP_CORNER,Corner);
       ObjectSet("Margin Required Micro Lot C",OBJPROP_XDISTANCE,700);
       ObjectSet("Margin Required Micro Lot C",OBJPROP_YDISTANCE,60);
    
       ObjectCreate("Pip Value Micro Lot C",OBJ_LABEL,SubWindow,0,0);
       ObjectSetText("Pip Value Micro Lot C",DoubleToStr(Pip_Value/100,2),FontSize,Font,FontColor);
       ObjectSet("Pip Value Micro Lot C",OBJPROP_CORNER,Corner);
       ObjectSet("Pip Value Micro Lot C",OBJPROP_XDISTANCE,800);
       ObjectSet("Pip Value Micro Lot C",OBJPROP_YDISTANCE,60);
    
    //Margin Required Penny Lot
       ObjectCreate("Margin Required Penny Lot L",OBJ_LABEL,SubWindow,0,0);
       ObjectSetText("Margin Required Penny Lot L"," Penny Lot",FontSize,Font,FontColor);
       ObjectSet("Margin Required Penny Lot L",OBJPROP_CORNER,Corner);
       ObjectSet("Margin Required Penny Lot L",OBJPROP_XDISTANCE,600);
       ObjectSet("Margin Required Penny Lot L",OBJPROP_YDISTANCE,75);
    
       ObjectCreate("Margin Required Penny Lot C",OBJ_LABEL,SubWindow,0,0);
       ObjectSetText("Margin Required Penny Lot C",DoubleToStr(MarginRequired/1000,2),FontSize,Font,FontColor);
       ObjectSet("Margin Required Penny Lot C",OBJPROP_CORNER,Corner);
       ObjectSet("Margin Required Penny Lot C",OBJPROP_XDISTANCE,700);
       ObjectSet("Margin Required Penny Lot C",OBJPROP_YDISTANCE,75);
    
       ObjectCreate("Pip Value Penny Lot C",OBJ_LABEL,SubWindow,0,0);
       ObjectSetText("Pip Value Penny Lot C",DoubleToStr(Pip_Value/1000,2),FontSize,Font,FontColor);
       ObjectSet("Pip Value Penny Lot C",OBJPROP_CORNER,Corner);
       ObjectSet("Pip Value Penny Lot C",OBJPROP_XDISTANCE,800);
       ObjectSet("Pip Value Penny Lot C",OBJPROP_YDISTANCE,75);//+------------------------------------------------------------------+
     
    eevviill:
    You are wrong.

    Really ?

    Prove it.

     
    Donald Gibson:

    I am working an a indicator that gives me certain information about the currencies I trade.

    One part of this is the amount of Margin Used to open a trade.

    Market Info(NULL,MODE_MARGIN REQUIRED) works just fine as long as the "quote" part of the symbol is USD but it does nothing if USD is the "base" part of the symbol.

    Anyone know how to calculate the amount of Margin needed to open a trade if the base is USD?

    It's pretty simple really; you just have to convert one to another at the current rate.  This can be challenging if you have something like GBPJPY and you want to know the margin in USD.  But if the base currency *is* USD, you basically use the price.

    e.g. if EURUSD is trading at $120, then at 100:1 leverage, and 100,000 EUR for a contract, (100,000 EUR is worth $140,000) so it will cost $1400 at 100:1.  $700 at 200:1.   So at 100:1 leverage, 0.01 lots of GBPUSD trading at $1.34 will cost $134,000 / 200 X 0.01 lots = $6.70

    If you *are* doing AUDNZD (for example) and want to know margin in dollars, then you have to figure it in NZD (us AUD) and convert to USD at the current NZDUSD (or AUDUSD) rate.