_x_BidAskLogger
Download scriptThe Bid Ask Logger is a specialized monitoring tool designed for the MetaTrader 4 platform. Its primary purpose is to provide traders with a visual history of price fluctuations—specifically tracking the "Ask" and "Bid" prices—over a specific period of recent market activity.
Core Functionality
Instead of looking at current live prices in isolation, this tool creates a dedicated visual window that maps out how these prices have behaved over time. It allows you to observe the relationship between buying and selling prices more clearly by plotting them as distinct lines.
How the Logic Works
The script operates based on the following logic:
- Historical Tracking: The user can define a specific number of "ticks" (the smallest unit of price movement) to be displayed. For example, if set to 500, the tool will maintain a visual record of the last 500 movements.
- Dynamic Updates: Every time the market moves (a new tick occurs), the script captures the most recent Bid and Ask prices. It then "shifts" the previous data points forward to make room for this new information, creating a continuous scrolling history.
- Data Visualization:
- The Ask price (the price at which you can buy) is represented by one colored line.
- The Bid price (the price at which you can sell) is represented by a second colored line.
- User Interface: Upon loading, the tool automatically generates a small informative label on your chart to identify the indicator and its settings, ensuring the interface remains organized.
Summary for the Trader
This tool acts like a "heart rate monitor" for the spread. By viewing the Bid and Ask lines simultaneously in a separate window, you can more easily identify patterns in market liquidity, observe how wide the gap between buying and selling prices becomes during volatile periods, and see historical price trends that might not be as obvious on a standard candlestick chart.
//+------------------------------------------------------------------+
//| 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 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2
extern int LastTicks = 500;
double Spread_Ask[];
double Spread_Bid[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
IndicatorBuffers(2);
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, Spread_Ask);
SetIndexStyle(1, DRAW_LINE);
SetIndexBuffer(1, Spread_Bid);
short_name="Bid Ask Logger ("+LastTicks+")";
IndicatorShortName(short_name);
SetIndexLabel(0, "ASK");
SetIndexLabel(1, "BID");
objectCreate("mrt",10,10,"CopyRight by Mr. T @ www.codeforex.com ");
for (int i=0; i<LastTicks; i++)
{
Spread_Ask[i] = EMPTY_VALUE;
Spread_Bid[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_Ask[i-1]!=EMPTY_VALUE) Spread_Bid[i] = Spread_Bid[i-1];
if (Spread_Bid[i-1]!=EMPTY_VALUE) Spread_Ask[i] = Spread_Ask[i-1];
}
Spread_Bid[0] = Bid;
Spread_Ask[0] = Ask;
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