#Stochastic_Cross_Alert_SigOverlayM_cw_001

Download script
Author: Copyright � 2006, Robert Hill
#Stochastic_Cross_Alert_SigOverlayM_cw_001

This script is an automated technical analysis tool designed for the MetaTrader platform. Its primary purpose is to monitor specific price movements and automatically identify "Buy" or "Sell" signals based on the Stochastic Oscillator, a common momentum indicator used by traders to determine whether an asset is overbought or oversold.

Core Functionality

The tool scans live market data to detect three specific types of technical events:

  • Momentum Crossovers: It identifies when the "Fast" moving line crosses the "Slow" moving line of the Stochastic Oscillator. A crossover upward often suggests a gain in momentum, while a downward crossover may suggest a loss of momentum.
  • Oversold Breakouts: The script monitors the Fast line to see if it has climbed above a specific "Oversold" threshold (defaulting to 20). This can indicate that a downward trend is exhausting and a reversal upward might be occurring.
  • Overbought Breakdowns: Conversely, it monitors the Slow line to see if it has dropped below an "Overbought" threshold (defaulting to 80), which may signal that an upward trend is peaking and a correction is likely.

Visual and Notification Alerts

When one of these conditions is met, the script performs several actions simultaneously to keep the user informed:

  1. Visual Markers: It automatically draws colored arrows directly on your trading chart. Green arrows appear below the price candles to signify potential "Buy" opportunities, while red arrows appear above the candles for potential "Sell" opportunities.
  2. Dynamic Positioning: To ensure clarity, the tool calculates a small buffer zone (based on recent market volatility) so that the arrows are placed at a clean distance from the actual price candle, preventing them from overlapping with the price action.
  3. Real-Time Notifications: The script can be configured to send immediate alerts through two different channels:
    • Audio Alerts: A pop-up sound notification triggered on your computer.
    • Email Notifications: An automated email sent to your registered address containing specific details, including the current price (Bid/Ask), the exact time of the signal, and the specific currency pair or asset being traded.

Customization Options

The logic is highly flexible, allowing users to toggle specific behaviors on or off. You can choose whether you want to rely solely on the line crossovers, only on the overbought/oversold levels, or a combination of both. Additionally, the settings allow for fine-tuning the sensitivity of the Stochastic Oscillator (the "K" and "D" periods) to match different trading styles, from fast-paced scalping to slower, long-term trend following.

Price Data Components
Series array that contains open time of each bar
Indicators Used
Stochastic oscillator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screenIt sends emails
14 Views
0 Downloads
0 Favorites
#Stochastic_Cross_Alert_SigOverlayM_cw_001
//compile//
//+------------------------------------------------------------------+
//|                                       Stochastic_Cross_Alert.mq4 |
//|                                    Copyright © 2006, Robert Hill |
//|                                                                  |
//| Written Robert Hill for use with AIME for the stochastic cross   |
//| to draw arrows and popup alert or send email                     |
//| Modified by Linuxser to display in a separate windows            |
//|                                       http://www.linuxser.com.ar |     
//+------------------------------------------------------------------+

#property copyright "Copyright © 2006, Robert Hill"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LawnGreen
#property indicator_color2 Red
#property indicator_width1  1
#property indicator_width2  1

extern bool SoundON=false;
extern bool EmailON=false;
//---- input parameters
extern int KPeriod=5;
extern int DPeriod=3;
extern int Slowing=3;
extern int MA_Method = 0; // SMA 0, EMA 1, SMMA 2, LWMA 3
extern int PriceField = 0; // Low/High 0, Close/Close 1
extern int       OverBoughtLevel    =  80;
extern int       OverSoldLevel      =  20;
extern bool show_KD_cross = false;
extern bool show_K_OBOScross = true;
extern bool show_D_OBOScross = false;

extern string   note_Price = "PriceField:  Low/High = 0, Close/Close = 1";
extern string   _MA_Method = "SMA0 EMA1 SMMA2 LWMA3";



double CrossUp[];
double CrossDown[];
int flagval1 = 0;
int flagval2 = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
 
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double tmp=0;
   double fastMAnow, slowMAnow, fastMAprevious, slowMAprevious;
   double Range, AvgRange;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;
   
   for(i = 1; i <= limit; i++) {
   
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
//       AvgRange=AvgRange+MathAbs(iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i)-iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i+1));
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;
       
      fastMAnow = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i);
      fastMAprevious = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i+1);

      slowMAnow = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_SIGNAL, i);
      slowMAprevious = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_SIGNAL, i+1);
      
      CrossUp[i] = EMPTY_VALUE;
      CrossDown[i] = EMPTY_VALUE;

      
    if 
    ( ((show_KD_cross)&&(fastMAnow > slowMAnow) && (fastMAprevious < slowMAprevious))||
      ((show_K_OBOScross)&&(fastMAnow > OverSoldLevel) && (fastMAprevious < OverSoldLevel))||
      ((show_D_OBOScross)&&(slowMAnow > OverSoldLevel) && (slowMAprevious < OverSoldLevel)) )

     
      {
         if (i == 1 && flagval1==0)
         {
           flagval1=1;
           flagval2=0;
           if (SoundON) Alert("BUY signal at Ask=",Ask,"\n Bid=",Bid,"\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
           if (EmailON) SendMail("BUY signal alert","BUY signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
         }
         CrossUp[i] = Low[i] - Range*0.5;
//         CrossUp[i] = AvgRange;
         CrossDown[i] = EMPTY_VALUE;
      }
    else if 
     
    ( ((show_KD_cross)&&(fastMAnow < slowMAnow) && (fastMAprevious > slowMAprevious))||
      ((show_K_OBOScross)&&(fastMAnow < OverBoughtLevel) && (fastMAprevious > OverBoughtLevel))||
      ((show_D_OBOScross)&&(slowMAnow < OverBoughtLevel) && (slowMAprevious > OverBoughtLevel)) )
      
    {
         if (i == 1 && flagval2==0)
         {
          flagval2=1;
          flagval1=0;
         if (SoundON) Alert("SELL signal at Ask=",Ask,"\n Bid=",Bid,"\n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
         if (EmailON) SendMail("SELL signal alert","SELL signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
         }
 
          CrossDown[i] = High[i] + Range*0.5;
//        CrossDown[i] = AvgRange;
          CrossUp[i] = EMPTY_VALUE;         
      }
   }

   return(0);
}

Comments