This tool is designed to monitor price momentum and provide real-time notifications when specific trends shift on your trading chart. It simplifies the process of identifying "crossovers"—moments when one moving average line passes through another—which are often used by traders to signal potential entry or exit points.
How it Works
The script focuses on a technical indicator known as the Stochastic Oscillator. This indicator consists of two main lines that move up and down based on recent price action:
- The Main Line: Represents the current momentum of the market.
- The Signal Line: Acts as a smoothed version of the main line to filter out minor "noise."
Core Logic & Features
The script constantly analyzes the relationship between these two lines. It is specifically looking for two types of events:
- Upward Crossover: When the Main Line moves from below the Signal Line to above it, the script recognizes a bullish trend change.
- Downward Crossover: When the Main Line moves from above the Signal Line to below it, the script recognizes a bearish trend change.
Key Functionalities
To ensure the tool is useful for active trading, it includes several automated features:
- Real-Time Alerts: Whenever a crossover occurs, the script automatically generates a text alert on your screen. This alert specifies the current currency pair, the timeframe you are viewing, and the direction of the move (Up or Down).
- Audio Notifications: In addition to visual alerts, the script plays specific sound files to notify you of these movements immediately, ensuring you don't miss a trend shift while away from your screen.
- Smart Filtering: The logic is designed to trigger only once per candle. This prevents "alert fatigue" by ensuring that if a line oscillates rapidly back and forth during a single price candle, the script won't spam you with repeated notifications for the same move.
- Strength Calculation: The tool includes an internal calculation to measure the "strength" of the momentum, providing a mathematical basis for how wide or narrow the gap between these two lines is at any given moment.
In summary, this script acts as a vigilant observer, watching the Stochastic Oscillator for you and announcing exactly when the market momentum flips direction.
//+------------------------------------------------------------------+
//| StochCrossStrength.mq4 |
//| Copyright © 2006 Scorpion@fxfisherman.com |
//+------------------------------------------------------------------+
#property copyright "FxFisherman.com"
#property link "http://www.fxfisherman.com"
#property indicator_chart_window
#property indicator_buffers 1
#include <WinUser32.mqh>
extern string Sound1 = "alert.wav";
extern string Sound2 = "alert2.wav";
extern int Stoch_K = 5;
extern int Stoch_D = 3;
extern int Stoch_Slowing = 2;
//---- buffers
double v1[];
int init()
{
IndicatorBuffers(1);
SetIndexDrawBegin(0,-1);
SetIndexBuffer(0, v1);
SetIndexLabel(0,"Buy");
watermark();
return(0);
}
int start()
{
// Calculate values
double stochk0 = iStochastic(Symbol(), Period(), Stoch_K,Stoch_D, Stoch_Slowing, MODE_SMA, 0, MODE_MAIN, 1);
double stochd0 = iStochastic(Symbol(), Period(), Stoch_K,Stoch_D, Stoch_Slowing, MODE_SMA, 0, MODE_SIGNAL, 1);
double stochk1 = iStochastic(Symbol(), Period(), Stoch_K,Stoch_D, Stoch_Slowing, MODE_SMA, 0, MODE_MAIN, 2);
double stochd1 = iStochastic(Symbol(), Period(), Stoch_K,Stoch_D, Stoch_Slowing, MODE_SMA, 0, MODE_SIGNAL, 2);
int strength = 100 - (MathAbs(stochk0-stochd0)*5);
if (strength<0) strength=0;
// Output
static datetime last_cross;
if (last_cross != Time[0])
{
if (stochk1 <= stochd1 && stochk0 > stochd0)
{
last_cross = Time[0];
PlaySound(Sound1);
Alert(Symbol(), " ", Period(), " Stoch ", Stoch_K, ",", Stoch_D, ",", Stoch_Slowing, " Up");
//Alert("Stoch crosses up!");
}else if(stochk1 >= stochd1 && stochk0 < stochd0){
last_cross = Time[0];
PlaySound(Sound2);
Alert(Symbol(), " ", Period(), " Stoch ", Stoch_K, ",", Stoch_D, ",", Stoch_Slowing, " Dn");
//Alert("Stoch crosses down!");
}
}
return(0);
}
void watermark()
{
ObjectCreate("fxfisherman", OBJ_LABEL, 0, 0, 0);
ObjectSetText("fxfisherman", "fxfisherman.com", 11, "Lucida Handwriting", Black);
ObjectSet("fxfisherman", OBJPROP_CORNER, 2);
ObjectSet("fxfisherman", OBJPROP_XDISTANCE, 5);
ObjectSet("fxfisherman", OBJPROP_YDISTANCE, 10);
return(0);
}
//+------------------------------------------------------------------+
Comments