Crossover Stochs v1
Download scriptThis script is a specialized trading indicator designed to identify specific momentum shifts in the financial markets by analyzing "Stochastic" oscillators across different timeframes. Its primary purpose is to provide visual cues (arrows on the chart) and real-time notifications (alerts, sounds, or emails) when certain technical conditions for potential "Long" (buy) or "Short" (sell) opportunities are met.
Core Logic and Mechanism
The script functions by monitoring three distinct layers of price data simultaneously to ensure that a trade signal is synchronized across different speeds of market movement:
1. Multi-Layer Momentum Tracking The tool calculates three different types of Stochastic values. These represent the "velocity" and "oversold/overbought" status of the current price:
- Origin Line: A standard momentum measurement.
- Price Line: A secondary momentum measurement with a much higher sensitivity setting, used to track more aggressive price fluctuations.
- Multi-Timeframe Analysis: The script compares the movement of the current chart (e.g., the 5-minute timeframe) against a higher timeframe (the 15-minute timeframe). This ensures that a trade is only signaled if the shorter-term momentum aligns with the broader trend.
2. Signal Detection Criteria For a signal to appear, the script looks for specific "crossovers" and threshold breaches:
- Long (Buy) Signals: The script looks for a scenario where the market has dipped into a lower zone (below 23.6%). It triggers an upward arrow when it detects that the momentum lines are starting to curve upward and cross over each other, while simultaneously ensuring that the current 5-minute momentum is higher than the 15-minute momentum.
- Short (Sell) Signals: Conversely, for a sell signal, it looks for the market to reach an upper zone (above 76.4%). It triggers a downward arrow when the momentum lines begin to curve downward and cross over each other, while ensuring that the current 5-minute momentum is lower than the 15-minute momentum.
3. Dynamic Positioning and Alerts
- Visual Placement: To ensure the arrows do not clutter the price candles, the script calculates the average "range" (the height of recent price bars) and places the Buy/Sell arrows at a specific distance above or below the current price.
- Notification System: The script includes a built-in alert engine. When a valid crossover occurs on the most recent candle, the user can choose to receive a pop-up window alert, an audible sound file, or an automated email notification containing the symbol name and the price at which the signal occurred.
Summary for the User
In simple terms, this script acts as a "filter." Instead of just telling you when the price is moving up or down, it waits for a specific "confluence"—a moment where multiple momentum indicators across different timeframes agree that the market is reversing direction from an extreme point. When these conditions align, it marks the chart with an arrow and sends you an immediate notification.
//+------------------------------------------------------------------+
//| Crossover Stochs v1.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Skyline, 2008"
#property link "http://www.forexpertutti.it"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DodgerBlue
#property indicator_color2 Magenta
#property indicator_width1 2
#property indicator_width2 2
extern string Version = "Crossover Stochs Alerter v1 - coded by Skyline based on Spudfyre trading system - [25 Nov 2008]";
extern string Null4 = "----- Arrows settings -----";
extern int Arrow_Width = 3;
extern double Arrow_Position = 1;
extern string Null5 = "----- Alerts settings -----";
extern bool EnableSoundAlert = true;
extern bool EnableVisualAlert = true;
extern bool EnableEmailAlert = true;
double CrossUp[];
double CrossDown[];
static datetime alertTag = D'1980.01.01';
static datetime soundTag = D'1980.01.01';
static datetime emailTag = D'1980.01.01';
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW, EMPTY,Arrow_Width);
SetIndexArrow(0, 233);
SetIndexBuffer(0, CrossUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY,Arrow_Width);
SetIndexArrow(1, 234);
SetIndexBuffer(1, CrossDown);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
Comment("");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit, i, counter;
double Range, AvgRange;
int counted_bars=IndicatorCounted();
//Comment("\n"+Version); // Current version
//---- 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 = 0; i <= limit; i++)
{
counter=i;
Range=0;
AvgRange=0;
for (counter=i ;counter<=i+9;counter++)
{
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/10;
// Importa Indicatori //
double OriginLine_now = NormalizeDouble(iStochastic(NULL,0,14,3,3,MODE_SMA,0,MODE_MAIN,i),4);
double OriginLine_previous = NormalizeDouble(iStochastic(NULL,0,14,3,3,MODE_SMA,0,MODE_MAIN,i+1),4);
double OriginLine_after = NormalizeDouble(iStochastic(NULL,0,14,3,3,MODE_SMA,0,MODE_MAIN,i-1),4);
double PriceLine_now = NormalizeDouble(iStochastic(NULL,0,100,3,3,MODE_SMA,0,MODE_MAIN,i),4);
double PriceLine_previous = NormalizeDouble(iStochastic(NULL,0,100,3,3,MODE_SMA,0,MODE_MAIN,i+1),4);
double PriceLine_after = NormalizeDouble(iStochastic(NULL,0,100,3,3,MODE_SMA,0,MODE_MAIN,i-1),4);
double Stoch_M5_now = NormalizeDouble(iStochastic(NULL,0,14,1,1,MODE_SMA,0,MODE_MAIN,i),4);
double Stoch_M5_previous = NormalizeDouble(iStochastic(NULL,0,14,1,1,MODE_SMA,0,MODE_MAIN,i+1),4);
double Stoch_M5_after = NormalizeDouble(iStochastic(NULL,0,14,1,1,MODE_SMA,0,MODE_MAIN,i-1),4);
int BarShift_M15 = iBarShift(NULL,PERIOD_M15,Time[i],true)+1;
double Stoch_M15_now = NormalizeDouble(iStochastic(NULL,PERIOD_M15,14,1,1,MODE_SMA,0,MODE_MAIN,BarShift_M15),4);
double Stoch_M15_previous = NormalizeDouble(iStochastic(NULL,PERIOD_M15,14,1,1,MODE_SMA,0,MODE_MAIN,BarShift_M15+1),4);
double Stoch_M15_after = NormalizeDouble(iStochastic(NULL,PERIOD_M15,14,1,1,MODE_SMA,0,MODE_MAIN,BarShift_M15-1),4);
if (
OriginLine_previous < 23.6 && OriginLine_now > 23.6 &&
PriceLine_previous < 23.6 && PriceLine_now < 23.6 &&
Stoch_M5_now > Stoch_M15_now &&
Stoch_M5_now > 20 &&
Stoch_M5_previous < Stoch_M5_now &&
OriginLine_previous < OriginLine_now &&
PriceLine_previous < PriceLine_now &&
Stoch_M15_previous < Stoch_M15_now
)
{
CrossUp[i] = Low[i] - Range*Arrow_Position;
// Alert visivo //
if (EnableVisualAlert==true && i==1 && alertTag!=Time[0])
{
Alert("[Crossover Stochs] - ",Symbol()," LONG @ ",DoubleToStr(Close[i],Digits));
alertTag = Time[0];
}
// Alert Sonoro //
if (EnableSoundAlert==true && i==1 && soundTag!=Time[0])
{
PlaySound ("alert.wav");
soundTag = Time[0];
}
// Alert Email //
if (EnableEmailAlert==true && i==1 && emailTag!=Time[0])
{
SendMail("[Crossover Stochs]",Symbol()+" LONG @ "+DoubleToStr(Close[i],Digits));
emailTag = Time[0];
}
}
else
if (
OriginLine_previous > 76.4 && OriginLine_now < 76.4 &&
PriceLine_previous > 76.4 && PriceLine_now > 76.4 &&
Stoch_M5_now < Stoch_M15_now &&
Stoch_M5_now < 80 &&
Stoch_M5_previous > Stoch_M5_now &&
OriginLine_previous > OriginLine_now &&
PriceLine_previous > PriceLine_now &&
Stoch_M15_previous > Stoch_M15_now
)
{
CrossDown[i] = High[i] + Range*Arrow_Position;
// Alert visivo //
if (EnableVisualAlert==true && i==1 && alertTag!=Time[0])
{
Alert("[Crossover Stochs] - ",Symbol()," SHORT @ ",DoubleToStr(Close[i],Digits));
alertTag = Time[0];
}
// Alert Sonoro //
if (EnableSoundAlert==true && i==1 && soundTag!=Time[0])
{
PlaySound ("alert.wav");
soundTag = Time[0];
}
// Alert Email //
if (EnableEmailAlert==true && i==1 && emailTag!=Time[0])
{
SendMail("[Crossover Stochs]",Symbol()+" SHORT @ "+DoubleToStr(Close[i],Digits));
emailTag = Time[0];
}
}
}
return(0);
}
/*
string Periodo(int TF)
{
if (TF==1) { return("M1"); }
if (TF==5) { return("M5"); }
if (TF==15) { return("M15"); }
if (TF==30) { return("M30"); }
if (TF==60) { return("H1"); }
if (TF==240) { return("H4"); }
if (TF==1440) { return("D1"); }
}
*/
Comments