FX_Sniper_s_Ergodic_CCI_Trigger_Alert

Download script
FX_Sniper_s_Ergodic_CCI_Trigger_Alert

Overview of the FX Sniper Ergodic CCI Logic

The FX Sniper tool is designed to analyze market momentum by processing price movements through multiple layers of mathematical smoothing. Instead of looking at raw price fluctuations—which can often be "noisy" and misleading—this script breaks down the data into specific components to identify trends and potential entry points for traders.

How the Logic Works

1. Movement Analysis The process begins by calculating the "Momentum" of the market. It looks at the difference between the current closing price and the previous closing price. This allows the tool to understand the speed and direction of price movement. The script also calculates the "Absolute Momentum," which measures the magnitude of these movements regardless of whether they are up or down, helping to isolate the strength of the volatility.

2. Multi-Layer Smoothing (The "Ergodic" Component) To filter out minor market fluctuations that might trigger false signals, the script applies several layers of Exponential Moving Averages (EMA).

  • It smooths the raw momentum data first.
  • It then applies a secondary smoothing layer to those results.
  • It repeats this same smoothing process for the "Absolute Momentum" data.

By layering these averages, the tool creates a stabilized representation of the market's behavior, making it easier to see the underlying trend without being distracted by momentary price spikes.

3. The CCI Calculation The script combines these smoothed datasets into a specialized indicator called the "Ergodic CCI." This is achieved by comparing the smoothed momentum of the market against its smoothed absolute magnitude. Essentially, it looks at the relationship between how far the price is moving and how much energy is behind that move.

4. The Trigger Mechanism To provide clear actionable data, the script creates a final "Trigger Line." This is a third layer of smoothing applied specifically to the Ergodic CCI. This produces two distinct lines on your chart:

  • Ergodic CCI: Represents the primary momentum calculation.
  • Trigger Line: Represents the smoothed signal line.

Trading Signals and Alerts

The logic determines trading opportunities based on the interaction between these two lines:

  • Buy Signal (LONG): Triggered when the Trigger Line falls below the Ergodic CCI. This suggests a shift in momentum that may favor an upward move.
  • Sell Signal (SHORT): Triggered when the Trigger Line rises above the Ergodic CCI. This suggests a shift in momentum that may favor a downward move.
  • Neutral: When the lines are equal, the market is considered to be in a state of balance with no clear directional bias.

Notifications

The script includes built-in functionality to keep the user informed in real-time. Depending on your settings, it can generate:

  • Audible Alerts: A sound notification directly within the trading platform.
  • Email Notifications: An automated email sent to your registered address providing the specific Buy or Sell signal, current prices (Bid/Ask), date, time, and the specific currency pair being analyzed.
Price Data Components
Series array that contains open time of each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screenIt sends emails
6 Views
0 Downloads
0 Favorites
FX_Sniper_s_Ergodic_CCI_Trigger_Alert
//+------------------------------------------------------------------+
//|                                       Louw Coetzer aka FX Sniper |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2004, Fx Sniper."
#property  link      "http://www.dunno.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Turquoise
#property  indicator_color2  Red

extern bool SoundON=true;
extern bool EmailON=false;

// Ergo Variables

extern int pq =2;
extern int pr = 10;
extern int ps = 5;
extern int trigger =3;

//---- indicator buffers

string signal;
double mtm[];
double absmtm[];
double ErgoCCI[];
double MainCCI[];
double var1[];
double var2[];
double var2a[];
double var2b[];
//double valor1[];
//double valor2[];
//double extvar[];
//double cciSignal[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(8);
   
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,Turquoise);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2,Red);
   
   SetIndexBuffer(0,ErgoCCI);
   SetIndexLabel(0,"Ergodic CCI");
   SetIndexBuffer(1,MainCCI);
   SetIndexLabel(1,"Trigger Line");
   SetIndexBuffer(2,mtm);
   SetIndexBuffer(3,var1);
   SetIndexBuffer(4,var2);
   SetIndexBuffer(5,absmtm);
   SetIndexBuffer(6,var2a);
   SetIndexBuffer(7,var2b);
      
//---- name for DataWindow and indicator subwindow label

   
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Calculations                                    |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int i;
   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
   
//---- done

   for(i=0; i <= Bars; i++) 
   {
   mtm[i]= Close[i]- Close[i +1];
   }
   for(i=0; i <= Bars-1; i++) 
   { 
    absmtm[i] =  MathAbs(mtm[i]);
   }
   for(i=0; i <= Bars-1; i++) 
   {   
    var1[i]= iMAOnArray(mtm,0,pq,0,MODE_EMA,i);
   }
   for(i=0; i <= Bars-1; i++) 
   {
   var2[i]= iMAOnArray(var1,Bars,pr,0,MODE_EMA,i);
   }
   for(i=0; i <= Bars-1; i++) 
   {
   var2a[i]= iMAOnArray(absmtm,0,pq,0,MODE_EMA,i);
   }
   for(i=0; i <= Bars-1; i++) 
   {
   var2b[i]= iMAOnArray(var2a,0,pr,0,MODE_EMA,i);
   }
    for(i=0; i <= Bars-1; i++) 
   {   
   ErgoCCI[i] = (500 * iMAOnArray(var2,0,ps,0,MODE_EMA,i))/(iMAOnArray(var2b,0,ps,0,MODE_EMA,i)); //var2a[i]/var2b[i];
   
   }
   for(i=0; i<=Bars; i++)
   {
     MainCCI[i]=iMAOnArray(ErgoCCI,0,trigger,0,MODE_EMA,i);
   }
   
   for(i=0; i<=Bars; i++)
   {
      if(MainCCI[i] > ErgoCCI[i])
      {
      signal = "SHORT";
      if (SoundON) Alert("SELL signal at Ask=",Ask,"\n Bid=",Bid,"\n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
      if (EmailON) SendMail("SELL signal alert","SELL signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
      }
      if (MainCCI[i] < ErgoCCI[i])
      {
      signal = "LONG";
      if (SoundON) Alert("BUY signal at Ask=",Ask,"\n Bid=",Bid,"\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
      if (EmailON) SendMail("BUY signal alert","BUY signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
      }
      if (MainCCI[i] == ErgoCCI[i])
      {
      signal = "NEUTRAL";
      }
 
    IndicatorShortName("FX Sniper's Ergodic CCI & Trigger: "+signal);
   return(0); }
  }
//+------------------------------------------------------------------+

Comments