SGMAR
Download scriptThis technical indicator is designed to provide traders with a visual representation of momentum and trend reversals by analyzing price fluctuations in a dedicated sub-window. It combines three distinct layers of data processing to filter out market "noise" and highlight specific trading signals.
Core Logic and Data Processing
The tool operates through a three-step analysis of the market:
1. Momentum Measurement (RSI) At its foundation, the script calculates a Relative Strength Index (RSI). This standard metric measures the speed and change of price movements. It helps determine whether an asset is being overbought, oversold, or moving with consistent momentum.
2. Dual Moving Average Filtering Instead of looking at the raw RSI data alone—which can be volatile—the script applies two different types of "Moving Averages" to that data:
- Simple Moving Average (SMA): This smooths out the data to show the general path of the momentum.
- Exponential Moving Average (EMA): This gives more weight to recent price action, making it more responsive to immediate changes.
By overlaying these two different averages on top of the RSI, the script creates a "cross" mechanism. The relationship between these two lines helps identify when the momentum is accelerating or decelerating.
3. Signal Identification (The Crossover Logic) The primary logic for generating alerts is based on a "crossover" event between the SMA and the EMA. Specifically, the script looks for a change in the direction of the gap between these two averages.
When these two lines cross each other, it indicates a shift in momentum:
- Bullish Signals: When the lines cross in a specific upward orientation, the script identifies an upward shift and places a visual marker (an arrow) on the chart.
- Bearish Signals: When the lines cross in a downward orientation, the script identifies a downward shift and places a corresponding marker.
Visual Experience
For the user, this means the indicator does not just show you a messy line; it cleans up the data into smoothed trends and provides clear, visual arrows at the exact moment the mathematical logic detects a change in momentum. The inclusion of horizontal reference levels (70, 50, and 30) further helps the trader contextualize these signals by showing whether the current momentum is occurring in extreme territory or neutral territory.
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Lime
#property indicator_color2 Aqua
#property indicator_color3 Red
#property indicator_color4 DarkTurquoise
#property indicator_color5 Red
#property indicator_level1 70
#property indicator_level2 50
#property indicator_level3 30
#property indicator_levelcolor Gray
#property indicator_levelwidth 1
#property indicator_levelstyle STYLE_DASH
extern int Rsi = 14;
extern int Ma = 8;
extern int cbars = 0;
double RsiBuf[];
double MaP[];
double MaF[];
double Up[];
double Dn[];
void init() {
SetIndexStyle (0, DRAW_LINE,0, 2);
SetIndexStyle (1, DRAW_LINE,0,2);
SetIndexStyle (2, DRAW_LINE,0,2);
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,0);
SetIndexEmptyValue(4,0);
SetIndexArrow(3,108);
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--) {
// First Indicator Data
MaF[shift] = iMAOnArray(RsiBuf,0,Ma,0,MODE_SMA,shift);
// Previous Indicator Data
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];
else Dn[shift] = MaF[shift];
}
}
}
Comments