iCCI_Revercy v1.4
Download scriptThis script is a specialized technical analysis tool designed for the MetaTrader 4 platform. It aims to calculate and project potential price levels based on the Commodity Channel Index (CCI), a popular momentum-based oscillator used by traders to identify overbought or oversold conditions.
Core Functionality
The primary logic of this tool revolves around "reversing" the standard CCI calculation. While a typical CCI indicator tells you what the current price is doing relative to an average, this script performs a mathematical inverse: it takes a specific target CCI value (which you define) and attempts to calculate the corresponding price level required to reach that exact momentum state.
How It Works
The logic can be broken down into three main stages:
1. Data Gathering and Averaging The script looks at a specific window of recent market data (defined by the user as the "Period"). It calculates the average price over this timeframe using a simple moving average approach, specifically focusing on the "Typical Price" (a calculation based on the High, Low, and Close of each candle).
2. Deviation Analysis It measures how much the current market price deviates from that moving average. By calculating the absolute difference between the current price and the average across the entire period, it establishes a baseline of current market volatility and momentum.
3. Mathematical Projection (The "Revercy" Logic) This is the unique part of the script. Based on whether you are looking for an upward or downward movement, the tool uses a complex algebraic formula to solve for "Price."
- It takes your desired CCI level as a fixed constant.
- It incorporates the current price highs and lows.
- It factors in the sum of historical prices and deviations within the period.
- It then solves the equation to project a specific price coordinate.
Practical Application
Instead of simply looking at a moving line to see if the market is "too high," this tool allows you to see exactly where the price needs to be to hit a specific momentum target. It provides two distinct data points (labeled on the chart as "CloseUP" and "CloseDN") which represent these calculated price levels.
Essentially, it transforms a momentum oscillator into a price target generator, helping traders identify potential zones of interest where the market's momentum might shift based on specific mathematical thresholds.
//+------------------------------------------------------------------+
//| iCCI_Revercy.mq4 |
//| EvgeTrofi |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © Evgeniy Trofimov, 2009"
#property link "http://vkontakte.ru/id5374887/"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red
extern int CCIPeriod = 14;
extern double FindCCI = 100.0;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
IndicatorBuffers(2);
IndicatorDigits(Digits);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexDrawBegin(0,CCIPeriod);
SetIndexLabel(0, "CloseUP");
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexDrawBegin(1,CCIPeriod);
SetIndexLabel(1, "CloseDN");
IndicatorShortName("CCI_Revercy("+CCIPeriod+", "+FindCCI+")");
return(0);
}//init()
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
int BeginBar;
int counted_bars=IndicatorCounted(); // Ðàíåå âû÷èñëåííûå áàðû
if(counted_bars<0) return(-1); //---- îáõîäèì âîçìîæíûå îøèáêè
//---- íîâûå áàðû íå ïîÿâèëèñü è ïîýòîìó íè÷åãî ðèñîâàòü íå íóæíî
BeginBar=Bars-counted_bars-1;
//---- îñíîâíûå ïåðåìåííûå
double Price, CCILast, CCI;
for(int t=BeginBar; t>=0; t--) {
ExtMapBuffer1[t]=PriceCCI(FindCCI, t, 0);
ExtMapBuffer2[t]=PriceCCI(FindCCI, t, 1);
/*
CCILast=iCCI(NULL,0,CCIPeriod,PRICE_TYPICAL,t+2);
CCI=iCCI(NULL,0,CCIPeriod,PRICE_TYPICAL,t+1);
if((CCILast>0 && CCI<0) ||
(CCILast<0 && CCI>0)) {
ExtMapBuffer1[t+2]=EMPTY_VALUE;
}
*/
}//Next t
return(0);
} //start()
//+------------------------------------------------------------------+
double PriceCCI(double LevelCCI, int CurrentCandle=0, int index=0) {
//Âû÷èñëÿåì òåêóùèé CCI
double MovBuffer;
double Price, SummPrice, Abs, SummAbs;
double K = 0.015;
int j;
for(int i=CCIPeriod-1; i>=0; i--) {
j=i+CurrentCandle;
Price = (High[j]+Low[j]+Close[j])/3;
MovBuffer=iMA(NULL,0,CCIPeriod,0,MODE_SMA,PRICE_TYPICAL,CurrentCandle);
Abs = MathAbs(Price-MovBuffer);
if(i>0) {
SummPrice += Price;
SummAbs += Abs;
}
}//Next i
double CCI = (Price-MovBuffer)/((SummAbs+Abs)*K/CCIPeriod);
Comment("CCI("+CCIPeriod+") = "+DoubleToStr(CCI,4)+"\nFindCCI = "+DoubleToStr(LevelCCI,1));
// çàâèñèìîñòè îò çíàêà CCI äëÿ ðàñ÷¸òà íåîáõîäèìîé öåíû èñïîëüçóåòñÿ ñîîòâåòñòâóþùàÿ ôîðìóëà
double H = High[CurrentCandle];
double L = Low[CurrentCandle];
i = CCIPeriod;
if(index==0) {
CCI=LevelCCI;
Price = -(H*i-L*i*i-H*i*i+L*i-CCI*H*K-CCI*L*K+3*SummPrice*i-
CCI*3*K*SummPrice+CCI*H*K*i+CCI*L*K*i+CCI*3*K*SummAbs*i)/
(i-i*i-CCI*K+CCI*K*i);
} else {
CCI=-LevelCCI;
Price = -(H*i-L*i*i-H*i*i+L*i+CCI*H*K+CCI*L*K+3*SummPrice*i+
CCI*3*K*SummPrice-CCI*H*K*i-CCI*L*K*i+CCI*3*K*SummAbs*i)/
(i-i*i+CCI*K-CCI*K*i);
}
return(Price);
}//PriceCCI()
//+------------------------------------------------------------------+
Comments