_x_SpreadLogger

Download script
Author: Mr. T.
_x_SpreadLogger

Overview

The Spread Logger is a specialized monitoring tool designed for traders who need to visualize and track the "spread"—the difference between the buy and sell prices of a financial instrument—in real-time. Unlike standard price charts that focus on where the market is moving, this tool focuses on the cost of entering and exiting a trade, helping you identify periods of high volatility or liquidity issues.

How it Works

The logic behind this script can be broken down into three main functions:

1. Real-Time Data Capture The tool constantly communicates with the market to pull the current spread for the specific asset you are viewing. To make the data easier to read on a chart, the script automatically adjusts the raw numerical value (dividing it by ten) so that it fits comfortably within your visual workspace.

2. Historical Tracking (The "Memory") One of the key features of this script is its ability to remember past data. Instead of only showing you what the spread is right now, it maintains a rolling history. You can customize how many previous "ticks" (market updates) the tool should remember. It stores these previous values in a sequence, allowing you to see how the spread has fluctuated over a specific period rather than seeing a single, isolated number.

3. Visual Presentation The tool creates a dedicated window on your trading platform, separate from your main price candles.

  • The Line: It draws a continuous yellow line that represents the spread history. This allows you to visually identify "spikes"—sudden moments where the gap between buying and selling became wider.
  • Reference Levels: The tool includes pre-set horizontal levels (0.5, 1, 2, and 3) to help you quickly benchmark current market conditions against historical norms.
  • On-Screen Branding: It includes a small, non-intrusive text label on the screen to identify the tool and its origin.

Key Benefits for the User

  • Volatility Monitoring: By watching the line move, you can see if a broker's spread is widening during high-news events or low-liquidity hours (like market rollover).
  • Customizable Depth: You can adjust the "memory" of the logger to see as much or as little historical data as you need for your specific trading style.
  • Clean Interface: Because it opens in a separate window, it does not clutter your main price action, providing a clean way to monitor execution costs simultaneously.
Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
_x_SpreadLogger
//+------------------------------------------------------------------+
//|                                                 SpreadLogger.mq4 |
//|                                                           Mr. T. |
//|                                         http://www.codeforex.com |
//+------------------------------------------------------------------+
#property copyright "Mr. T."
#property link      "http://www.codeforex.com"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Yellow
#property indicator_width1 3
#property indicator_level1 0.5
#property indicator_level2 1
#property indicator_level3 2
#property indicator_level4 3

extern int LastTicks = 500;

double Spread_Value[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {

   string short_name;
   IndicatorBuffers(1);
   
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, Spread_Value);
   
   short_name="Spread Logger ("+LastTicks+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0, "SPREAD");
   objectCreate("mrt",10,10,"CopyRight by Mr. T @ www.codeforex.com ");
   for (int i=0; i<LastTicks; i++)
   {
    Spread_Value[i] = EMPTY_VALUE;
   }
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("mrt");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   for (int i=LastTicks-1;i>0;i--)
   {
      if (Spread_Value[i-1]!=EMPTY_VALUE) Spread_Value[i] = Spread_Value[i-1];      
   }
      
   Spread_Value[0] = MarketInfo(Symbol(),MODE_SPREAD)/10;
   
   return(0);
  }


//+------------------------------------------------------------------+
//    Create an Object -                                             |       
//+------------------------------------------------------------------+   
void objectCreate(string name,int x,int y,string text="",int size=12,
                  string font="Arial",color colour=Red)
  {
   ObjectCreate(name,OBJ_LABEL,1,0,0);
   ObjectSet(name,OBJPROP_CORNER,2);
   ObjectSet(name,OBJPROP_COLOR,colour);
   ObjectSet(name,OBJPROP_XDISTANCE,x);
   ObjectSet(name,OBJPROP_YDISTANCE,y);
   ObjectSetText(name,text,size,font,colour);
  }

Comments