notonlyspreadv1.01
Download scriptThis tool is designed to provide traders with real-time visibility into market liquidity and volatility by monitoring the "Spread"—the difference between the белй buying and selling prices of a currency or asset. By displaying these metrics directly on your trading chart, it helps you understand the cost of entering and exiting positions more clearly.
How the Logic Works
The script operates by continuously collecting data points every time the market moves (every "tick"). Here is a breakdown of the specific information it calculates:
Real-Time Spread Tracking The tool identifies the current market spread instantly. As new price movements occur, it captures the live value so you can see exactly how much the broker is charging at that specific second.
Dynamic Statistics (Highs and Lows) Throughout your trading session, the script keeps a running record of the highest and lowest spreads encountered. This allows you to visualize the "spread range," helping you identify periods of extreme market volatility versus periods of relative calm.
Moving Average Calculation Instead of just showing a single snapshot, the tool calculates a running average of the spread based on all price movements since the indicator was started. This smooths out temporary spikes and gives you a much more accurate picture of the "typical" cost of trading for that specific asset during your session.
Market Speed Analysis One of the unique features of this script is its ability to measure market activity. It tracks how many price updates (ticks) occur within a specific timeframe (which you can customize). By converting these ticks into a "Ticks Per Minute" value, it provides a clear metric for market speed, helping you gauge how "active" or "fast" the current market environment is.
User Experience
The information is displayed as a clean text overlay on your chart. To keep the data relevant and easy to read, the tool refreshes its display automatically at set intervals (defaulting to every 30 seconds). This ensures that while the math is happening constantly in the background, you are only presented with organized, updated figures at regular intervals.
//+------------------------------------------------------------------+
//| NotOnlySpread.mq4 |
//| Spread, its average, its maximum and minimum,|
//| and ticks per second (market speed) on comment.|
//+------------------------------------------------------------------+
#property copyright "Fabrizio"
#property link "fajuzi@yahoo.it"
#property version "1.01"
#property indicator_chart_window
input int digi=1;//digits format
input int sec=30;//seconds to refresh
input bool clear=false;//if true clears comment after closing indicator
double newspread,averagespread,maxpread,minspread,cumulative;
int tickscount;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
EventSetTimer(sec);
averagespread=MarketInfo(Symbol(),MODE_SPREAD);
maxpread=averagespread; minspread=averagespread;
tickscount=0; cumulative=0.0;
Comment("INSTANT SPREAD = ",DoubleToString(averagespread,digi),
"; PLEASE WAIT ",IntegerToString(sec)," SECONDS...");
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
EventKillTimer();
if(clear==true) Comment("");
}
//+------------------------------------------------------------------+
//| On timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
Comment("INSTANT SPREAD = ",DoubleToString(newspread,digi),
"; AVERAGE = ",DoubleToString(averagespread,digi),
"; MAX = ",DoubleToString(maxpread,digi),
"; MIN = ",DoubleToString(minspread,digi),
"; TICKS/MINUTE SPEED = ",IntegerToString(60*tickscount/sec),
"; ",IntegerToString(sec)," SECONDS TO REFRESH...");
newspread=averagespread; maxpread=averagespread; minspread=averagespread;
tickscount=0; cumulative=0.0;
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
tickscount++;
newspread=MarketInfo(Symbol(),MODE_SPREAD);
cumulative+=newspread;
maxpread=MathMax(maxpread,newspread);
minspread=MathMin(minspread,newspread);
averagespread=cumulative/tickscount;
return(rates_total);
}
//+------------------------------------------------------------------+
Comments