Vinin_LRMA_Color_Sound
Download scriptThis tool is designed as a visual aid for traders to help identify shifts in market momentum and trend direction directly on their charts. By analyzing price action through specialized moving averages, it provides clear, color-coded signals that simplify the interpretation of complex market data.
Core Logic and Visualization
The script works by calculating two different types of moving averages simultaneously based on a user-defined timeframe. It then applies a specific mathematical formula to these averages to generate a dynamic line on your chart.
The primary purpose of this calculation is to detect "momentum." Instead of just showing where the price is, it highlights how fast and in what direction the price is moving. To make this easy to read at a glance, the tool uses a color-coding system:
- Green Line: Appears when the calculated momentum is increasing, suggesting an upward trend or bullish sentiment.
- Red Line: Appears when the calculated momentum is decreasing, suggesting a downward trend or bearish sentiment.
- Yellow Line: Serves as the base calculation point for the momentum shifts.
Real-Time Alerts
Beyond just providing visual cues, the script includes an automated notification system. It monitors the transition between these colors in real-time. When the momentum switches—for example, moving from a Green state to a Red state (or vice versa)—the tool can trigger an audible alert sound. This ensures that you are notified of potential trend reversals immediately, even if you are not staring directly at the chart.
Customization Options
Users have several ways to tailor the experience to their specific trading style:
- Period: Adjust how many previous bars are considered in the calculation (higher numbers smooth out the data; lower numbers make it more sensitive to recent price changes).
- Price Source: Define which specific price data (such as Close, Open, etc.) the indicator should follow.
- Sound Settings: Toggle audio alerts on or off and customize the specific sound file used for notifications.
- Visual Shift: Adjust the position of the lines on the chart to better align with your personal layout.
//+------------------------------------------------------------------+
//| Vinin_LRMA_Color&&Sound v1.mq4 |
//| Victor Nicolaev aka Vinin |
//| vinin@mail.ru |
//+------------------------------------------------------------------+
#property copyright "2008, Victor Nicolaev aka Vinin"
#property link "mailto: vinin@mail.ru"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
extern int period=21;
extern int price=0;
extern int Shift=0;
extern bool bPlaySound=true;
extern string SoundName="alert.wav";
extern int CheckBar=0;
//---- buffers
double BufferGreen[];
double BufferYellow[];
double BufferRed[];
double alertTag;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
int i;
for (i=0;i<3;i++) {
SetIndexStyle(i,DRAW_LINE);
SetIndexDrawBegin(i,period);
SetIndexShift(i,Shift);
}
SetIndexBuffer(0,BufferYellow);
SetIndexBuffer(1,BufferGreen);
SetIndexBuffer(2,BufferRed);
return(0); }//int init()
//+------------------------------------------------------------------+
int start() {
int limit;
double tmp1,tmp2,tmp3;
int tmpBar, tmpTime;
int counted_bars=IndicatorCounted();
int i, j,k;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
int cmd;
for (i = limit;i>=0;i--){
tmp1=iMA(Symbol(),0,period,0,MODE_SMA,price,i);
tmp2=iMA(Symbol(),0,period,0,MODE_LWMA,price,i);
tmp3=3.0*tmp2-2.0*tmp1;
BufferGreen[i] =tmp3;
BufferYellow[i]=tmp3;
BufferRed[i] =tmp3;
if (BufferYellow[i]>BufferYellow[i+1]){
BufferRed[i]=EMPTY_VALUE;
} else if (BufferYellow[i]<BufferYellow[i+1]){
BufferGreen[i] =EMPTY_VALUE;
} else {
BufferRed[i]=EMPTY_VALUE;
BufferGreen[i] =EMPTY_VALUE;
}
}
if (bPlaySound &&alertTag!=Time[0]) {
if (BufferRed[CheckBar+1]==EMPTY_VALUE && BufferRed[CheckBar]!=EMPTY_VALUE ) PlaySound(SoundName);
if (BufferGreen[CheckBar+1]==EMPTY_VALUE && BufferGreen[CheckBar]!=EMPTY_VALUE) PlaySound(SoundName);
alertTag=Time[0];
}
return(0);
}
Comments