This script is a specialized trading tool designed to monitor and alert users based on the behavior of the Stochastic Oscillator. Its primary purpose is to identify specific "crosses"—moments when two trend lines within the oscillator interact—and notify the trader instantly through both visual alerts and audio sounds.
Core Logic Overview
The indicator works by analyzing the relationship between two components of the Stochastic Oscillator: the Main line (K) and the Signal line (D).
-
The Signal Trigger: The tool constantly monitors whether the Main line has moved from being below the Signal line to above it (an "Up" cross), or vice versa (a "Down" cross). It specifically looks for these transitions occurring between the most recent price candle and the one immediately preceding it.
-
Cross Verification: To ensure the alert is accurate, the logic verifies that a crossover actually happened on the current movement. If the lines cross upward, it triggers an "Up" alert; if they cross downward, it triggers a "Down" alert.
-
Alert Management: The script includes built-in logic to prevent "alert spam." It tracks the time of the last detected crossover. This ensures that once a cross is identified and the notification is sent, the system will not repeat the same alert multiple times for the same price candle.
-
User Customization & Multi-Timeframe Potential: While the primary active logic focuses on the immediate Stochastic crossing, the script is built with a sophisticated framework that allows users to define multiple different timeframes (e.g., 5 minutes, 15 minutes, 60 minutes). It provides placeholders for advanced filtering, such as:
- Price Fields: Choosing between high/low prices or closing prices.
- Strength Levels: Setting specific thresholds for high and low values.
- Consecutive Candle Checks: Evaluating how many consecutive candles have moved in a specific direction to confirm a trend's momentum before acting.
User Experience
When the conditions for a cross are met, the script performs three simultaneous actions:
- Audio Notification: Plays a specific sound file (configurable by the user).
- Visual Alert: Displays a pop-up message on the trading platform window containing the symbol name, the timeframe, and the specific Stochastic values at the time of the cross.
- On-Screen Branding: Displays a decorative watermark on the chart for identification purposes.
In summary, this tool acts as an automated "watchman," scanning the momentum of the market to notify traders the exact moment the trend sentiment shifts according to the Stochastic Oscillator's moving lines.
//+------------------------------------------------------------------+
//| 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 = 11;
extern int Stoch_D = 3;
extern int Stoch_Slowing = 3;
extern int TimeFrame_1 = 5, // {1=M1, 5=M5, 15=M15, ..., 1440=D1, 10080=W1, 43200=MN1}
KPeriod_1 = 5,
DPeriod_1 = 3,
Slowing_1 = 3,
MAMethod_1 = 0, // {0=SMA, 1=EMA, 2=SMMA, 3=LWMA}
PriceField_1 = 0; // {0=Hi/Low, 1=Close/Close}
extern bool UseOpenCandle_1 = false;
extern int TimeFrame_2 = 15, // {1=M1, 5=M5, 15=M15, ..., 1440=D1, 10080=W1, 43200=MN1}
KPeriod_2 = 5,
DPeriod_2 = 3,
Slowing_2 = 3,
MAMethod_2 = 0, // {0=SMA, 1=EMA, 2=SMMA, 3=LWMA}
PriceField_2 = 0, // {0=Hi/Low, 1=Close/Close}
StochLevelHigh_2 = 75, // The stoch value for this time frame must be greater than this value
StochLevelLow_2 = 25, // The stoch value for this time frame must be less than this value.
PeriodOfInc_Dec_2 = 3; // This is a check for the total number of closed candles that have increased or decreased consectively for condition to be true
// Set to zero and UseOpenCandle_2 = true if only open candle to check for condition is desired
// Set to 1 if 1 closed candle is desired for condition and then open candle option as desired. Etc for more closed candles
extern bool UseOpenCandle_2 = true;
extern bool UseStochCondition_3 = true; // This is if the user wants to use the stoch 3 and stoch 4 condition check
extern int TimeFrame_3 = 60, // {1=M1, 5=M5, 15=M15, ..., 1440=D1, 10080=W1, 43200=MN1}
KPeriod_3 = 5,
DPeriod_3 = 3,
Slowing_3 = 3,
MAMethod_3 = 0, // {0=SMA, 1=EMA, 2=SMMA, 3=LWMA}
PriceField_3 = 0, // {0=Hi/Low, 1=Close/Close}
StochLevelHigh_3 = 70, // The stoch value for this time frame must be greater than this value
StochLevelLow_3 = 30, // The stoch value for this time frame must be less than this value
PeriodOfInc_Dec_3 = 2; // This is a check for the total number of closed candles that have increased or decreased consectively for condition to be true
// Set to zero and UseOpenCandle_3 = true if only open candle to check for condition is desired
// Set to 1 if 1 closed candle is desired for condition and then open candle option as desired. Etc for more closed candles
extern bool UseOpenCandle_3 = true;
extern bool UseStochCondition_4 = true; // This is if the user wants to use the stoch 4 condition check
extern int TimeFrame_4 = 60, // {1=M1, 5=M5, 15=M15, ..., 1440=D1, 10080=W1, 43200=MN1}
KPeriod_4 = 5,
DPeriod_4 = 3,
Slowing_4 = 3,
MAMethod_4 = 0, // {0=SMA, 1=EMA, 2=SMMA, 3=LWMA}
PriceField_4 = 0, // {0=Hi/Low, 1=Close/Close}
StochLevelHigh_4 = 70, // The stoch value for this time frame must be greater than this value
StochLevelLow_4 = 30, // The stoch value for this time frame must be less than this value
PeriodOfInc_Dec_4 = 2; // This is a check for the total number of closed candles that have increased or decreased consectively for condition to be true
// Set to zero and UseOpenCandle_4 = true if only open candle to check for condition is desired
// Set to 1 if 1 closed candle is desired for condition and then open candle option as desired. Etc for more closed candles
extern bool UseOpenCandle_4 = true;
//---- 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 @ ", stochk1);
//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 @ ", stochk1);
//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