This script functions as a technical analysis tool designed to visualize price momentum and market sentiment by processing historical price data into a three-color histogram. Instead of simply showing the raw movement of an asset, it calculates a complex underlying value based on how prices are distributed over a specific period.
Core Logic Overview
The tool operates by analyzing segments of price history to determine "Market Significance." Here is the step-by-step breakdown of that logic:
1. Data Collection and Windowing The script looks back at a user-defined number of bars (the "Length"). It focuses on the closing prices within this window to establish a baseline for recent market behavior.
2. Price Distribution Analysis Unlike simple moving averages that just look at the average price, this logic identifies clusters of price action. It organizes the data to see where the price has spent the most time and how frequently it has moved between different levels.
3. Statistical Weighting (Momentum Calculation) The script performs a mathematical calculation to determine the "strength" of the current trend. It evaluates the variance and positioning of prices relative to a central point. By calculating the product of the price deviations, it produces a single numerical value that represents the "velocity" or "momentum" of the market at that specific moment.
4. The Three-Color Signaling System The final output is a visual histogram that uses three distinct colors to represent the direction and intensity of this calculated momentum:
- Lime (Green): This appears when the current momentum value is increasing compared to the previous calculation, suggesting upward strength or positive acceleration.
- Red: This appears when the momentum value is decreasing, indicating a loss of strength or downward pressure.
- Purple: This serves as a neutral signal, appearing when there is no significant change in the momentum value between two points, indicating a period of consolidation or "sideways" stability.
Summary for the User
In essence, this tool filters out the "noise" of standard price fluctuations to provide a cleaner look at market energy. It tells you not just where the price is, but how strongly it is moving in a particular direction by comparing current statistical trends against recent history.
//+------------------------------------------------------------------+
//| 3color_ J_TPO.mq4 |
//| J_TPO: Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//| 3color: Copyright © 2005, Nikolay Kositsin |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, ."
#property link ""
#property indicator_separate_window
#property indicator_minimum -1.0
#property indicator_maximum 1.0
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Purple
//---- input parameters
extern int Len=14;
extern int CountBars=300;
//---- buffers
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- 3 additional buffers are used for counting.
IndicatorBuffers(4);
SetIndexBuffer(0,ind_buffer1);
SetIndexBuffer(1,ind_buffer2);
SetIndexBuffer(2,ind_buffer3);
SetIndexBuffer(3,ExtMapBuffer1);
SetIndexEmptyValue(0,0);
SetIndexEmptyValue(1,0);
SetIndexEmptyValue(2,0);
//---- name for DataWindow and indicator subwindow label
short_name="J_TPO_SignHist";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
SetIndexLabel(1,short_name);
SetIndexLabel(2,short_name);
//----
SetIndexStyle(0,DRAW_HISTOGRAM, STYLE_SOLID, 2);
SetIndexStyle(1,DRAW_HISTOGRAM, STYLE_SOLID, 2);
SetIndexStyle(2,DRAW_HISTOGRAM, STYLE_SOLID, 2);
SetIndexDrawBegin(0,Bars-CountBars);
SetIndexDrawBegin(1,Bars-CountBars);
SetIndexDrawBegin(2,Bars-CountBars);
return(0);
}
//+------------------------------------------------------------------+
//| J_TPO indicatop |
//+------------------------------------------------------------------+
int start()
{
//int limit;
//int counted_bars=IndicatorCounted();
//---- check for possible errors
//if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
//if(counted_bars>0) counted_bars--;
//limit=Bars-counted_bars;
//---- main loop
double f0, f8, f10, f18, f20, f28, f30, f40, k,
var14, var18, var1C, var20, var24, shift, value;
int f38, f48, var6, var12, varA, varE;
double arr0[300], arr1[300], arr2[300], arr3[300];
//---- J_TPO_SignHist------------------------------
double oldvalue, minuse;
//-------------------------------------------------
//f38=0;
for(int i=Bars-Len-100; i>=0; i--)
{
var14=0;
var1C=0;
if(f38==0)
{
f38=1;
f40=0;
if (Len-1>= 2) f30=Len-1;
else f30=2;
f48=f30+1;
f10=Close[i];
arr0[f38] = Close[i];
k=f48;
f18 = 12 / (k * (k - 1) * (k + 1));
f20 = (f48 + 1) * 0.5;
}
else
{
if (f38 <= f48) f38 = f38 + 1;
else f38 = f48 + 1;
f8 = f10;
f10 = Close[i];
if (f38 > f48)
{
for (var6 = 2; var6<=f48; var6++) arr0[var6-1] = arr0[var6];
arr0[f48] = Close[i];
}
else arr0[f38] = Close[i];
if ((f30 >= f38) && (f8 != f10)) f40 = 1;
if ((f30 == f38) && (f40 == 0)) f38 = 0;
}
if (f38 >= f48)
{
for (varA=1; varA<=f48; varA++)
{
arr2[varA] = varA;
arr3[varA] = varA;
arr1[varA] = arr0[varA];
}
for (varA=1; varA<=(f48-1); varA++)
{
var24 = arr1[varA];
var12 = varA;
var6 = varA + 1;
for (var6=varA+1; var6<=f48; var6++)
{
if (arr1[var6] < var24)
{
var24 = arr1[var6];
var12 = var6;
}
}
var20 = arr1[varA];
arr1[varA] = arr1[var12];
arr1[var12] = var20;
var20 = arr2[varA];
arr2[varA] = arr2[var12];
arr2[var12] = var20;
}
varA = 1;
while (f48 > varA)
{
var6 = varA + 1;
var14 = 1;
var1C = arr3[varA];
while (var14 != 0)
{
if (arr1[varA] != arr1[var6])
{
if ((var6 - varA) > 1)
{
var1C = var1C / (var6 - varA);
varE = varA;
for (varE=varA; varE<=(var6-1); varE++)
arr3[varE] = var1C;
}
var14 = 0;
}
else
{
var1C = var1C + arr3[var6];
var6 = var6 + 1;
}
}
varA = var6;
}
var1C = 0;
for (varA=1; varA<=f48; varA++)
var1C = var1C + (arr3[varA] - f20) * (arr2[varA] - f20);
var18 = f18 * var1C;
}
else
var18 = 0;
value = var18;
if (value == 0) value = 0.00001;
ExtMapBuffer1[i]=value;
//---- 3color------------------------------------------------------------------------------------+
oldvalue = ExtMapBuffer1[i+1];
minuse = value - oldvalue;
if(minuse>0.0){ind_buffer1[i]= value; ind_buffer2[i]=0.0; ind_buffer3[i]=0.0;}
else {if(minuse<0.0){ind_buffer1[i]=0.0; ind_buffer2[i]= value; ind_buffer3[i]=0.0;}
else {ind_buffer1[i]=0.0; ind_buffer2[i]=0.0; ind_buffer3[i]= value;}}
//----------------------------------------------------------------------------------------------+
}
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments