Cowabunga
Download scriptThis script is designed as a market analysis tool for the MetaTrader platform, specifically tailored to identify market trends and entry signals. It functions by processing multiple technical indicators simultaneously to provide a comprehensive view of price movement.
Core Logic and Behavior
1. Multi-Timeframe Trend Analysis The logic operates by looking at "big picture" data from the 4-hour (H4) timeframe, regardless of which smaller timeframe you are currently viewing. It evaluates three specific conditions to determine the overall market trend:
- Moving Average Crosses: It monitors two different moving averages. If they cross in a specific direction while maintaining certain proportions, it signals a shift in momentum.
- Relative Strength Index (RSI): It checks if the RSI is above or below the 50-level to confirm strength.
- Stochastic Momentum: It analyzes Stochastic oscillators to see if the "Main" and "Signal" lines are moving in harmony with the trend.
When these three conditions align, the script establishes a "Trend." Depending on your settings, it will visually display this trend on your chart as either an upward or downward indicator.
2. Specific Asset Optimization (GBPUSD) The script contains specialized logic specifically for the GBP/USD currency pair on the 15-minute timeframe. When these specific conditions are met, the tool becomes much more detailed, activating a "Trigger" system.
3. Signal Triggers For the optimized GBPUSD settings, the script looks for high-probability "Triggers." To generate a signal, the logic requires several layers of confirmation:
- The current moving averages must cross.
- The RSI must be in the correct zone (above 50 for buys, below 50 for sells).
- The Stochastic indicators must show consistent movement.
- The MACD (Moving Average Convergence Divergence) must show a positive change in momentum.
4. Visual and Notification Output The script communicates its findings to the user in three ways:
- Trend Lines: It draws lines on the chart to indicate the current prevailing market direction.
- Signal Arrows: When a "Trigger" is identified, it places arrows on the chart to highlight the specific entry point.
- Email Alerts: If the email notification feature is enabled, the script can automatically send an alert to your inbox. This alert includes a detailed summary of the market state at the moment of the trigger, including specific values for all technical indicators (Moving Averages, RSI, Stochastic, and MACD) so you can review the data even if you aren't looking at the screen.
Summary of User Experience
For most users, this is a visual guide that helps separate "noise" from actual trend movement by filtering out weak signals. For GBPUSD traders on the 15-minute chart, it acts as a sophisticated alerting system that confirms entries only when multiple technical factors align perfectly with the established higher-timeframe trend.
//+------------------------------------------------------------------+
//| Cowabunga.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
extern int IndicatorDisplacement = 15;
extern bool Show_Trend = true;
extern bool Only_Show_Valid_Triggers= true;
extern bool Send_Mail;
//---- buffers
double UPTrend[];
double DNTrend[];
double UPTrigger[];
double DNTrigger[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- additional buffers are used for counting
IndicatorBuffers(4);
//---- indicators
SetIndexLabel(2,NULL);
SetIndexLabel(3,NULL);
if((Symbol()=="GBPUSD")&&(Period()==PERIOD_M15))
{
SetIndexLabel(0,NULL);
SetIndexLabel(1,NULL);
SetIndexStyle(0,DRAW_LINE,STYLE_DOT,1,Blue);
SetIndexStyle(1,DRAW_LINE,STYLE_DOT,1,Red);
}
else
{
SetIndexLabel(0,"UP TREND");
SetIndexLabel(1,"DOWN TREND");
SetIndexStyle(0,DRAW_LINE,0,3,Blue);
SetIndexStyle(1,DRAW_LINE,0,3,Red);
}
SetIndexStyle(2,DRAW_ARROW,EMPTY,3,Blue);
SetIndexStyle(3,DRAW_ARROW,EMPTY,3,Red);
SetIndexArrow(2,SYMBOL_ARROWUP);
SetIndexArrow(3,SYMBOL_ARROWDOWN);
SetIndexBuffer(0,UPTrend);
SetIndexBuffer(1,DNTrend);
SetIndexBuffer(2,UPTrigger);
SetIndexBuffer(3,DNTrigger);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int maCross,StochCHANGE,maCross4H,StochCHANGE4H,MACDChange,i,counted_bars=IndicatorCounted();
double ma5now,ma10now,ma5prev,ma10prev,ma5now4H,ma10now4H,ma5prev4H,ma10prev4H;
double RSI,Stoch1,Stoch2,Signal1,Signal2,MACDChange1,MACDChange2,RSI4H,Stoch4H1,Stoch4H2,Signal4H1,Signal4H2;
int Trigger,i4h;
static int TrendON;
bool GBP15;
string text,CRLF;
CRLF = CharToStr(13) + CharToStr(10);
GBP15=((Symbol()=="GBPUSD")&&(Period()==PERIOD_M15));
if(Bars<=100) return(0);
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- the last counted bar will be recounted
if(counted_bars>0) counted_bars--;
i=Bars-counted_bars;
while(i>=0)
{
//---- TREND4H
i4h=iBarShift(NULL,PERIOD_H4,iTime(NULL,0,i+1),true)+1;
ma5now4H=iMA(NULL,PERIOD_H4,5,0,MODE_EMA,PRICE_CLOSE,i4h);
ma10now4H=iMA(NULL,PERIOD_H4,10,0,MODE_EMA,PRICE_CLOSE,i4h);
ma5prev4H=iMA(NULL,PERIOD_H4,5,0,MODE_EMA,PRICE_CLOSE,i4h+1);
ma10prev4H=iMA(NULL,PERIOD_H4,10,0,MODE_EMA,PRICE_CLOSE,i4h+1);
if(ma5now4H > ma5prev4H && ma10now4H > ma10prev4H && ma5prev4H < ma10prev4H && ma5now4H > ma10now4H) maCross4H=1;
else if(ma5now4H < ma5prev4H && ma10now4H < ma10prev4H && ma5prev4H > ma10prev4H && ma5now4H < ma10now4H) maCross4H=2;
else maCross4H=0;
RSI4H= iRSI(NULL,PERIOD_H4,9,PRICE_CLOSE,i4h);
Stoch4H1= iStochastic(NULL,PERIOD_H4,10,3,3,MODE_SMA,0,MODE_MAIN,i4h);
Stoch4H2= iStochastic(NULL,PERIOD_H4,10,3,3,MODE_SMA,0,MODE_MAIN,i4h+1);
Signal4H1= iStochastic(NULL,PERIOD_H4,10,3,3,MODE_SMA,0,MODE_SIGNAL,i4h);
Signal4H2= iStochastic(NULL,PERIOD_H4,10,3,3,MODE_SMA,0,MODE_SIGNAL,i4h+1);
if(Stoch4H1>Stoch4H2 && Signal4H1>Signal4H2) StochCHANGE4H=1;
else if(Stoch4H1<Stoch4H2 && Signal4H1<Signal4H2) StochCHANGE4H=2;
else StochCHANGE4H=0;
if((maCross4H==1) && (RSI4H>50) && (StochCHANGE4H==1)) TrendON=1;
if((maCross4H==2) && (RSI4H<50) && (StochCHANGE4H==2)) TrendON=-1;
if(Show_Trend)
{
if(TrendON==1)
{
UPTrend[i]= High[i]+IndicatorDisplacement*Point;
SetIndexLabel(0,"UP TREND");
SetIndexLabel(1,NULL);
}
else if(TrendON==-1)
{
DNTrend[i]= Low[i]-IndicatorDisplacement*Point;
SetIndexLabel(0,NULL);
SetIndexLabel(1,"DOWN TREND");
}
}
if(GBP15)
{
//---- TRIGGERS
ma5now=iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,i+1);
ma10now=iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,i+1);
ma5prev=iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,i+2);
ma10prev=iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,i+2);
if(ma5now > ma5prev && ma10now > ma10prev && ma5prev < ma10prev && ma5now > ma10now) maCross=1;
else if(ma5now < ma5prev && ma10now < ma10prev && ma5prev > ma10prev && ma5now < ma10now) maCross=2;
else maCross=0;
RSI= iRSI(NULL,0,9,PRICE_CLOSE,i+1);
Stoch1= iStochastic(NULL,0,10,3,3,MODE_SMA,0,MODE_MAIN,i+1);
Stoch2= iStochastic(NULL,0,10,3,3,MODE_SMA,0,MODE_MAIN,i+2);
Signal1= iStochastic(NULL,0,10,3,3,MODE_SMA,0,MODE_SIGNAL,i+1);
Signal2= iStochastic(NULL,0,10,3,3,MODE_SMA,0,MODE_SIGNAL,i+2);
if(Stoch1>Stoch2 && Signal1>Signal2) StochCHANGE=1;
else if(Stoch1<Stoch2 && Signal1<Signal2) StochCHANGE=2;
else StochCHANGE=0;
MACDChange1=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i+1);
MACDChange2=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i+2);
if(MACDChange2<0 && MACDChange2<MACDChange1) MACDChange=1;
else if(MACDChange2>0 && MACDChange2>MACDChange1) MACDChange=2;
else MACDChange=0;
if((maCross==1) && (RSI>50) && (StochCHANGE==1) && (MACDChange==1) && ((TrendON==1)||(Only_Show_Valid_Triggers==false))) Trigger=1;
if((maCross==2) && (RSI<50) && (StochCHANGE==2) && (MACDChange==2) && ((TrendON==-1)||(Only_Show_Valid_Triggers==false))) Trigger=2;
if((UPTrigger[i+1]!=0x7fffffff)||(DNTrigger[i+1]!=0x7fffffff)) Trigger=0;
if(Trigger==1) UPTrigger[i+1]= High[i+1]+10*Point;
if(Trigger==2) DNTrigger[i+1]= Low[i+1]-10*Point;
if((Trigger)&&(Send_Mail) && (TimeYear(Time[i])>=Year())&&(TimeMonth(Time[i])>=Month())&&(TimeDay(Time[i])>=Day())&&(TimeHour(Time[i])>=Hour())&&(TimeMinute(Time[i])>=Minute()))
{
if(Trigger==1) text="BUY ";
else text="SELL ";
text=text + "trigger occurred on " +TimeDay(Time[i+1])+"/"+TimeMonth(Time[i+1])+"/"+TimeYear(Time[i+1])+" at "+TimeHour(Time[i+1])+":"+TimeMinute(Time[i+1]) + " (server time)" + CRLF;
text=text + CRLF + CRLF;
text=text + "Trend is ";
if(TrendON==1) text=text + "UP" + CRLF + CRLF;
else text=text + "DOWN" + CRLF + CRLF;
text = text +"MA5 = " + ma5now + CRLF;
text = text +"MA10 = " + ma10now + CRLF;
text = text +"MA5 Previous Bar = " + ma5prev + CRLF;
text = text +"MA10 Previous Bar = " + ma10prev + CRLF;
text = text +"RSI = " + RSI + CRLF;
text = text +"STOCHASTIC MAIN = " + Stoch1 + CRLF;
text = text +"STOCHASTIC SIGNAL = " + Signal1 + CRLF;
text = text +"STOCHASTIC MAIN Previous Bar = " + Stoch2 + CRLF;
text = text +"STOCHASTIC SIGNAL Previous Bar = " + Signal2 + CRLF;
text = text +"MACD = " + MACDChange1 + CRLF;
text = text +"MACD Previous Bar = " + MACDChange2 + CRLF;
SendMail("COWABUNGA Trigger",text);
Print(text);
}
/*if(Trigger>0)
{
Print(TimeDay(Time[i])+"/"+TimeMonth(Time[i])+"/"+TimeYear(Time[i])+" at "+TimeHour(Time[i])+":"+TimeMinute(Time[i]));
Print(Day()+"/"+Month()+"/"+Year()+" at "+Hour()+":"+Minute());
Print(Send_Mail);
}*/
}
Trigger=0;
i--;
}
return(0);
}
//+-----------------------------------------------------------------+
Comments