ShowImportantParams
Download scriptThis script is designed to act as an information dashboard for MetaTrader users. Its primary purpose is to display essential trading parameters and account statistics directly on the chart in real-time, allowing you to monitor critical data at a glance without having to navigate through complex menus.
How it Works
1. Data Collection and Smoothing The script actively monitors the "Spread" (the difference between the buy and sell prices) of the specific financial instrument you are viewing. To prevent the numbers from jumping around erratically due to minor market fluctuations, it uses a smoothing logic. It tracks the spread over a series of recent price movements and calculates an average, providing a more stable and readable value.
2. Real-Time Calculations Beyond just displaying raw data, the script performs background calculations to provide deeper insights:
- Cost Analysis: It calculates the cost of trading a standard lot based on the current smoothed spread and the currency's tick value.
- Account Health: It fetches your account's leverage, margin requirements, and specific "Stop Out" levels (the point at which a broker may close your positions).
3. Visual Display The script automatically creates a list of text labels on your chart. These labels are organized vertically and updated instantly as the market moves. The information provided includes:
- Margin Requirements: How much capital is needed for 4 lots.
- Leverage: Your current account leverage ratio.
- Spread Metrics: Both the smoothed average spread and the immediate live spread.
- Trading Limits: The "Stop Level" (minimum distance for opening/closing orders).
- Risk Thresholds: Your specific Margin Call and Stop Out percentages.
4. User Customization While the logic remains consistent, the script allows you to customize the visual presentation through simple settings. You can adjust the text size, color, and font style, as well as the exact position on the screen where the information block appears, ensuring it doesn't obstruct your view of the price action.
Summary for the Trader
Essentially, this tool acts as a "Status Bar" for your trading environment. It translates complex backend data—like tick values, margin modes, and smoothed spreads—into a readable summary on your screen, helping you stay informed about your account limits and current market costs in real-time.
//+------------------------------------------------------------------+
//| ShowImportantParams.mq4 |
//| Copyright 2016, Alexey Volchanskiy |
//| https://mql.gnomio.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016 June 30, Alexey Volchanskiy"
#property link "https://mql.gnomio.com/"
#property version "1.03"
#property strict
#property description "Indicator shows important params for current symbol and account"
#property indicator_chart_window
#property indicator_buffers 0
input int FontSize = 10;
input color FontColor = clrYellow;
input string FontName = "Tahoma";
input int XOffset = 10;
input int YOffset = 15;
input int SpreadSmoothTicks = 20;
string lNames[]={"Margin4lot=","Leverage=1:","SpreadSmooth=","SpreadPrice=","StopLevel=","StopOut=","MarginCall="};
double SpreadBuf[];
int SpreadBufIdx=0;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectsDeleteAll(0,"SIP");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnInit()
{
ArrayResize(SpreadBuf,SpreadSmoothTicks);
for(int n=0; n<SpreadSmoothTicks; n++)
SpreadBuf[n]=0;
SpreadBufIdx=0;
ObjectsDeleteAll(0,"SIP");
Sleep(200);
ChartRedraw();
Sleep(200);
for(int n=ArraySize(lNames)-1; n>=0; n--)
{
if(!CreateLabel("SIP_"+lNames[ArraySize(lNames)-1-n],XOffset,YOffset*n+YOffset))
Print("CreateLabel returns false, n = ",IntegerToString(n));
}
Sleep(200);
ChartRedraw();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int size=ArraySize(SpreadBuf);
SpreadBuf[SpreadBufIdx++]=Ask-Bid;
if(SpreadBufIdx >= SpreadSmoothTicks)
SpreadBufIdx = 0;
double sprd=0;
for(int n = 0; n < SpreadSmoothTicks; n++)
sprd += SpreadBuf[n];
sprd/=(double)SpreadSmoothTicks;
ResetLastError();
double price4lot;
Quote2Price(sprd,price4lot,Symbol());
ObjectSetString(0,"SIP_"+lNames[0],OBJPROP_TEXT,lNames[0]+DoubleToString(MarketInfo(Symbol(),MODE_MARGINREQUIRED),2));
ObjectSetString(0,"SIP_"+lNames[1],OBJPROP_TEXT,lNames[1]+IntegerToString(AccountLeverage()));
ObjectSetString(0,"SIP_"+lNames[2],OBJPROP_TEXT,lNames[2]+DoubleToString(sprd,_Digits) + ", RealSpread=" + DoubleToString(Ask - Bid,_Digits));
ObjectSetString(0,"SIP_"+lNames[3],OBJPROP_TEXT,lNames[3]+DoubleToString(price4lot,2));
ObjectSetString(0,"SIP_"+lNames[4],OBJPROP_TEXT,lNames[4]+DoubleToString(MarketInfo(Symbol(),MODE_STOPLEVEL),0));
ENUM_ACCOUNT_STOPOUT_MODE stop_out_mode=(ENUM_ACCOUNT_STOPOUT_MODE)AccountInfoInteger(ACCOUNT_MARGIN_SO_MODE);
string s=(stop_out_mode==ACCOUNT_STOPOUT_MODE_PERCENT)?" %":"";
ObjectSetString(0,"SIP_"+lNames[5],OBJPROP_TEXT,lNames[5]+DoubleToString(AccountInfoDouble(ACCOUNT_MARGIN_SO_SO),0)+s);
ObjectSetString(0,"SIP_"+lNames[6],OBJPROP_TEXT,lNames[6]+DoubleToString(AccountInfoDouble(ACCOUNT_MARGIN_SO_CALL),0)+s);
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool Quote2Price(double diff,double &price4lot,string symbol="EURUSD")
{
int dig=(int)MarketInfo(symbol,MODE_DIGITS);
if(dig == 0)
return(false); // symbol is none
double tickSize = MarketInfo(symbol, MODE_TICKSIZE); // ïóíêò â âàëþòå êîòèðîâêè (0,00001 äëÿ EURUSD íà 5-çíàêå)
double tickValue = MarketInfo(symbol, MODE_TICKVALUE); // ïóíêò â âàëþòå äåïîçèòà ($1 äëÿ EURUSD íà 5-çíàêå)
double price=diff/(tickSize/tickValue);
price4lot=NormalizeDouble(price,2);
return (true);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CreateLabel(string name,int x,int y=10)
{
if(!ObjectCreate(0,name,OBJ_LABEL,0,0,0))
return false;;
ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_LEFT_LOWER);
ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_LOWER);
ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,FontSize);
ObjectSetInteger(0,name,OBJPROP_COLOR,FontColor);
ObjectSetInteger(0,name,OBJPROP_SELECTABLE,true);
ObjectSetString(0,name,OBJPROP_FONT,FontName);
ChartRedraw();
return true;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTimer()
{
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
}
//+------------------------------------------------------------------+
Comments