StochCrossAlert

Download script
Author: FxFisherman.com
StochCrossAlert

This custom indicator for MetaTrader is designed to monitor price momentum and provide real-time audio and visual alerts based on specific behaviors in the Stochastic Oscillator. It serves as a signaling tool to help traders identify potential shifts in market direction without having to manually watch every tick of the price action.

How the Logic Works

The script focuses on two primary components of the Stochastic Oscillator: the "Main" line (representing current momentum) and the "Signal" line (representing a smoothed average of that momentum). By comparing these two lines, the tool identifies when they intersect or "cross" each other.

1. Detection of Momentum Shifts The core functionality is triggered by the crossing of these two lines:

  • Bullish Signal: When the Main line moves from below the Signal line to above it, the script recognizes an upward momentum shift and triggers a "Stoch crosses up!" alert.
  • Bearish Signal: When the Main line moves from above the Signal line to below it, the script recognizes a downward momentum shift and triggers a "Stoch crosses down!" alert.

2. Alert System To ensure that traders do not miss these transitions, the script provides immediate feedback through three distinct channels:

  • On-Screen Alerts: A pop-up notification appears on the trading platform.
  • Audio Notifications: The tool plays specific sound files (user-defined) to provide an audible cue for each type of cross.
  • Visual Identification: It includes a watermark on the chart to identify the source of the tool.

3. Intelligent Filtering To prevent "false positives" or repetitive alerts during a single price candle, the logic includes a time-tracking mechanism. This ensures that the indicator only fires one alert per candle (or time frame). Once a cross is detected for the current moment, it waits for the next candle to arrive before providing another signal.

4. Strength Calculation Behind the scenes, the script also calculates a "strength" value based on the distance between the two Stochastic lines. While the primary alerts are driven by the crosses themselves, this internal calculation helps define how aggressively the momentum is moving relative to its average.

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

//---- 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, 0);
  double stochd0 = iStochastic(Symbol(), Period(), Stoch_K,Stoch_D, Stoch_Slowing, MODE_SMA, 0, MODE_SIGNAL, 0);
  double stochk1 = iStochastic(Symbol(), Period(), Stoch_K,Stoch_D, Stoch_Slowing, MODE_SMA, 0, MODE_MAIN, 1);
  double stochd1 = iStochastic(Symbol(), Period(), Stoch_K,Stoch_D, Stoch_Slowing, MODE_SMA, 0, MODE_SIGNAL, 1);
  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("Stoch crosses up!");
    }else if(stochk1 >= stochd1 && stochk0 < stochd0){
      PlaySound(Sound2);
      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