SGMAR1_Alert
Download scriptThis script is a specialized technical analysis tool designed to help traders identify potential momentum shifts by combining two well-known market indicators: the Relative Strength Index (RSI) and Moving Averages. Instead of looking at price alone, this tool analyzes the "strength" of the trend and provides visual cues when specific mathematical conditions are met.
How the Logic Works
The tool operates through a multi-layered calculation process:
1. Measuring Market Momentum (RSI) First, the script calculates the RSI, which measures how fast and how far prices are moving. This provides a baseline for whether a market is currently "overbought," "oversold," or moving with steady momentum.
2. Smoothing the Data (Dual Moving Averages) Rather than looking at the raw RSI values—which can be jumpy and inconsistent—the script applies two different types of Moving Averages to that RSI data:
- A Simple Moving Average (SMA)
- An Exponential Moving Average (EMA)
By applying these to the RSI, the tool creates two distinct "trend lines" for momentum. Think of this as smoothing out the noise to see the clearer direction of the underlying sentiment.
3. Identifying Crossover Signals The core logic focuses on the relationship between these two smoothed trend lines. The script constantly monitors whether these lines are crossing each other. A crossover suggests that the momentum is shifting from one direction to another.
4. Generating Buy and Sell Signals To filter out "false" signals and ensure the movements are significant, the script looks for a specific change in direction between the current moment and the previous moment:
- Upward Signal: When the smoothed lines cross in a way that suggests upward momentum is taking over, the script places an upward-pointing arrow on your chart.
- Downward Signal: When the lines cross in a way that suggests downward momentum is gaining strength, the script places a downward-pointing arrow.
Automated Alerts
In addition to the visual arrows on the chart, the script includes a notification system. If the user enables alerts, the tool will trigger a pop-up notification on the trading platform whenever a new "Up" or "Down" signal is detected. This allows traders to stay informed of potential entry points in real-time without having to constantly watch the screen.
//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 70
#property indicator_level2 50
#property indicator_level3 30
#property indicator_levelcolor DarkBlue
#property indicator_levelstyle STYLE_DOT
extern int Rsi = 14;
extern int Ma = 8;
extern int cbars = 0;
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 = cbars;
if(limit==0) limit = Bars;
for(shift=limit-1; shift>=0; shift--) {
RsiBuf[shift] = iRSI(NULL,0,Rsi,PRICE_CLOSE,shift);
}
for(shift=limit-1; 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//second ma
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]-4; Dn[shift] = EMPTY_VALUE;
if(alertOn && Up[0] != EMPTY_VALUE && Bars>alertBar){
Alert("SGMAR Up signal on ", Symbol()," M", Period()," at ",Close[0]); alertBar = Bars;}//Bid tester Close[0]
}
else
{
Dn[shift] = MaF[shift]+2; Up[shift] = EMPTY_VALUE;
if( Dn[0] != EMPTY_VALUE && Bars>alertBar) {
Alert("SGMAR Down Signal on ",Symbol()," M", Period()," at ",Close[0]); alertBar = Bars;}//Bid
}
}
}
return(0);
}
Comments