SmCCI-RS
Download scriptThis tool is designed as a technical analysis indicator for the MetaTrader platform. Its primary purpose is to identify potential entry points in the market by analyzing price momentum and identifying "overextended" conditions.
Core Logic Overview
The script functions by processing price data through several mathematical layers to smooth out market noise and highlight significant trends. Instead of looking at raw price movements, it calculates a specific type of momentum (the CCI) and then passes that data through a multi-stage smoothing process.
How the Analysis Works
- Momentum Calculation: The script first measures the current velocity of the price relative to its average move over a user-defined period.
- Multi-Stage Smoothing: To prevent "fake signals" caused by rapid, insignificant price flickers, the data is filtered through six successive layers of weighted averages. This creates a much smoother curve that represents the underlying trend rather than the immediate volatility.
- Trend Detection (T3): The script uses a specific mathematical formula (known as T3) to calculate the trajectory of these smoothed values. It looks for when this trajectory moves significantly above or below certain thresholds.
Signal Generation
The indicator monitors the relationship between the current trend and two pre-defined boundaries (Upper and Lower limits). It generates signals based on the following behaviors:
- Trend Transitions: When the calculated momentum shifts from positive to negative (or vice versa) and crosses a specific threshold, the script identifies a potential change in market direction.
- Exhaustion Signals: The logic includes a specific "reversal" check. If the price hits an extreme high or low but fails to sustain that momentum (indicating the move might be "exhausted"), the script can trigger a notification to alert the user of a potential reversal.
Notifications and Alerts
The script is designed to be proactive rather than passive. Depending on the settings chosen by the user, it can provide feedback in three ways:
- Visual Alerts: On-screen pop-up messages identifying "BUY" or "SELL" conditions.
- Audio Alerts: Playing a specific sound file when a condition is met.
- Log Tracking: Recording the data internally for analysis.
In summary, this script acts as a sophisticated filter that takes raw market price movement, cleans it of "noise" through multiple layers of smoothing, and alerts the user when the momentum suggests a significant trend shift or a price exhaustion point.
//+------------------------------------------------------------------+
//| SmCCI.mq4 |
//| MetaQuotes |
//| http://forum.alpari-idc.ru/viewtopic.php?t=48186 |
//+------------------------------------------------------------------+
#property copyright "MetaQuotes"
#property link "http://forum.alpari-idc.ru/viewtopic.php?t=48186"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Gold
//---- input parameters
extern double t3_period=8.0;
extern int per=14;
extern double ppor=100.0;
extern double mpor=-100.0;
extern double b=0.7;
extern int MessageType=0;
extern string MessageSound="Alert2.wav";
/*
Ïàðàìåòðû:
- MessageType - òèï ñèãíàëà
0 - Íåò ñèãíàëà (ïî óìîë÷àíèþ)
1 - Îêíî ñîîáùåíèÿ
2 - Çâóê
- MessageSound - íàçâàíèå ôàéëà äëÿ çâóêà
*/
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double e1Buffer[];
double e2Buffer[];
double e3Buffer[];
double e4Buffer[];
double e5Buffer[];
double e6Buffer[];
double /*e1,e2,e3,e4,e5,e6,*/c1,c2,c3,c4,n,w1,w2,b2,b3;
double dpo,t3,cci,trig, message, extrem_p, extrem_m;
//+------------------------------------------------------------------+
//| User functions |
//+------------------------------------------------------------------+
string PeroidToStr(int period)
{
string ret;
switch(period)
{
case 1:
ret="M1";
break;
case 5:
ret="M5";
break;
case 15:
ret="M15";
break;
case 30:
ret="M30";
break;
case 60:
ret="H1";
break;
case 240:
ret="H4";
break;
case 1440:
ret="D1";
break;
case 10080:
ret="W1";
break;
case 43200:
ret="MN1";
break;
}
return(ret);
}
//------------------------------------------------------------------------------------------
void AlertExt(int MessageType, string sOrderType)
{
switch(MessageType)
{
case 1:
Alert("SmCCI: ", sOrderType," ", Symbol(),", ",PeroidToStr(Period()));
break;
case 2:
PlaySound(MessageSound);
break;
}
return(1);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(8);
SetIndexStyle(0,DRAW_LINE, STYLE_DOT);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(2,e1Buffer);
SetIndexBuffer(3,e2Buffer);
SetIndexBuffer(4,e3Buffer);
SetIndexBuffer(5,e4Buffer);
SetIndexBuffer(6,e5Buffer);
SetIndexBuffer(7,e6Buffer);
SetIndexEmptyValue(0,0.0);
SetIndexEmptyValue(1,0.0);
SetIndexEmptyValue(2,0.0);
SetIndexEmptyValue(3,0.0);
SetIndexEmptyValue(4,0.0);
SetIndexEmptyValue(5,0.0);
SetIndexEmptyValue(6,0.0);
SetIndexEmptyValue(7,0.0);
b2=b*b;
b3=b2*b;
c1=-b3;
c2=(3*(b2+b3));
c3=-3*(2*b2+b+b3);
c4=(1+3*b+b3+3*b2);
n=t3_period;
if(n<1) n=1;
n = 1 + 0.5*(n-1);
w1 = 2 / (n + 1);
w2 = 1 - w1;
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int shift,limit;
if (counted_bars==0) limit=Bars-per;
if (counted_bars>=0) limit=Bars-counted_bars;
limit--;
for (shift=limit;shift>=0;shift--)
{//Begin
cci=iCCI(NULL,0,per,PRICE_CLOSE,shift);
dpo=cci;
e1Buffer[shift] = w1*dpo + w2*e1Buffer[shift+1];
e2Buffer[shift] = w1*e1Buffer[shift] + w2*e2Buffer[shift+1];
e3Buffer[shift] = w1*e2Buffer[shift] + w2*e3Buffer[shift+1];
e4Buffer[shift] = w1*e3Buffer[shift] + w2*e4Buffer[shift+1];
e5Buffer[shift] = w1*e4Buffer[shift] + w2*e5Buffer[shift+1];
e6Buffer[shift] = w1*e5Buffer[shift] + w2*e6Buffer[shift+1];
t3 = c1*e6Buffer[shift] + c2*e5Buffer[shift] + c3*e4Buffer[shift] + c4*e3Buffer[shift];
if (t3==0) t3=0.0001;
if (t3>0) trig=ppor;
if (t3<0) trig=mpor;
/*
if(shift==0) // âûâîäèì â ëîã òîëüêî íà íóëåâîì áàðå
{
Print("Bars=",Bars," e1=",e1," e2=",e2," e3=",e3," e4=",e4,
" e5=",e5," e6=",e6," t3=",t3);
}
*/
ExtMapBuffer1[shift]=trig;
ExtMapBuffer2[shift]=t3;
}
//---------------------------- Messages ------------------------------------
if (trig!=message)
{
string OType;
if (trig>0) {OType="BUY";}
if (trig<0) {OType="SELL";}
AlertExt(MessageType, OType);
message=trig;
extrem_p=1;
extrem_m=-1;
}
if (trig<MathRound(t3) && ppor==trig) {extrem_p=0;}
if (trig>=MathRound(t3) && ppor==trig && extrem_p==0)
{
AlertExt(MessageType, "*SELL*");
extrem_p=1;
}
if (trig>MathRound(t3) && mpor==trig) {extrem_m=0;}
if (trig<=MathRound(t3) && mpor==trig && extrem_m==0)
{
AlertExt(MessageType, "*BUY*");
extrem_m=-1;
}
//--------------------------------------------------------------------------
return(0);
}
//+------------------------------------------------------------------+
Comments