On FXCM, Usable margin % is calculated by free_margin/equity. It is a percent between 0 and 100. On metatrader (through interbankfx at least) the margin level % is calculated differently. I am trying to create an indicator or something that will display the usable margin % calculated like fxcm does. I have created an indicator that will show the usable margin % on a chart but I am having trouble determining if it is updating in real-time correctly. I was wondering if my code was correct for it to keep updating the usable margin % in real time regardless of the time frame of the chart the indicator is attached to. (I've also been curious if anyone else has made something like this.)
Thanks
Code:
#property indicator_chart_window
//---- input parameters
extern int decimals=6;
extern int Text_Size=10;
extern color Text_Color=White;
extern int X_Distance=10;
extern int Y_Distance=20;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int iBarsToCalc = Bars - IndicatorCounted();
if (iBarsToCalc < Bars) iBarsToCalc++;
// Iterate over bars
for (int i=iBarsToCalc-1;i>=0;i--) {
double free=AccountFreeMargin()/AccountEquity()*100;
ObjectCreate("comment_label",OBJ_LABEL,0,0,0);
ObjectSet("comment_label",OBJPROP_XDISTANCE,X_Distance);
ObjectSet("comment_label",OBJPROP_YDISTANCE,Y_Distance);
string words = "Usable Margin: "+DoubleToStr(free,decimals)+"%";
ObjectSetText("comment_label",words,Text_Size,"Arial",Text_Color);
WindowRedraw();
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+