StochCrossAlert_MTF

Author: FxFisherman.com
StochCrossAlert_MTF

This script is designed as a technical analysis tool for the MetaTrader platform, specifically engineered to identify and alert traders to specific movements in the "Stochastic Oscillator." The primary goal of this logic is to detect when two key moving lines within the Stochastic indicator cross each other, signaling potential shifts in market momentum.

Core Mechanics

1. Cross Detection Logic The script continuously monitors the relationship between two lines: the Main line (K) and the Signal line (D). It looks for a specific "crossover" event:

  • Bullish Signal: It triggers an alert when the Main line moves from being below or equal to the Signal line to moving above it.
  • Bearish Signal: It triggers an alert when the Main line moves from being above or equal to the Signal line to moving below it.

To ensure accuracy and prevent multiple alerts for the same movement, the script includes a "memory" function. Once a cross is detected on a specific candle, it registers that time and will not trigger another alert until a new candle begins.

2. Strength Calculation Beyond simply identifying the cross, the script calculates a "Strength" value. This is derived from the mathematical distance between the two lines at the moment of the crossover. A smaller gap suggests a stronger, more decisive movement, while a larger gap may indicate a weaker transition.

Multi-Timeframe Configuration

While the primary alert system focuses on the current chart's Stochastic crossover, the script contains a comprehensive framework for multi-timeframe analysis. It is configured to monitor up to four different timeframes simultaneously. This allows users to define:

  • Specific Timeframes: Monitoring different intervals (e.g., 5-minute, 15-minute, 60-minute) at once.
  • Customized Thresholds: Setting specific "High" and "Low" levels for the Stochastic indicator on these secondary timeframes to identify overbought or oversold conditions.
  • Trend Consistency: The logic allows for checking consecutive candle movements (increases or decreases) across these multiple periods.

User Notifications

When a crossover condition is met, the script provides immediate feedback to the trader through two methods:

  • Auditory Alerts: It plays specific sound files (alerts) to notify the user without them having to watch the screen constantly.
  • Visual Pop-ups: It generates a text alert on the trading platform screen, displaying the current asset name, the timeframe, and the specific Stochastic values at the time of the cross.

Visual Identity

The script includes a "watermark" feature that places a small piece of identifying text on the trading chart, ensuring clear branding and origin information for the tool.

Indicators Used
Stochastic oscillator
Miscellaneous
It plays sound alertsIt issuies visual alerts to the screen
11 Views
0 Downloads
0 Favorites
StochCrossAlert_MTF
//+------------------------------------------------------------------+
//|                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 = 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