This technical indicator is designed to help traders identify potential momentum shifts in the market by analyzing the relationship between two specific moving averages derived from a core price oscillator.
Instead of looking at raw price action alone, the tool focuses on the following logical layers:
Core Data Foundation
The script begins by pulling data from a standard "Commodity Channel Index" (CCI). This serves as the baseline for all subsequent calculations. By using the CCI, the indicator captures the market's momentum and overbought/oversold conditions relative to a specific price range.
Dual Moving Average Analysis
The logic then applies two different types of moving averages to that CCI data simultaneously:
- Simple Moving Average (SMA): A standard average used to smooth out price fluctuations.
- Exponential Moving Average (EMA): A weighted average that places more emphasis on the most recent price data.
By calculating these two different averages over the same period, the script creates a "signal" based on how these two mathematical models interact with each other.
Signal Generation Logic
The primary objective of the script is to detect a "crossover." It monitors the distance between the SMA and the EMA:
- Upward Signal: The script looks for a specific moment where the relationship between these two averages flips from negative to positive (or vice versa). When the logic detects this transition and the data points indicate an upward trend, it identifies a "Buy" or "Up" signal.
- Downward Signal: Conversely, if the relationship flips in the opposite direction, indicating a shift toward a downward trend, it identifies a "Sell" or "Down" signal.
Visual and Audible Alerts
To make this information actionable for the user, the script provides three layers of notification:
- Visual Plotting: It draws continuous lines representing the two moving averages so you can see the trends in real-time.
- On-Chart Markers: When a crossover occurs, the script places specific arrow icons on the chart to highlight the exact point where the signal was triggered.
- Pop-up Alerts: If enabled, the script will trigger a proactive desktop alert window whenever a new signal appears, providing the current price and timeframe to ensure the trader doesn't miss the entry point.
In summary, this tool filters out market noise by comparing two different methods of averaging momentum, alerting the user only when those two mathematical models agree that a trend change is occurring.
//ShadowWz 03-11-2006, http://www.forex-tsd.com/13195-post2.html
//http://www.forex-tsd.com/metatrader-4/1270-signal-generator-show-mas-crossing-when-overlayed-rsi.html#post13195
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Green
#property indicator_color2 Blue
#property indicator_color3 Maroon
#property indicator_color4 DarkTurquoise
#property indicator_color5 DarkViolet
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_level1 100
#property indicator_level2 -100
//#property indicator_level3 30
#property indicator_levelcolor DarkBlue
#property indicator_levelstyle STYLE_DOT
extern int CCI = 14;
extern int Ma = 8;
extern bool alertOn = true;
double alertBar;
double RsiBuf[];
double MaP[];
double MaF[];
double Up[];
double Dn[];
void init() {
SetIndexStyle (0, DRAW_LINE);
SetIndexStyle (1, DRAW_LINE);
SetIndexStyle (2, DRAW_LINE);
SetIndexStyle (3, DRAW_ARROW);
SetIndexStyle (4, DRAW_ARROW);
SetIndexBuffer(0, RsiBuf);
SetIndexBuffer(1, MaP);
SetIndexBuffer(2, MaF);
SetIndexBuffer(3, Up);
SetIndexBuffer(4, Dn);
SetIndexEmptyValue(3,EMPTY_VALUE);
SetIndexEmptyValue(4,EMPTY_VALUE);
SetIndexArrow(3,108);//233 234
SetIndexArrow(4,108);
}
void deinit() {
}
int start()
{
int shift,limit,counted_bars=IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars > 0) counted_bars--;
limit = Bars-counted_bars;
for(shift=limit;shift>=0;shift--)
{
RsiBuf[shift] = iCCI(NULL,0,CCI,PRICE_CLOSE,shift);
}
for(shift=limit;shift>=0;shift--)
{
Dn[shift] = EMPTY_VALUE; Up[shift] = EMPTY_VALUE;
// First Indicator Data
MaF[shift] = iMAOnArray(RsiBuf,0,Ma,0,MODE_SMA,shift);
// Previous Indicator Data//secondMA
MaP[shift] = iMAOnArray(RsiBuf,0,Ma,0,MODE_EMA,shift);
if((MaF[shift]-MaP[shift])*(MaF[shift+1]-MaP[shift+1])<0)
{
if(MaF[shift]-MaP[shift]<0)
{
Up[shift] = MaP[shift]-15; Dn[shift] = EMPTY_VALUE;
if(alertOn && Up[0] != EMPTY_VALUE && Bars>alertBar){
Alert("SGMAcci Up signal on ", Symbol()," M", Period()," at ",Close[0]); alertBar = Bars;}//Bid tester Close[0]
}
else
{
Dn[shift] = MaF[shift]+10; Up[shift] = EMPTY_VALUE;
if( alertOn && Dn[0] != EMPTY_VALUE && Bars>alertBar) {
Alert("SGMAcci Down Signal on ",Symbol()," M", Period()," at ",Close[0]); alertBar = Bars;}//Bid
}
}
}
return(0);
}
Comments