Download MetaTrader 5
To add comments, please log in or register
Do you want to order an application? Find out how to obtain the desired result
Donald Gibson
483
Donald Gibson 2015.08.07 09:50 

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?

Donald Gibson
483
Donald Gibson 2015.08.09 01:16  
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?
Keith Watford
Moderator
7918
Keith Watford 2015.08.09 01:54  
It works perfectly ok for me whether USD is the first or second currency in the pair.
Donald Gibson
483
Donald Gibson 2015.08.09 09:15  
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.
whroeder1
13619
whroeder1 2015.08.09 12:16  
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
    Vasyl Nosal
    18211
    Vasyl Nosal 2015.08.09 12:23  
    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.
    Donald Gibson
    483
    Donald Gibson 2015.08.09 13:41  
    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);//+------------------------------------------------------------------+
    Donald Gibson
    483
    Donald Gibson 2015.08.09 13:42  
    eevviill:
    You are wrong.

    Really ?

    Prove it.

    /
    To add comments, please log in or register