JMA_CCI_v1
Download scriptThis technical tool is designed to provide traders with a sophisticated visual representation of market momentum and price volatility. By blending two distinct mathematical concepts—the Jurik Moving Average (JMA) and the Commodity Channel Index (CCI)—the script creates a customized oscillator that helps identify whether an asset is overextended or trending in a specific direction.
How the Logic Works
The script functions through a multi-layered calculation process to filter out market "noise" and highlight significant price movements:
1. Establishing the Baseline (The JMA Layer) Instead of using a standard moving average, which can often lag behind current price action, this tool utilizes the Jurik Moving Average. The logic first calculates this baseline to determine the "true" average path of the price over a specific period. Because the JMA is designed to be highly responsive while remaining smooth, it provides a stable foundation for the rest of the calculations.
2. Measuring Price Deviation (The Variance Layer) Once the moving average is established, the script looks at how much the current price fluctuates around that average. It calculates the "Typical Price" (an average of the high, low, and closing prices) for each candle and measures the distance between those prices and the JMA baseline. This creates a measure of market volatility—essentially telling the system how much the price is "stretching" away from its norm.
3. Calculating Relative Position (The Relationship Layer) Next, the script determines the raw difference between the current price and the moving average. By isolating this specific gap, the tool can see exactly how far the market has moved in a positive or negative direction relative to its recent history.
4. Final Indicator Output (The Synthesis) The final step of the logic involves dividing the relative position by the volatility measure. This creates a normalized ratio.
- If the price is moving significantly further than usual, the indicator will show a higher intensity.
- If the price is moving within its normal expected range, the indicator remains more stable.
What this means for the User
By combining these elements, the script produces a single line on your chart that represents a "smoothed" momentum. It effectively tells you: "Compared to the recent average, how far is the price pushing right now, relative to how much it usually swings?"
This allows traders to see trends more clearly, identify potential exhaustion points where the price may be over-extended, and observe the strength of a move without being distracted by minor, insignificant price flickers.
//+------------------------------------------------------------------+
//| JMA_CCI.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, scorpion."
#property link "http://www.fxfisherman.com/"
//----
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 LightSeaGreen
//---- input parameters
extern int CCIPeriod=14;
extern int JMAPhrase=0;
//---- buffers
double CCIBuffer[];
double RelBuffer[];
double DevBuffer[];
double MovBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- 3 additional buffers are used for counting.
IndicatorBuffers(4);
SetIndexBuffer(1, RelBuffer);
SetIndexBuffer(2, DevBuffer);
SetIndexBuffer(3, MovBuffer);
//---- indicator lines
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,CCIBuffer);
//---- name for DataWindow and indicator subwindow label
short_name="JMA CCI("+CCIPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
SetIndexDrawBegin(0,CCIPeriod);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Commodity Channel Index |
//+------------------------------------------------------------------+
int start()
{
int i,k,counted_bars=IndicatorCounted();
double price,sum,mul;
if(Bars<=CCIPeriod) return(0);
//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=CCIPeriod;i++) CCIBuffer[Bars-i]=0.0;
for(i=1;i<=CCIPeriod;i++) DevBuffer[Bars-i]=0.0;
for(i=1;i<=CCIPeriod;i++) MovBuffer[Bars-i]=0.0;
}
//---- last counted bar will be recounted
int limit=Bars-counted_bars;
if(counted_bars>0) limit++;
//---- moving average
for(i=0; i<limit; i++)
MovBuffer[i]=iCustom(NULL,0,"JMA",CCIPeriod,0,i);
//MovBuffer[i]=iMA(NULL,0,CCIPeriod,0,MODE_SMA,PRICE_TYPICAL,i);
//---- standard deviations
i=Bars-CCIPeriod+1;
if(counted_bars>CCIPeriod-1) i=Bars-counted_bars-1;
mul=0.015/CCIPeriod;
while(i>=0)
{
sum=0.0;
k=i+CCIPeriod-1;
while(k>=i)
{
price=(High[k]+Low[k]+Close[k])/3;
sum+=MathAbs(price-MovBuffer[i]);
k--;
}
DevBuffer[i]=sum*mul;
i--;
}
i=Bars-CCIPeriod+1;
if(counted_bars>CCIPeriod-1) i=Bars-counted_bars-1;
while(i>=0)
{
price=(High[i]+Low[i]+Close[i])/3;
RelBuffer[i]=price-MovBuffer[i];
i--;
}
//---- cci counting
i=Bars-CCIPeriod+1;
if(counted_bars>CCIPeriod-1) i=Bars-counted_bars-1;
while(i>=0)
{
if(DevBuffer[i]==0.0) CCIBuffer[i]=0.0;
else CCIBuffer[i]=RelBuffer[i]/DevBuffer[i];
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments