MPCandle
Download scriptThis tool is designed to identify significant price levels by analyzing how frequently the market interacts with specific prices over a defined timeframe. Instead of looking at simple trends, it looks for "congestion zones"—prices where the market has spent the most time or repeated its activity most often.
How the Logic Works
1. Timeframe Synchronization The script works by breaking down your current chart's timeframe into smaller "base units." For example, if you are looking at a large timeframe but set the base period to a smaller one (like 1 minute), the tool will scan through all those smaller intervals to see what happened during the current bar.
2. Price Frequency Mapping For every historical bar on your chart, the logic performs a deep dive:
- It examines every small price movement within that specific period.
- It tracks how many times specific closing prices occur.
- Essentially, it creates a "hit list" of prices and counts how many times each one is touched or repeated.
3. Identifying the "Focus Price" Once the script has finished counting all occurrences in a period, it identifies the price with the highest number of occurrences (the maximum count).
- The tool then marks this specific price on your chart as the Focus Buffer.
- This represents the most significant "gravity point" for that period—the price level where the market showed the most consensus or activity.
4. Visual Feedback To make this data easy to read, the script provides two types of visual information:
- Markers: It places arrows on the chart to pinpoint exactly where these high-frequency focus prices are located.
- Activity Scores: If enabled, it displays text labels above those markers. These numbers tell you exactly how many times that specific price was "hit" or repeated during that timeframe, giving you a sense of the market's intensity at that level.
Summary for the User
Think of this script as a "popularity contest" for prices. Rather than showing you where the price went, it shows you where the price stayed. By highlighting the levels with the highest frequency of occurrence, it helps you identify key zones of support, resistance, or heavy trading activity that might be overlooked by standard moving averages or trend lines.
//+------------------------------------------------------------------+
//| MPCandle.mq4 |
//| Copyright ?2013, Walter Choy |
//| brother3th@yahoo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2013, Walter Choy"
#property link "brother3th@yahoo.com"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow
#property indicator_width1 2
//--- parameters
extern string desc = "(Base on PERIOD values, must be smaller than the chart time frame) base_period = 1, 5, 15, 30, 60, 240...etc.";
extern int base_period = 1; //set base_period to 1 is best for M5 and M15; set to 5 is best for H4 and D1
extern int max_counting_bars = 250;
extern bool show_static = true;
extern int static_show_n = 250;
extern color static_txt_color = Black;
//--- buffers
double FocusBuffer[];
double tempBuffer[500][2];
double staticBuffer[];
int idx = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(2);
IndicatorDigits(Digits);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,159);
SetIndexBuffer(0,FocusBuffer);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1, DRAW_NONE);
SetIndexBuffer(1, staticBuffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
for (int n=0; n<static_show_n; n++){
string objname = "MPC_STATIC_" + n;
if(ObjectFind(objname) != -1){
ObjectDelete(objname);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int i = Bars - counted_bars;
int j, k;
//----
if(i > max_counting_bars) i = max_counting_bars;
double interval = Period() / base_period;
while(i >= 0){
// Clear tempBuffer
ArrayInitialize(tempBuffer, 0);
//for (j=0; j<=idx; j++){
// tempBuffer[j][0] = 0;
// tempBuffer[j][1] = 0;
//}
// For each trade period, counting the occurrence
idx = 0;
for(j=0; j<interval; j++){
if(TimeCurrent() >= Time[i]+j*base_period*60){
double cp = NormalizeDouble(iClose(NULL, base_period, iBarShift(NULL, base_period, Time[i]+j*base_period*60)), Digits - 1);
for(k=0; k<idx; k++){
if(tempBuffer[k][0] == cp){
break;
}
}
if (tempBuffer[k][0] == 0) tempBuffer[k][0] = cp;
tempBuffer[k][1]++;
idx++;
}
}
// Found out the max counting price
int MaxNum = 0; int MaxIdx = 0;
for (j=0; j<=idx; j++){
if(MaxNum < tempBuffer[j][1]){
MaxNum = tempBuffer[j][1];
MaxIdx = j;
}
}
// Set the price into indicator array
FocusBuffer[i] = tempBuffer[MaxIdx][0];
staticBuffer[i] = MaxNum;
i--;
}
if(show_static){
double sp = (WindowPriceMax() - WindowPriceMin()) * 0.01;
for (int n=0; n<static_show_n; n++){
string objname = "MPC_STATIC_" + n;
if(ObjectFind(objname) == -1){
ObjectCreate(objname, OBJ_TEXT, 0, 0, 0);
}
ObjectSet(objname, OBJPROP_TIME1, Time[n]);
ObjectSet(objname, OBJPROP_PRICE1, FocusBuffer[n] - sp);
ObjectSetText(objname, DoubleToStr(staticBuffer[n], 0), 6, "Arial", static_txt_color);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments