GrabBuffers
Download scriptThis script serves as a diagnostic tool designed to help traders "peek under the hood" of other technical indicators in MetaTrader. When using complex custom indicators, it can often be difficult to know exactly which data points are being used to generate specific visual signals, such as color changes or trend lines. This script simplifies that process by extracting the raw numerical data from those hidden background layers (known as "buffers").
How the Logic Works
The core purpose of this tool is to reveal the invisible numbers behind the visuals. Most indicators store their data in a series of eight separate channels, or "buffers." Some channels might hold the actual value of a moving average, while others might act as "switches" that turn a bar red or green depending on certain conditions.
When you run this script:
- Data Extraction: It reaches out to a specific indicator (which you can define by name) and pulls the current numerical values from all eight of its available data channels simultaneously.
- Real-Time Reporting: It takes those raw numbers and prints them directly into your platform's "Experts" log.
- Visual Correlation: By looking at these numbers while watching the indicator on your chart, you can perform a manual "discovery" process. For example, if you notice the indicator changes color on your screen and simultaneously see a specific buffer number jump from 0 to 1 in the log, you have successfully identified which data source controls that visual signal.
Practical Applications for Traders
- Signal Identification: If an indicator changes color, this tool helps you identify exactly which hidden calculation triggered that change.
- Crossover Detection: For indicators like the MACD, it allows you to see the raw values of both the histogram and the trend line, making it easier to understand how they interact.
- Data Filtering: It helps distinguish between "active" data (numbers that move meaningfully) and "empty" data (large, arbitrary numbers that represent "No Value" in the visual display).
In short, this is a forensic tool for traders who want to move beyond just looking at what an indicator shows and start understanding the specific math it uses to produce those results.
//+------------------------------------------------------------------+
//| GrabBuffers.mq4 |
//+------------------------------------------------------------------+
// IndicatorName is the .mq4/.ex4 filename. You do not need to have
// the source code (i.e. .mq4 file) to read from the buffers.
//
// The Indicator you're analyzing does not have to be on the current
// chart, but it makes it easier because you have to analyze because
// you can compare the Buffer output with changes in the Indicator.
// For example, if the indicator changes color and suddenly a different
// buffer is being used, then it may be that that particular color
// is assigned to that buffer
//
// Look at the scale on the indicator right side. If the scale is
// 0.0000 to 0.0004 and you see the indicator at 0.0100 (you can
// also hover the mouse over the indicator to get the current value)
// and it moves to 0.0110 and the value of a buffer changes to match
// that, then you've discovered the buffer which is being used to
// carry the current value of the indicator.
//
// If a buffer has a huge number like 217344678.99, then that value
// is set to No Value in the indicator.
//
// The 8 accessible buffers (buffers 0 through 7) from iCustom are doubles, even if they
// only carry integer values in them
//
// A buffer can be used for storing a number (e.g. value of the ATR in the indicator window)
// or to trigger a particular color to be displayed. For example, Buffer 0 = Red,
// Buffer 1 = Green, Buffer 2 = Black. If Buffer 0 = 0, Buffer 1 = 1, and Buffer 2 = 0, then
// the indicator window bar will be Green. This has a great deal of benefit if you want to
// know when a bar changes colors for some trading entry/exit signal. When the buffers are
// used to store numbers, you can detect when there are cossovers. For example with MACD,
// you can see that Buffer 0 is the Histogram value and Buffer 1 is the Trendline value and
// by comparing Buffer0 with Buffer1 you can detect crossover.
//
// Frequently the value under the Properties tab for Color corresponds to the Buffer #. In
// the example of MACD, #0 = Gray and #1 = Red and the values for the Histogram are found
// in Buffer 0 and displayed as Gray. The value of the trendline is found in Buffer 1 and
// displayed in Red. With CCI, Buffer 0 holds the value of the CCI line. If you didn't
// have the source code for CCI, the changes values in Buffers 1, 2, and 3 might not have any
// meaning (you may not be able to figure what they're used for). Looking at the source code
// you can tell that they're used for storing rather than displaying data.
//
#property copyright ""
#property link ""
#property indicator_chart_window
extern string IndicatorName="ATR";
//+------------------------------------------------------------------+
int start()
{
Print("Indicator: "+IndicatorName+" Buffer0="+DoubleToStr(iCustom(NULL,0,IndicatorName,0,0),8)+" Buffer1="+DoubleToStr(iCustom(NULL,0,IndicatorName,1,0),8)+" Buffer2="+DoubleToStr(iCustom(NULL,0,IndicatorName,2,0),8)+" Buffer2="+DoubleToStr(iCustom(NULL,0,IndicatorName,3,0),8)+" Buffer4="+DoubleToStr(iCustom(NULL,0,IndicatorName,4,0),8)+" Buffer5="+DoubleToStr(iCustom(NULL,0,IndicatorName,5,0),8)+" Buffer6="+DoubleToStr(iCustom(NULL,0,IndicatorName,6,0),8)+" Buffer7="+DoubleToStr(iCustom(NULL,0,IndicatorName,7,0),8));
return(0);
}
Comments