MPC
Download scriptThis tool, known as the Middle Point Channel (MPC), is designed to help traders visualize the dynamic price boundaries and the central equilibrium of a financial instrument over a specific timeframe. Instead of looking at just a single price point, it provides a visual "channel" that helps identify where the market is currently trading in relation to its recent highs and lows.
How the Logic Works
The script operates by scanning a predetermined window of historical data—defined by the user as the "Range." For every point on the chart, the tool performs three specific calculations:
- The Upper Bound: It looks back through the specified range to find the highest price reached. This line represents the recent resistance or peak.
- The Lower Bound: It looks back through the same range to find the lowest price reached. This line represents the recent support or valley.
- The Middle Point (MPC Line): This is the core of the indicator. It calculates the exact mathematical midpoint between that highest and lowest price. This line acts as a "fair value" indicator, showing you where the balance lies between the extreme highs and lows.
Key Features and Behavior
- Dynamic Adjustment: As new candles form and price action shifts, the boundaries and the middle point automatically recalculate. If a new high is hit, the upper boundary moves up; if a new low is hit, the lower boundary drops down.
- Visual Clarity: The indicator renders three distinct lines on your chart. By observing how the current price interacts with these three lines, traders can get a sense of whether the market is overextended (near the bounds) or returning to its "mean" (the middle line).
- Customizable Range: Users can adjust the "Range" parameter to make the channel more sensitive or broader. A smaller range focuses on immediate, short-term volatility, while a larger range captures more significant, long-term trends.
- Processing Efficiency: The script is designed to be efficient, with options to focus its calculations only on the most recent price action (the last bar) or to update across the entire visible history, depending on the user's preference for real-time analysis versus historical review.
In essence, this script provides a structural "map" of price movement, helping you see the boundaries of current market volatility and identify the center of gravity where the price tends to balance out.
//+------------------------------------------------------------------+
//| MPC.mq4 |
//| Copyright © 2007, Alexandre |
//| http://www.kroufr.ru/content/view/885/124/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Alexandre"
#property link "http://www.kroufr.ru/content/view/885/124/"
//----
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Magenta
#property indicator_color2 Red
#property indicator_color3 Aqua
//---- input parameters
extern int MPC_Range = 40;
extern bool LastBarOnly = true;
//---- buffers
double UppValueBuffer[];
double MidPointBuffer[];
double LowValueBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if (MPC_Range <= 1) { MPC_Range = 1; }
//---- indicators
IndicatorShortName("Middle Point Channel (" + MPC_Range + ")");
//----
SetIndexStyle(0, DRAW_LINE);
SetIndexLabel(0, "Upper MPC Bound");
SetIndexBuffer(0, UppValueBuffer);
SetIndexDrawBegin(0, MPC_Range);
//----
SetIndexStyle(1, DRAW_LINE);
SetIndexLabel(1, "MPC Line");
SetIndexBuffer(1, MidPointBuffer);
SetIndexDrawBegin(1, MPC_Range);
//----
SetIndexStyle(2, DRAW_LINE);
SetIndexLabel(2, "Lower MPC Bound");
SetIndexBuffer(2, LowValueBuffer);
SetIndexDrawBegin(2, MPC_Range);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
int Limit;
int i, cnt_bars;
double hhv, llv, m_pr;
static bool run_once;
static double m_pr_old;
//----
if(counted_bars < 0)
return(-1);
Limit = Bars - counted_bars;
// run once on start
if(run_once == false)
cnt_bars = Limit - MPC_Range;
else
if(LastBarOnly == false)
cnt_bars = Limit;
else
cnt_bars = 0;
m_pr = (High[cnt_bars] + Low[cnt_bars]) / 2.0;
//----
if(MathAbs(m_pr - m_pr_old) < Point)
return(0);
else
m_pr_old = m_pr;
//----
for(i = cnt_bars; i >= 0; i--)
{
hhv = High[iHighest(NULL, 0, MODE_HIGH, MPC_Range, i)];
llv = Low[iLowest (NULL, 0, MODE_LOW, MPC_Range, i)];
UppValueBuffer[i] = hhv;
MidPointBuffer[i] = (hhv + llv) / 2.0;
LowValueBuffer[i] = llv;
}
//----
if(run_once == false)
run_once = true;
//----
return(0);
}
//+------------------------------------------------------------------+
Comments