Download MetaTrader 5
To add comments, please log in or register
Deposit to your account via PayPal
Robert
14
Robert 2014.11.20 21:42 

Hi,

I'm trying to code a EA for the Japanese Candlesticks.  I want an EA that emails/texts/alerts me when a trading opportunity presents itself.  My code is below.  If anyone can help me or offer any feedback, I'd greatly appreciate it.

 

 

//+------------------------------------------------------------------+
//| candlesticks.mq4 |
//| Copyright © 2014, MetaQuotes Software Corp. |
//| MetaTrader 4, MetaTrader 5, TeamWox / MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"


string symbol = "EURUSD";

double this_high = iHigh(symbol,PERIOD_H4,1);
double this_low = iLow(symbol,PERIOD_H4,1);
double this_open = iOpen(symbol,PERIOD_H4,1);
double this_close = iClose(symbol,PERIOD_H4,1);

double last_high = iHigh(symbol,PERIOD_H4,2);
double last_low = iLow(symbol,PERIOD_H4,2);
double last_open = iOpen(symbol,PERIOD_H4,2);
double last_close = iClose(symbol,PERIOD_H4,2);         
                
double this_body = MathAbs(this_close - this_open);
double last_body = MathAbs(last_close - last_open);
double this_candle = this_high - this_low;      
double last_candle = last_high - last_low;

double this_body = MathAbs(this_close - this_open);
double last_body = MathAbs(last_close - last_open);
double three_body = MathAbs(three_close - three_open);
double this_candle = this_high - this_low;
double last_candle = last_high - last_low;
double three_candle = three_high - three_low;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
        patterns();
        patterns_2();

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

//custom function 
int patterns()
{
        
        
        //-------------------------
        //white and black marubozus
        //-------------------------
        if(((this_high > 0.95*this_close) && (this_high < 1.05*this_close)) && 
                ((this_low < 0.95*this_open) && (this_low > 1.05*this_open)))
                {
                        Alert("This is a white marubozu - bullish!");
                
                }
        
        if(((this_high > 0.95*this_open) && (this_high < 1.05*this_open)) && 
                ((this_low < 0.95*this_close) && (this_low > 1.05*this_close)))
                {
                        Alert("This is a black marubozu - bearish!");
                        
                }
        
        
        
        
        //-------------------------
        //hammer
        //-------------------------
        if((this_open < this_close) && 
                ((this_high > 0.9*this_open) && (this_high < 1.1*this_open)) && 
                (this_candle >= 2*this_body))
                {
                        Alert("This is a hammer - bullish!");
                        
                }
        
        //-------------------------
        //hanging man
        //-------------------------
        if((this_open > this_close) && 
                ((this_high > 0.9*this_open) && (this_high < 1.1*this_open)) && 
                (this_candle >= 2*this_body))
                {
                        Alert("This is a hanging man - bearish!");
                        
             
                }
        
        //-------------------------
        //inverted hammer
        //-------------------------
        if((this_open < this_close) && 
                ((this_low > 0.9*this_open) && (this_low < 1.1*this_open)) && 
                (this_candle >= 2*this_body))
                {
                        Alert("This is an inverted hammer - bullish!");
            
                }
        
        //-------------------------
        //shooting star
        //-------------------------
        if((this_open > this_close) && 
                ((this_low > 0.9*this_close) && (this_low < 1.1*this_close)) && 
                (this_candle >= 2*this_body))
                {
                        Alert("This is a shooting star - bearish!");
            
                }
        
        
        
        
        
        //-------------------------
        //bullish engulfing
        //bearish engulfing
        //-------------------------
        if((this_close > this_open) && 
                (last_close < last_open)  && 
                (this_open < last_close) && 
                (this_close > last_open))
                {
                        Alert("This is bullish engulfing!");
            
                }

        if((this_close < this_open) && 
                (last_close > last_open)  && 
                (this_open > last_close) && 
                (this_close < last_open))
                {
                        Alert("This is bearish engulfing!");
           
                }
        
        
        
        
        //-------------------------
        //tweezer tops
        //tweezer bottoms
        //-------------------------
        if((last_close > last_open) && 
                (this_close < this_open) && 
                (last_open < last_close) && 
                ((last_low > 0.9*last_open) && (last_low < 1.1*last_open)) && 
                (last_candle >= 1.75*last_body) && 
                (this_open > this_close) && 
                ((this_low > 0.9*this_close) && (this_low < 1.1*this_close)) && 
                (this_candle >= 1.75*this_body))
                {
                        Alert("This is tweezer tops - bearish!");
           
                }
        
        if((last_close < last_open) && 
                (this_close < this_open) && 
                (last_open > last_close) && 
                ((last_high > 0.9*last_open) && (last_high < 1.1*last_open)) && 
                (last_candle >= 1.75*last_body) && 
                ((this_open < this_close) && 
                ((this_high > 0.9*this_open) && (this_high < 1.1*this_open)) && 
                (this_candle >= 1.75*this_body)))
                {
                        Alert("This is tweezer bottoms - bullish!");
            
                }
        
        
        
        
        
        //-------------------------
        //morning star
        //evening star
        //-------------------------
        if((three_close < three_open) && 
                (last_open < three_close) && 
                (last_close < three_close) && 
                (this_close > this_open) && 
                (this_close > (three_close + .5*three_body)))
                {
                        Alert("This is a morning star - bullish!");
           
                }
        
        if((three_close > three_open) && 
                (last_open > three_close) && 
                (last_close > three_close) && 
                (this_close < this_open) && 
                (this_close < (three_close + .5*three_body)))
                {
                        Alert("This is an evening star - bearish!");
            
                }
        
        
        
        
        //-------------------------
        //three black crows
        //three white soldiers
        //-------------------------
        if((three_close < three_open) && 
                (last_close < last_open) && 
                (this_close < this_open) && 
                (last_body > three_body) && 
                (this_body > last_body) && 
                (last_close < 1.1*last_low || last_close > 0.9*last_low) && 
                (this_close < 1.1*this_low && this_close > 0.9*this_low))
                {
                        Alert("This is three black crows - bearish!");
            
                }
        
        if((three_close > three_open) && 
                (last_close > last_open) && 
                (this_close > this_open) && 
                (last_body > three_body) && 
                (this_body > last_body) && 
                (last_close < 1.1*last_high || last_close > 0.9*last_high) && 
                (this_close < 1.1*this_high && this_close > 0.9*this_high))
                {
                        Alert("This is three white soldiers - bullish!");

                }
        
        
        
        
        //-------------------------
        //three inside up
        //three inside down
        //-------------------------
        if((three_close < three_open) && 
                (three_body > .75*three_candle) && 
                (last_close > three_close + 0.5*three_body) && 
                (this_close > this_open) && 
                (this_close > three_high))
                {
                        Alert("This is three inside up - bullish!");
            
                }
                
        if((three_close > three_open) && 
                (three_body > .75*three_candle) && 
                (last_close < three_close - 0.5*three_body) && 
                (this_close < this_open) && 
                (this_close < three_low))
                {
                        Alert("This is three inside down - bearish!");
            
                }
        
        
         return(0);
}



//custom function number 2
int patterns_2()
{       
        
        //-------------------------
        //piercing line
        //dark cloud cover
        //-------------------------     
        if((last_close < last_open) && 
                (last_body >= 0.65*last_candle) && 
                (this_open < 0.95*last_close) && 
                (this_close > this_open) && 
                (this_close > last_close + 0.5*last_body))
                {
                        Alert("This is a piercing line - bullish!");
            
                }
        
        if((last_close > last_open) && 
                (last_body >= 0.65*last_candle) && 
                (this_open > 1.05*last_close) && 
                (this_close < this_open) && 
                (this_close < last_close - 0.5*last_body))
                {
                        Alert("This is dark cloud cover - bearish!");
           
                }
        
        
        //-------------------------
        //bullish harami
        //bearish harami
        //-------------------------
        if((this_close > this_open) && 
                (last_close < last_open)  && 
                (this_open > last_close) && 
                (this_close < last_open))
                {
                        Alert("This is bullish harami!");
           
                }

        if((this_close < this_open) && 
                (last_close > last_open)  && 
                (this_open < last_close) && 
                (this_close > last_open))
                {
                        Alert("This is bearish harami!");
                
                }       
        
        return(0);
}







Carl Schreiber
5959
Carl Schreiber 2014.11.21 07:59  

just add e.g. a Print() where you want to be informed:

     Print("write here what you want to read?");
whroeder1
13641
whroeder1 2014.11.21 14:48  
rhabramov: If anyone can help me or offer any feedback, I'd greatly appreciate it.
double this_high = iHigh(symbol,PERIOD_H4,1);
double this_low = iLow(symbol,PERIOD_H4,1);
double this_open = iOpen(symbol,PERIOD_H4,1);
double this_close = iClose(symbol,PERIOD_H4,1);
:
  1. Can't offer help since you haven't stated a problem.
  2. All those global variables are constant. You need to assign them at the beginning of start().
  3. When can I expect your check?
Robert
14
Robert 2014.11.22 03:37  
gooly:

just add e.g. a Print() where you want to be informed:

I was thinking more along the lines of an email or SMS message. 
Carl Schreiber
5959
Carl Schreiber 2014.11.22 08:58  
Here is an sample code for sending emails:
ali33
7
ali33 2015.02.03 09:25  

I think the logic is wrong:

        if(((this_high > 0.95*this_close) && (this_high < 1.05*this_close)) && 
                ((this_low < 0.95*this_open) && (this_low > 1.05*this_open)))
                {
                        Alert("This is a white marubozu - bullish!");
                
                }
        
        if(((this_high > 0.95*this_open) && (this_high < 1.05*this_open)) && 
                ((this_low < 0.95*this_close) && (this_low > 1.05*this_close)))
                {
                        Alert("This is a black marubozu - bearish!");
                        
                }
/
To add comments, please log in or register