Stochastic_Cross_Alert_Overlay
Download scriptThis tool is designed to act as an automated monitoring system for traders who use the Stochastic Oscillator, a common technical indicator used to identify potential turning points in market momentum. Rather than requiring a trader to constantly watch the charts for specific price movements, this script automatically detects key "crossovers" and provides instant notifications.
Core Functionality
The primary logic of the script revolves around identifying two types of signal movements:
- Buy Signals: These occur when the "fast" line of the oscillator moves from below to above the "slow" signal line. This transition is typically interpreted by traders as an increase in upward momentum.
- Sell Signals: These occur when the "fast" line drops from above to below the "slow" signal line, which is often viewed as a sign of downward momentum.
How it Works
The script performs several background actions to ensure accuracy and usability:
- Real-Time Monitoring: The script continuously scans the most recent market data to determine if the current price action has caused the two indicator lines to cross one another.
- Crossover Detection: It looks specifically for the moment of intersection. It distinguishes between a "cross" and the lines simply moving alongside each other, ensuring that signals are only triggered at the point of change.
- Dynamic Range Calculation: To ensure the visual indicators on the chart are meaningful, the script calculates an average range based on recent price fluctuations. This helps in determining how to represent the signal visually.
- Visual Feedback: When a crossover is detected, the script places specific icons (arrows) directly on the trading chart. This allows the trader to see historical signals at a glance.
Notification System
To ensure that traders do not miss critical market movements, the script includes an integrated alert system. Depending on the user's preferences, it can perform three different actions simultaneously when a signal is confirmed:
- Pop-up Alerts: A visual notification window appears on the trading platform screen.
- Audio Alerts: An audible sound plays to grab the trader's attention.
- Email Notifications: The script can automatically send an email containing the specific details of the trade, including the current price (Ask and Bid), the exact time of the signal, the currency pair being traded, and the timeframe.
User Customization
The logic is designed to be flexible. Users can adjust the sensitivity of the Stochastic Oscillator (the periods and smoothing factors) to match their specific trading style—whether they prefer capturing quick, short-term fluctuations or identifying broader, longer-term trends.
//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_separate_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
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));
}
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 ((fastMAnow > slowMAnow) && (fastMAprevious < slowMAprevious))
{
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] = AvgRange;
CrossDown[i] = EMPTY_VALUE;
}
else if ((fastMAnow < slowMAnow) && (fastMAprevious > slowMAprevious))
{
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] = AvgRange;
CrossUp[i] = EMPTY_VALUE;
}
}
return(0);
}
Comments