syst_ ao_sto__m260_sig_alert1.2
Download scriptThis technical script is designed as a trading indicator for the MetaTrader platform, specifically built to identify potential entry and exit points in the financial markets by analyzing price momentum and volatility. It automates the process of "reading" specific market conditions, providing visual cues on the chart and audio alerts for the user.
Core Logic Overview
The script functions by monitoring three primary components of market data simultaneously:
-
Momentum Analysis (Stochastic Oscillator): The tool tracks a "Stochastic" indicator, which measures the velocity of price movement. It looks specifically for instances where the indicator crosses certain high and low thresholds (Overbought and Oversold zones). This helps the user identify when a market trend might be becoming overextended and is due for a correction.
-
Trend Confirmation (Price Action): The script doesn't rely on the momentum indicator alone. It validates signals by checking the relationship between the current price and the previous candle's close. It seeks confirmation that the price is moving in the intended direction before triggering a signal.
-
Volatility Filtering (ATR): To ensure the signals are not generated during "choppy" or flat market conditions, the script incorporates an Average True Range (ATR) calculation. This allows it to dynamically adjust the placement of visual signals based on current market volatility, ensuring that the entry markers are placed at a mathematically relevant distance from the price candles.
Signal Generation
The logic branches into two primary types of signals:
- Long Signals (Buy): Triggered when the momentum indicator crosses above a specific upper limit while the price is showing upward movement. When this occurs, the script paints an upward-pointing arrow on the chart and can trigger a "Long Entry" alert.
- Short Signals (Sell): Triggered when the momentum indicator drops below a specific lower limit while the price shows downward pressure. This results in a downward-pointing arrow and a "Short Entry" alert.
Exit Logic
Unique to this script is its sophisticated exit detection. Once a position signal has been identified, the script continues to monitor the "Awesome Oscillator" (AO) momentum values. It looks for a specific reversal pattern:
- For an active Long position, it waits for the momentum to peak and begin to decline.
- For an active Short position, it waits for the momentum to bottom out and begin to rise.
When these reversal conditions are met, the script generates a secondary visual marker (a "Stop" sign) and sends a specific "Exit" alert, notifying the user that the momentum has shifted enough to consider closing the trade.
User Features
- Visual Aids: The script draws different colored arrows and lines directly on the price chart to distinguish between entries, exits, and trend shifts.
- Real-Time Notifications: If enabled, the script will send pop-up alerts in the trading platform every time an entry or exit condition is met, allowing traders to monitor the market without constantly staring at the screen.
- Customizable Thresholds: Users can adjust the sensitivity of the indicators (such as the overbought/oversold levels) to fit different trading styles or specific currency pairs.
//http://www.forexfactory.com/showthread.php?p=2181821#post2181821
//syst_ha_ma_sto_stevejames_alert.mq4
//http://www.fxfisherman.com/forums/forex-metatrader/trading-systems/5310-stochastic-trading-system-highly-profitable.html
//2009fxtsd
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 RoyalBlue
#property indicator_color2 OrangeRed
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_color5 RoyalBlue
#property indicator_color6 OrangeRed
#property indicator_width1 0
#property indicator_width2 0
extern bool AlertOn = false;
extern double arrOffset=0.7; // above/below high/low to paint arrows
extern int StochK=10; // Stochastic %K
extern int StochD=1; // Stochastic %D
extern int StochSlowing=3; // Stochastic Slowing
extern int StochMethod=MODE_SMA; // Stochastic Method
extern int StochPrice=0; // Stochastic Price (0=low/high, 1=close/close)
extern int StoObLv =60;
extern int StoOsLv =40;
//extern double PSARStep=0.05; // Parabolic SAR Step
//extern double PSARMax=0.2; // Parabolic SAR Maximum
datetime timenow;
static datetime extime;
double SignalL[],SignalS[];
double SignalLlv[],SignalSlv[];
double SignalLex[],SignalSex[];
//===========================================================================================
//===========================================================================================
int init()
{
SetIndexBuffer(0,SignalL);
SetIndexBuffer(1,SignalS);
SetIndexStyle(0, DRAW_ARROW);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(0,SYMBOL_ARROWUP);
SetIndexArrow(1,SYMBOL_ARROWDOWN);
SetIndexEmptyValue(0,EMPTY_VALUE);
SetIndexEmptyValue(1,EMPTY_VALUE);
SetIndexBuffer(2,SignalLex);
SetIndexBuffer(3,SignalSex);
SetIndexStyle(2, DRAW_ARROW);
SetIndexStyle(3, DRAW_ARROW);
SetIndexArrow(2,SYMBOL_STOPSIGN);
SetIndexArrow(3,SYMBOL_STOPSIGN);
SetIndexEmptyValue(2,EMPTY_VALUE);
SetIndexEmptyValue(3,EMPTY_VALUE);
SetIndexStyle(4, DRAW_LINE);
SetIndexStyle(5, DRAW_LINE);
SetIndexBuffer(4,SignalLlv);
SetIndexBuffer(5,SignalSlv);
return(0);
}
//===========================================================================================
//===========================================================================================
int deinit()
{
return(0);
}
//===========================================================================================
//===========================================================================================
int start()
{
int i,limit,counted_bars=IndicatorCounted();
// double ac0,ac1,ao0,ao1,ss0,ss1,sm0,sm1,ss2,sar0,sar1;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(i=limit; i>=0; i--)
{
// double ac0=iAC(NULL,0,i);
// double ac1=iAC(NULL,0,i+1);
double ao0=iAO(NULL,0,i);
double ao1=iAO(NULL,0,i+1);
double ao2=iAO(NULL,0,i+2);
// double sar0=iSAR(NULL,0,PSARStep,PSARMax,i);
// double sar1=iSAR(NULL,0,PSARStep,PSARMax,i+1);
double sm0=iStochastic(NULL,0,StochK,StochD,StochSlowing,StochMethod,StochPrice,MODE_MAIN,i);
double sm1=iStochastic(NULL,0,StochK,StochD,StochSlowing,StochMethod,StochPrice,MODE_MAIN,i+1);
double ss0=iStochastic(NULL,0,StochK,StochD,StochSlowing,StochMethod,StochPrice,MODE_SIGNAL,i);
double ss1=iStochastic(NULL,0,StochK,StochD,StochSlowing,StochMethod,StochPrice,MODE_SIGNAL,i+1);
//---
bool paup=false;
if (Close[i]>Close[i+1]) paup=true; else paup=false;
bool padn=false;
if (Close[i]<Close[i+1]) padn=true; else padn=false;
// Stochastic Notes
// Main = %K = Solid/Teal Line
// Signal = %D = Dashed/Red Line
// sm2<limit && sm1>limit = Main line crossed above limit
// sm2>limit && sm1<limit = Main line crossed below limit
// ss2<limit && ss1>limit = Signal line crossed above limit
// ss2>limit && ss1<limit = Signal line crossed below limit
// sm1>ss1&&sm2<ss2 = Stochastic Cross Up
// sm1<ss1&&sm2>ss2 = Stochastic Cross Down
// AC & AO Notes
// ac1>ac2 = Green AC
// ac1<ac2 = Red AC
// ao1>ao2 = Green AO
// ao1<ao2 = Red AO
SignalL[i]=EMPTY_VALUE;
SignalS[i]=EMPTY_VALUE;
SignalLlv[i]=SignalLlv[i+1];
SignalSlv[i]=SignalSlv[i+1];
// if(sar0<iOpen(NULL,0,i)&& sar1>iOpen(NULL,0,i+1))
// {}
if( sm0>StoObLv && sm1<StoObLv && paup ) //ao0>ao1 &&
{
SignalL[i] = iLow(NULL,0,i)-arrOffset*iATR(NULL,0,7,i);
SignalLlv[i]= iHigh(NULL,0,i)+10*Point;SignalSlv[i]= EMPTY_VALUE;
}
// else SignalL[i]= EMPTY_VALUE;
// if(sar0>iOpen(NULL,0,i)&& sar1<iOpen(NULL,0,i+1))
// {}
if ( sm0<StoOsLv && sm1>StoOsLv )// && ao0<ao1
{
SignalS[i] = iHigh(NULL,0,i)+arrOffset*iATR(NULL,0,7,i);
SignalSlv[i]= iLow(NULL,0,i)-10*Point; SignalLlv[i]= EMPTY_VALUE;
}
if (SignalLlv[i]!= EMPTY_VALUE && ao2<ao1 && ao1>ao0)SignalLex[i]= iLow(NULL,0,i)-10*Point;
if (SignalSlv[i]!= EMPTY_VALUE && ao2>ao1 && ao1<ao0)SignalSex[i]= iHigh(NULL,0,i)+10*Point;
// else SignalS[i]= EMPTY_VALUE;
if(AlertOn)
{
if ( timenow != Time[0])
{
if ( SignalL[0] != EMPTY_VALUE )
{
Alert( "StoAO: EntryLongSignal ", Symbol()," M",Period());
timenow = Time[0];
}
if ( SignalS[0] != EMPTY_VALUE )
{
Alert ( "StoAO: EntryShortSignal ", Symbol()," M",Period());
timenow = Time[0];
}
}
if (extime != Time[0] )
{
if ( SignalLex[0] != EMPTY_VALUE )
{
Alert( "StoAO: ExitLongSignal ", Symbol()," M",Period());
extime = Time[0];
}
if ( SignalSex[0] != EMPTY_VALUE )
{
Alert ( "StoAO: ExitShortSignal ", Symbol()," M",Period());
extime = Time[0];
}
}
}
}
return(0);
}
//===========================================================================================
//===========================================================================================
Comments