Download MetaTrader 5
To add comments, please log in or register
Register at MQL5.community and leave your comments!
Robert
11
Robert 2014.10.12 00:27 

Hey y'all,

 I recently started working with MQL4 and I need some help with my code.  Although it runs and I can execute my EA, it doesn't work like it's supposed to.  Any help or tips wold be greatly appreciated.  The code is attached below:

It runs in that it compiles successfully and I can attach it to charts, but it doesn't send out alerts.  Basically, I want this to run at the end of every session, and analyze the last 3 candlesticks for the Japanese Candlestick patterns below for the D1 and the H4 charts.   

 

//+------------------------------------------------------------------+

//| 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);

} 
Keith Watford
Moderator
7953
Keith Watford 2014.10.12 00:33  

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))

{
If you write your long lines of code like this, it makes everything easier to read
whroeder1
13619
whroeder1 2014.10.12 12:50  
rha1: it doesn't work like it's supposed to.
  1. Previously asked and answered. Don't double post
  2. Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling back and forth trying to read it. Edit the post with formatted code and you might get additional help.
/
To add comments, please log in or register