Trix_osma4c_alert_mtf
Download scriptTechnical Logic Overview: FX_Sniper's Ergodic CCI & Trigger Alert Fast
This script is a sophisticated technical analysis tool designed for the MetaTrader platform to help traders identify momentum shifts and potential price reversals. It functions by layering multiple moving averages and mathematical filters to smooth out market "noise," allowing for clearer visualization of trend directions.
Core Calculation Logic
The indicator operates through a multi-stage processing sequence:
- Data Smoothing: The script begins by taking raw price data and applying a series of Moving Averages (MAs). It doesn't just calculate one average; it calculates an average of an average, which is then processed again. This "nested" calculation is designed to filter out minor price fluctuations while retaining the integrity of the primary trend.
- Momentum Generation: Once the smoothed data is established, the script calculates the rate of change between these averages. By measuring the difference between consecutive values and multiplying them, it generates a momentum figure (similar to a momentum oscillator).
- Ergodic Filtering: The "Ergodic" component refers to the additional smoothing applied to the final momentum figures. The script applies specific periods to these results to create two primary lines:
- Main CCI: The primary momentum signal.
- ErgoCCI: A secondary, smoother signal used as a baseline for comparison.
- OSMA Integration (Optional): The script includes an optional "Oscillator" mode. When enabled, it calculates the distance between the Main CCI and the ErgoCCI, multiplying that gap by a user-defined factor. This helps highlight the strength of the trend—the wider the gap, the stronger the momentum.
Visual Representation
The indicator provides several visual elements on the chart:
- Histograms: These display the smoothed price movements and momentum values, helping you see the "weight" of the current market movement.
- Signal Lines: The primary lines allow you to see where the current momentum stands in relation to its historical average.
Multi-Timeframe Analysis
One of the advanced features of this script is its ability to perform Multi-Timeframe (MTF) analysis. This means that even if you are looking at a 1-minute chart, the script can be configured to pull and display data from higher timeframes (like 15 minutes, 1 hour, or Daily). This provides traders with a "big picture" view without needing to constantly switch between different charts.
Alert System
The script is equipped with an automated notification system. It monitors the relationship between the Main CCI and the ErgoCCI. When these two lines cross each other, it identifies a potential shift in momentum:
- Long Signal: Triggered when the Main CCI crosses from below to above the ErgoCCI.
- Short Signal: Triggered when the Main CCI crosses from above to below the ErgoCCI.
When these crossings occur, the script can provide real-time feedback via three different methods (depending on user settings): a pop-up alert on the screen, an audible sound, or a notification sent directly to your email.
//+------------------------------------------------------------------+
//| FX_Sniper's_Ergodic_CCI_&_Trigger_Alert_Fast by mladen |
//+------------------------------------------------------------------+
//2008fxtsd
//mod 2009fxtsd Trix_4c_alert_mtf.mq4
#property copyright "mladen"
#property link "mladenfx@gmail.com"
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_color4 Green
#property indicator_color5 DarkOrange
#property indicator_color6 DodgerBlue
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 1
#property indicator_width6 1
//
//
//
//
//
extern int Trixperiod = 5;
extern int sigMAperiod = 7;
extern int priorsmzper = 3;
extern int smzperiod = 3;
extern int MAmethod = 1;
extern int price = 5;
extern int TimeFrame = 0;
extern bool alertsOn = false;
extern bool alertsSound = true;
extern bool alertsMessage = true;
extern bool alertsEmail = false;
extern bool osma = true;
extern double osmaMult = 2;
extern string note_timeframes = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";
extern string ma_method_price = "SMA0 EMA1 SMMA2 LWMA3||0O,1C 2H3L,4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";
string IndicatorFileName;
double ErgoCCI[];
double MainCCI[];
double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];
double buffer5[];
double buffer6[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(8);
SetIndexBuffer(0,buffer1);
SetIndexBuffer(1,buffer4);
SetIndexBuffer(2,buffer3);
SetIndexBuffer(3,buffer2);
SetIndexBuffer(4,MainCCI); SetIndexLabel(4,"Trix");
SetIndexBuffer(5,ErgoCCI); SetIndexLabel(5,"TrixSigMA");
SetIndexBuffer(6,buffer5);
SetIndexBuffer(7,buffer6);
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexStyle(3,DRAW_HISTOGRAM);
TimeFrame=MathMax(TimeFrame, Period());
string shortname = "Trix ("+Trixperiod+","+sigMAperiod+"; "+priorsmzper+","+smzperiod+"; "+MAmethod+","+price+") M"+TimeFrame+" ";
IndicatorShortName (shortname);
IndicatorFileName = WindowExpertName();
return(0);
}
//
//
//
//
//
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 (TimeFrame != Period())
{
limit = MathMax(limit,TimeFrame/Period());
for(i=limit; i>=0; i--)
{
int y = iBarShift(NULL,TimeFrame,Time[i]);
buffer1[i] = iCustom(NULL,TimeFrame,IndicatorFileName,Trixperiod,sigMAperiod,priorsmzper,smzperiod,MAmethod,price,0,alertsOn,alertsSound,alertsMessage, alertsEmail,osma,osmaMult,0,y);
buffer4[i] = iCustom(NULL,TimeFrame,IndicatorFileName,Trixperiod,sigMAperiod,priorsmzper,smzperiod,MAmethod,price,0,alertsOn,alertsSound,alertsMessage, alertsEmail,osma,osmaMult,1,y);
buffer3[i] = iCustom(NULL,TimeFrame,IndicatorFileName,Trixperiod,sigMAperiod,priorsmzper,smzperiod,MAmethod,price,0,alertsOn,alertsSound,alertsMessage, alertsEmail,osma,osmaMult,2,y);
buffer2[i] = iCustom(NULL,TimeFrame,IndicatorFileName,Trixperiod,sigMAperiod,priorsmzper,smzperiod,MAmethod,price,0,alertsOn,alertsSound,alertsMessage, alertsEmail,osma,osmaMult,3,y);
MainCCI[i] = iCustom(NULL,TimeFrame,IndicatorFileName,Trixperiod,sigMAperiod,priorsmzper,smzperiod,MAmethod,price,0,alertsOn,alertsSound,alertsMessage, alertsEmail,osma,osmaMult,4,y);
ErgoCCI[i] = iCustom(NULL,TimeFrame,IndicatorFileName,Trixperiod,sigMAperiod,priorsmzper,smzperiod,MAmethod,price,0,alertsOn,alertsSound,alertsMessage, alertsEmail,osma,osmaMult,5,y);
}
return(0);
}
//
//
//
//
//
buffer1[i]=EMPTY_VALUE; buffer2[i]=EMPTY_VALUE; buffer3[i]=EMPTY_VALUE;
buffer4[i]=EMPTY_VALUE; buffer5[i]=EMPTY_VALUE; buffer6[i]=EMPTY_VALUE;
for(i=limit;i>=0;i--) buffer1[i]= iMA(NULL,0,priorsmzper,0,MAmethod,price,i);
for(i=limit;i>=0;i--) buffer2[i]= iMAOnArray(buffer1,0,Trixperiod,0,MAmethod,i);
for(i=limit;i>=0;i--) buffer3[i]= iMAOnArray(buffer2,0,Trixperiod,0,MAmethod,i);
for(i=limit;i>=0;i--) buffer5[i]= iMAOnArray(buffer3,0,Trixperiod,0,MAmethod,i);
for(i=limit;i>=0;i--) buffer4[i]= (buffer5[i]-buffer5[i+1])*1000;
for(i=limit;i>=0;i--) MainCCI[i]= iMAOnArray(buffer4,0,smzperiod,0,MAmethod,i);
for(i=limit;i>=0;i--) ErgoCCI[i]= iMAOnArray(MainCCI,0,sigMAperiod,0,MAmethod,i);
for(i=limit;i>=0;i--) if (!osma)
buffer6[i]=ErgoCCI[i];
else
buffer6[i]=(iMAOnArray(MainCCI,0,smzperiod,0,MAmethod,i)-
iMAOnArray(ErgoCCI,0,smzperiod,0,MAmethod,i))*osmaMult;
//
//
//
for(i=limit;i>=0;i--)
{
buffer1[i]=EMPTY_VALUE; buffer2[i]=EMPTY_VALUE;
buffer3[i]=EMPTY_VALUE; buffer4[i]=EMPTY_VALUE;
if (buffer6[i]>buffer6[i+1])
{
if (buffer6[i]>0) buffer2[i]=buffer6[i];
else buffer3[i]=buffer6[i];
}
else
if (buffer6[i]>0) buffer4[i]=buffer6[i];
else buffer1[i]=buffer6[i];
//
//
//
if (alertsOn)
{
if(MainCCI[i+1] < ErgoCCI[i+1] && MainCCI[i] > ErgoCCI[i]) doAlert("goes long");
if(MainCCI[i+1] > ErgoCCI[i+1] && MainCCI[i] < ErgoCCI[i]) doAlert("goes short");
}
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
void doAlert(string doesWhat)
{
static string previousAlert="nothing";
static datetime previousTime;
string message;
if (previousAlert != doesWhat || previousTime != Time[0]) {
previousAlert = doesWhat;
previousTime = Time[0];
//
//
//
//
//
message = StringConcatenate(Symbol()," M",Period()," ",TimeToStr(TimeLocal(),TIME_SECONDS)," trix ",doesWhat);
if (alertsSound) PlaySound("ok.wav");//alert2
if (alertsMessage) Alert(message);
if (alertsEmail) SendMail(StringConcatenate(Symbol()," trix crossing "),message);
}
}
Comments