This script, known as the FX Sniper's Ergodic CCI & Trigger, is a specialized technical analysis tool designed to help traders identify specific momentum shifts and trend reversals in financial markets. Unlike standard indicators that might simply track price averages, this logic uses a multi-layered mathematical approach to filter out market "noise" and pinpoint high-probability entry points.
Core Logic and Mechanics
The functionality of the script can be broken down into three primary stages:
1. Data Smoothing and Momentum Calculation The script begins by analyzing the price movements between consecutive candles. It doesn't just look at where the price is, but rather how much it moved from one point to another. It calculates both the raw movement and the absolute value of that movement. This allows the tool to distinguish between the direction of a trend and the sheer intensity (volatility) of the price action.
2. The Ergodic Processing Layer The "Ergodic" part of the name refers to the advanced mathematical filtering applied to these movements. The script passes the raw data through several layers of calculation (weighted averages). By using specific "Alpha" factors—which are determined by user-defined settings—the script blends the price momentum with historical volatility.
- The first layer focuses on the general trend.
- The second layer analyzes the magnitude of the moves.
- The final layers combine these inputs to create the Ergodic CCI (Commodity Channel Index). This results in a smoothed, more "intelligent" representation of market cycles than a standard CCI indicator.
3. The Trigger Mechanism To prevent traders from entering a position too early or during a choppy market, the script introduces a "Trigger Line." Instead of reacting instantly to every flicker of the Ergodic CCI, the script calculates a secondary moving average of the Ergodic line itself.
This creates a relationship between two lines:
- The Ergodic CCI: Represents the current momentum.
- The Trigger Line: Represents the smoothed trend signal.
How it Works in Practice (Signals)
The logic is designed to identify "crosses." When these two lines intersect, it suggests that the momentum has reached a significant turning point:
- Long Signal: Occurs when the Trigger Line moves from below the Ergodic CCI to above it (or vice versa depending on specific orientation), indicating a potential shift into upward momentum.
- Short Signal: Occurs when the lines cross in the opposite direction, suggesting a downward shift.
Integrated Alert System
To ensure that traders do not have to watch the screen constantly, the script includes an automated notification system. When the logic detects these specific crosses between the Ergodic CCI and the Trigger Line, it can trigger multiple types of notifications simultaneously:
- Pop-up Alerts: Visual notifications on your trading platform.
- Email Notifications: Sent directly to your registered email address.
- Audio Alerts: Sound files played to grab your attention immediately.
By combining heavy mathematical filtering with a dual-line trigger system, this script aims to provide a clearer view of market dynamics while minimizing the frequency of "false" signals that often plague simpler indicators.
//+------------------------------------------------------------------+
//| Louw Coetzer aka FX Sniper |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//| FX Sniper's Ergodic CCI & Trigger
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, Fx Sniper."
#property link "http://www.dunno.net/"
//+------------------------------------------------------------------+
//| FX_Sniper's_Ergodic_CCI_&_Trigger_Alert_Fast by mladen |
//+------------------------------------------------------------------+
//2008fxtsd
#property copyright "mladen"
#property link "mladenfx@gmail.com"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 2
//
//
//
//
//
extern int pq = 2;
extern int pr = 10;
extern int ps = 5;
extern int trigger = 3;
extern bool alertsOn = false;
extern bool alertsMessage = true;
extern bool alertsSound = false;
extern bool alertsEmail = false;
double ErgoCCI[];
double MainCCI[];
double buffer[][8];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0,ErgoCCI); SetIndexLabel(0,"Ergodic CCI");
SetIndexBuffer(1,MainCCI); SetIndexLabel(1,"Trigger Line");
return(0);
}
//
//
//
//
//
#define mtm 0
#define absmtm 1
#define var1 2
#define var2 3
#define var2a 4
#define var2b 5
#define var2c 6
#define var2d 7
//
//
//
//
//
int start()
{
int i,r,limit,counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
if (ArrayRange(buffer,0) != Bars) ArrayResize(buffer,Bars);
//
//
//
//
//
double alphaPq = 2.0/(1.0+pq);
double alphaPr = 2.0/(1.0+pr);
double alphaPs = 2.0/(1.0+ps);
double alphaTrigger = 2.0/(1.0+trigger);
for(i=limit,r=Bars-limit-1; i >=0; i--,r++)
{
buffer[r][mtm] = Close[i]-Close[i+1];
buffer[r][absmtm] = MathAbs(buffer[r][mtm]);
buffer[r][var1] = buffer[r-1][var1] + alphaPq*(buffer[r][mtm] -buffer[r-1][var1]);
buffer[r][var2] = buffer[r-1][var2] + alphaPr*(buffer[r][var1] -buffer[r-1][var2]);
buffer[r][var2a] = buffer[r-1][var2a] + alphaPq*(buffer[r][absmtm]-buffer[r-1][var2a]);
buffer[r][var2b] = buffer[r-1][var2b] + alphaPr*(buffer[r][var2a] -buffer[r-1][var2b]);
buffer[r][var2c] = buffer[r-1][var2c] + alphaPs*(buffer[r][var2] -buffer[r-1][var2c]);
buffer[r][var2d] = buffer[r-1][var2d] + alphaPs*(buffer[r][var2b] -buffer[r-1][var2d]);
if (buffer[r][var2d]!=0)
ErgoCCI[i] = (500*buffer[r][var2c]/buffer[r][var2d]);
else ErgoCCI[i] = 0;
MainCCI[i] = MainCCI[i+1] + alphaTrigger*(ErgoCCI[i]-MainCCI[i+1]);
}
if (alertsOn)
{
if(MainCCI[1] <= ErgoCCI[1] && MainCCI[0] > ErgoCCI[0]) doAlert("short");
if(MainCCI[1] >= ErgoCCI[1] && MainCCI[0] < ErgoCCI[0]) doAlert("long");
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
void doAlert(string doWhat)
{
static string previousAlert="nothing";
static datetime previousTime;
string message;
if (previousAlert != doWhat || previousTime != Time[0]) {
previousAlert = doWhat;
previousTime = Time[0];
//
//
//
//
//
message = StringConcatenate(Symbol()," M",Period()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," ergodic ",doWhat);
if (alertsMessage) Alert(message);
if (alertsEmail) SendMail(StringConcatenate(Symbol()," ergodic crossing"),message);
if (alertsSound) PlaySound("alert2.wav");
}
}
Comments