functions and function calls

 
Hi
I'm noob alert !

Backround subject:
I'm learning about the changes since build 600+ after a long lapse in learning mql4
At best I was only intermediate beginner back then.
Anyhow, specifically functions and function calls.

First Question:
ref:
https://book.mql4.com/programm/samples
I assume I (would or could) now use the new OnInit(),OnStart(), and OnDeinit() instead of the ref: linked init(),start(), and deinit() ?

The question is about global declaration of functions?
I see posts asking questions about code, and they show custom functions inside the start() function.
I'm assuming they did not show the global declaration of their code ?

Any declaration of a function other then global for me produces an error
(function can only be declared on global scope)

Am I assuming correctly on this; and based on the ref: link provided ?

Please advise




Second:
Additionally I am testing function call output to see how things work.
I am having trouble getting any output of the function call at all.

Anything I can read to find out why ?
Thanks

//+------------------------------------------------------------------+
//|                                                 functiontest.mq4 |
//|                                                 testing code     |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "You know not what you are doing"
#property link      "http:www.me_no_like_your_code.com"
#property version   "1.00"
#property strict


 bool bullishengulfing() //Bullish Engulfing Candle
   {
      if(Open[2] > Close[2]        //bear candle identified
            && Open[1] < Close[1]  //bull candle identified
            && Open[1] < Close[2]  //bull engulfing condition
            && Open[2] < Close[1]) //open of previous bear lower then bull close = engulfing condition
               {
               Print (Close[1], " Bullish Engulfing Candle ");
               return(true);
               }
       else
       Print (" No Bullish Engulfing Candle Found");
       return(false);
       
    }

bool bearishengulfing() //Bearish Engulfing Candle
   {
      if(Open[2] < Close[2]     //bull candle identified
            && Open[1] > Close[1]  //bear candle identified
            && Open[1] > Close[2]  //bear engulfing condition
            && Open[2] > Close[1]) //bear engulfing condition
               {
               Print (Close[1], " Bearish Engulfing Candle "); 
               return(true);
               }
      else
      Print (" No Bearish Engulfing Candle Found");
      return(false);
    }



//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

int OnInit()
  {
//---
  

   
   
//---
   return(INIT_SUCCEEDED);
  }
  
   
  
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }


int OnStart()
   {
   if(bullishengulfing())
      {
      return(bullishengulfing());
      Print ("OK");
      }
   

    return(0);
   
   }



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


   
 
int OnStart()
   {
   if(bullishengulfing())
      {
      return(bullishengulfing());     //WHAT IS THIS MEANT TO DO????
      Print ("OK");
      }
   

    return(0);
   
   }
if your function returns true, you exit start before doing anything, but you should still get the print (in the experts tab) if the function is true.
 
Agent86: I assume I (would or could) now use the new OnInit(),OnStart(), and OnDeinit() instead of the ref: linked init(),start(), and deinit() ?
int OnStart()
  1. Don't assume, read the manual.
  2. OnStart is a void function and only works with scripts.
 
WHRoeder:
Agent86: I assume I (would or could) now use the new OnInit(),OnStart(), and OnDeinit() instead of the ref: linked init(),start(), and deinit() ?
  1. Don't assume, read the manual.
  2. OnStart is a void function and only works with scripts.
Ok thanks
I misunderstood this
For the OnStart() function, the int return type can be specified.

Also this confused me as well:
source: https://docs.mql4.com/mql4changes
"init(), deinit() and start() predefined functions have remained for compatibility, however, OnInit(), OnDeinit(), OnStart(), OnCalculate() and OnTick() ones can now be used instead
"

Ok so back to the drawingboard
Thanks
 
Oh FYI I do understand now why not output from the EA; and based on what WHRoeder corrected me on.

Not because of exiting but simply because i'ts not even and EA and I'm running it with the EA tester to read the journal of the print output.
Obviously now that I know OnStart() is for script only, it is apparent the EA will not run my code because it's not recognizing it as an EA for testing.

So anyhow I get it, thanks
 
GumRai:
if your function returns true, you exit start before doing anything, but you should still get the print (in the experts tab) if the function is true.
Ok so what it's suppose to do is find bullish engulfing candle if it exists then return true
I may be confused about what I'm returning. I thought that return(true): would be an assignment of true to the function.
So if bullish candle exists bullishengulfing() ==true; ?? Is that not what I'm saying here with this function ?

bool bullishengulfing() //Bullish Engulfing Candle
   {
      if(Open[2] > Close[2]        //bear candle identified
            && Open[1] < Close[1]  //bull candle identified
            && Open[1] <= Close[2]  //bull engulfing condition
            && Open[2] < Close[1]) //open of previous bear lower then bull close = engulfing condition    
               {
               Print(Close[1], " Bullish Engulfing Candle ", " and bullsize = ",Close[1]-Open[1]);
               return(true);
               }
       else
       Print(" No Bullish Engulfing Candle Found");
       return(false);        
       
    }

int start()
   {
   if(bullishengulfing())
      {
      return(0);
      }
   
   return(0);
   
   }

It finds the bullish-engulfing candle

Unfortunately it doesn't seem to work exactly the way I want, finding little bullish engulfing candles;  and also when testing the size of the candle it's prints junk like this with a lot of decimals:

2014.09.30 12:34:52.973    2013.11.27 20:59  functiontest EURUSD,M5: 1.35718 1.35707 Bullish Engulfing Candle  and bullsize = 0.0001100000000000545
2014.09.30 12:34:52.973    2013.11.27 20:59  functiontest EURUSD,M5: 1.35718 1.35707 Bullish Engulfing Candle  and bullsize = 0.0001100000000000545
2014.09.30 12:34:52.973    2013.11.27 20:59  functiontest EURUSD,M5: 1.35718 1.35707 Bullish Engulfing Candle  and bullsize = 0.0001100000000000545
2014.09.30 12:34:52.973    2013.11.27 20:59  functiontest EURUSD,M5: 1.35718 1.35707 Bullish Engulfing Candle  and bullsize = 0.0001100000000000545
2014.09.30 12:34:52.973    2013.11.27 20:59  functiontest EURUSD,M5: 1.35718 1.35707 Bullish Engulfing Candle  and bullsize = 0.0001100000000000545
2014.09.30 12:34:52.973    2013.11.27 20:59  functiontest EURUSD,M5: 1.35718 1.35707 Bullish Engulfing Candle  and bullsize = 0.0001100000000000545
 

I must have been suffering with brain freeze when I posted before!

If you don''t want all the decimal places use 

DoubleToStr( Close[1]-Open[1],Digits)

 Also use a check to only call the function once per bar, so you don't get the print every tick

 
GumRai:

I must have been suffering with brain freeze when I posted before!

If you don''t want all the decimal places use 

 Also use a check to only call the function once per bar, so you don't get the print every tick

Perfect, thanks

Ok so once per bar hmmm ?
This is a concept I have struggled with since I started learning code, but I'll get this worked out thanks.


What about calling functions ?
I'm curious if the expression is:
if(function())

Is this statement always considered true regardless of the return(true);

I'm wondering if it's always true simply if the function exists ?
I'm trying to make it true or false but I may misunderstand this.

Am I not suppose to if - return(true); and else -return(false); ?
Is this a bad use of a function ?

Additionally, calling the function vs putting the the code in the int start() seems to have different results.
I thought they should be the same results which is the point of making the function. I obviously must misunderstand this and don't know what I'm missing.


Please advise
Thanks
 

 
Ok forget the bullish candles for a moment please.
Review this function regarding macdup instead
This seems to create an always true function too

This is my test functions codes below

I'm testing macdup() and the output is always true and never prints the else statement and never seems to be false.
This is why I'm asking if the functions simply exists does this make if(macdup()) == true always  ?

Look at the printout from the journal. It's has strange times too, not really reading all the macdup() signals either. Seems to be random and not really a signal at all.

Please advise thanks

//+------------------------------------------------------------------+
//|                                                 functiontest.mq4 |
//|                                                 testing code     |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "You know not what you are doing"
#property link      "http:www.me_no_like_your_code.com"
#property version   "1.00"




bool macdup()
   {
      if(faster > slower)
         {
         Print(" MACD UP");
         return(true);
         }
      else
      Print(" No Up Signal");
      return(false);
    //return(true);  
   }
   
   
bool macddown()
   {
      if(faster < slower)
         {
         Print(" MACD DOWN");
         return(true);
         }
      else
      Print(" No Down Signal");
      return(false);
   }   

bool bullishengulfing() //Bullish Engulfing Candle
   {
      if(Open[2] > Close[2]        //bear candle identified
            && Open[1] < Close[1]  //bull candle identified
            && Open[1] <= Close[2]  //bull engulfing condition
            && Open[2] < Close[1]) //open of previous bear lower then bull close = engulfing condition    
               {
               Print(Close[1], " Bullish Engulfing Candle ", " and bullsize = ",Close[1] - Open[1]);
               return(true);
               }
       else
       Print(" No Bullish Engulfing Candle Found");
       return(false);        
       
    }

bool bearishengulfing() //Bearish Engulfing Candle
   {
      if(Open[2] < Close[2]     //bull candle identified
            && Open[1] > Close[1]  //bear candle identified
            && Open[1] >= Close[2]  //bear engulfing condition
            && Open[2] > Close[1]) //bear engulfing condition
               {
               Print (Close[1], " Bearish Engulfing Candle "); 
               return(true);
               }
      else
      Print (" No Bearish Engulfing Candle Found");
      return(false);
    }

//+------------------------------------------------------------------+
//| Writing variables below my functions                             |
//+------------------------------------------------------------------+

bool bulls;
double      faster = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,3), //MODE_MAIN
            slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,3); //MODE_SIGNAL


//++++ These are adjusted for 5 digit brokers.

int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150

    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

int OnInit()
  {
  
   if (Digits == 5 || Digits == 3)   //Digits reads how many digits my broker has
      {    // Adjust for five (5) digit brokers.
         pips2dbl    = Point*10; pips2points = 10;  //Points converts the number to decimal tradeable number we use *10 for 5 digit
      } 
   else 
      {    
         pips2dbl    = Point;    pips2points =  1;
      }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
  
//---
 
//---
   return(INIT_SUCCEEDED);
  }
  
   
  
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }


int start()
   {
   if(macdup())
      {
      //return;
      }
   
   return(0);
   
   }



//+------------------------------------------------------------------+
//NOTES:
//My attempt to make a function true and test the condition has failed
//I need to rethink this because the function call is always true and prints the else statement everytime.


   





2014.10.01 10:19:52.979    EURUSD,M5: 309079 tick events (6993 bars, 310079 bar states) processed within 343 ms (total time 2465 ms)
2014.10.01 10:19:52.979    2014.09.29 23:58  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:58  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:58  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:58  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:57  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:57  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:57  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:57  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:56  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:56  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:55  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:55  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:54  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:54  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:54  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:53  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:53  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:53  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:51  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:51  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:49  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:49  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:49  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:48  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:48  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:47  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:47  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:47  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:46  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:46  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:46  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:45  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:45  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:45  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:44  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:44  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:44  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:43  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:43  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:43  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:43  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:43  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:43  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:43  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:42  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:42  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:42  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:42  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:42  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:42  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:42  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:42  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:42  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:42  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:42  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:42  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:41  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:41  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:41  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:41  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:41  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:41  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:41  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:40  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:40  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:40  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:40  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:40  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:40  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:40  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:39  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:39  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:39  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:39  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:39  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:39  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:39  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:38  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:38  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:38  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:38  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:38  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:38  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:38  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:38  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:38  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:37  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:37  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:37  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:36  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:36  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:36  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:36  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:35  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:35  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:35  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:34  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:34  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:34  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:34  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:34  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:33  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:33  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:33  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:33  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:33  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:33  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:33  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:33  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:33  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:32  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:32  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:32  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:32  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:32  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:32  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:32  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:31  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:31  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:31  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:31  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:31  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:31  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:30  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:30  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:30  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:30  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:30  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:30  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:30  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:30  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:29  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:28  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:28  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:28  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:28  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:28  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:28  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:28  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:28  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:28  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:28  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:27  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:26  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:25  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:25  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:25  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:25  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:25  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:25  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:24  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:24  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:24  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:24  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:24  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:24  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.979    2014.09.29 23:24  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.699    2014.09.08 09:52  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.699    2014.09.08 09:52  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.699    2014.09.08 09:52  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.699    2014.09.08 09:52  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.699    2014.09.08 09:52  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.699    2014.09.08 09:52  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.699    2014.09.08 09:52  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:52.699    2014.09.08 09:52  functiontest EURUSD,M5:  MACD UP
2014.10.01 10:19:50.519    TestGenerator: current spread 11 used
2014.10.01 10:19:50.509    Expert functiontest EURUSD,M5: loaded successfully
2014.10.01 10:19:50.509    Expert functiontest EURUSD,M5: removed
 
OK got some changes and partially doing what I want but there is a laps
I see the function finding engulfing candles I can trace them back on the charts but then all the sudden it jumps back to July

I can see engulfing candles on the charts on 9-29-14 and so on. Why did it quit finding them ?


2014.10.01 12:41:45.770    2014.09.30 15:46  functiontest EURUSD,M5: 1.26284 Bullish Engulfing Candle  and bullsize = 0.00024
2014.10.01 12:41:45.770    2014.09.30 15:46  functiontest EURUSD,M5: 1.26284 Bullish Engulfing Candle  and bullsize = 0.00024
2014.10.01 12:41:45.770    2014.09.30 15:45  functiontest EURUSD,M5: 1.26284 Bullish Engulfing Candle  and bullsize = 0.00024
2014.10.01 12:41:45.770    2014.09.30 15:45  functiontest EURUSD,M5: 1.26284 Bullish Engulfing Candle  and bullsize = 0.00024
2014.10.01 12:41:45.770    2014.09.30 15:40  functiontest EURUSD,M5:  No Bullish Engulfing Candle Found
2014.10.01 12:41:45.280    2014.07.15 08:35  functiontest EURUSD,M5: 1.36148 Bullish Engulfing Candle  and bullsize = 0.00059
2014.10.01 12:41:45.280    2014.07.15 08:35  functiontest EURUSD,M5: 1.36148 Bullish Engulfing Candle  and bullsize = 0.00059
2014.10.01 12:41:45.280    2014.07.15 08:35  functiontest EURUSD,M5: 1.36148 Bullish Engulfing Candle  and bullsize = 0.00059
2014.10.01 12:41:45.280    2014.07.15 08:35  functiontest EURUSD,M5: 1.36148 Bullish Engulfing Candle  and bullsize = 0.00059
2014.10.01 12:41:45.280    2014.07.15 08:35  functiontest EURUSD,M5: 1.36148 Bullish Engulfing Candle  and bullsize = 0.00059
2014.10.01 12:41:45.280    2014.07.15 08:35  functiontest EURUSD,M5: 1.36148 Bullish Engulfing Candle  and bullsize = 0.00059
2014.10.01 12:41:45.280    2014.07.15 08:35  functiontest EURUSD,M5: 1.36148 Bullish Engulfing Candle  and bullsize = 0.00059
2014.10.01 12:41:45.280    2014.07.15 08:35  functiontest EURUSD,M5: 1.36148 Bullish Engulfing Candle  and bullsize = 0.00059
2014.10.01 12:41:44.270    2014.04.17 04:11  functiontest EURUSD,M5: 1.38403 Bullish Engulfing Candle  and bullsize = 0.00023
2014.10.01 12:41:44.270    2014.04.17 04:11  functiontest EURUSD,M5: 1.38403 Bullish Engulfing Candle  and bullsize = 0.00023
2014.10.01 12:41:44.270    2014.04.17 04:11  functiontest EURUSD,M5: 1.38403 Bullish Engulfing Candle  and bullsize = 0.00023
2014.10.01 12:41:44.270    2014.04.17 04:11  functiontest EURUSD,M5: 1.38403 Bullish Engulfing Candle  and bullsize = 0.00023
2014.10.01 12:41:44.270    2014.04.17 04:11  functiontest EURUSD,M5: 1.38403 Bullish Engulfing Candle  and bullsize = 0.00023
2014.10.01 12:41:44.270    2014.04.17 04:11  functiontest EURUSD,M5: 1.38403 Bullish Engulfing Candle  and bullsize = 0.00023
2014.10.01 12:41:44.270    2014.04.17 04:11  functiontest EURUSD,M5: 1.38403 Bullish Engulfing Candle  and bullsize = 0.00023
2014.10.01 12:41:44.270    2014.04.17 04:11  functiontest EURUSD,M5: 1.38403 Bullish Engulfing Candle  and bullsize = 0.00023
2014.10.01 12:41:43.260    2013.11.06 10:37  functiontest EURUSD,M5: 1.35406 Bullish Engulfing Candle  and bullsize = 0.00076
2014.10.01 12:41:43.260    2013.11.06 10:37  functiontest EURUSD,M5: 1.35406 Bullish Engulfing Candle  and bullsize = 0.00076
2014.10.01 12:41:43.260    2013.11.06 10:37  functiontest EURUSD,M5: 1.35406 Bullish Engulfing Candle  and bullsize = 0.00076
2014.10.01 12:41:43.260    2013.11.06 10:37  functiontest EURUSD,M5: 1.35406 Bullish Engulfing Candle  and bullsize = 0.00076
2014.10.01 12:41:43.260    2013.11.06 10:37  functiontest EURUSD,M5: 1.35406 Bullish Engulfing Candle  and bullsize = 0.00076
2014.10.01 12:41:43.260    2013.11.06 10:37  functiontest EURUSD,M5: 1.35406 Bullish Engulfing Candle  and bullsize = 0.00076
2014.10.01 12:41:43.260    2013.11.06 10:37  functiontest EURUSD,M5: 1.35406 Bullish Engulfing Candle  and bullsize = 0.00076
2014.10.01 12:41:43.260    2013.11.06 10:37  functiontest EURUSD,M5: 1.35406 Bullish Engulfing Candle  and bullsize = 0.00076
2014.10.01 12:41:42.030    TestGenerator: unmatched data error (volume limit 47 at 2013.12.11 18:35 exceeded)
2014.10.01 12:41:39.550    TestGenerator: current spread 12 used
2014.10.01 12:41:39.550    Expert functiontest EURUSD,M5: loaded successfully
2014.10.01 12:41:39.550    Expert functiontest EURUSD,M5: removed


Here is my new edits
I thought I had the per bar subject worked out but still getting multiple printouts

//+------------------------------------------------------------------+
//|                                                 functiontest.mq4 |
//|                                                 testing code     |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "You know not what you are doing"
#property link      "http:www.me_no_like_your_code.com"
#property version   "1.00"
#property strict
extern double bullsize=0.5; //5 digits means 5 pips bullish candle

bool macdup()
   {
      if(faster > slower)
         {
         Print(" MACD UP");
         return(true);
         }
      else
      Print(" No Up Signal");
      return(false);
    //return(true);  
   }
   
   
bool macddown()
   {
      if(faster < slower)
         {
         Print(" MACD DOWN");
         return(true);
         }
      else
      Print(" No Down Signal");
      return(false);
   }   

bool bullishengulfing() //Bullish Engulfing Candle
   {
      if(Open[2] > Close[2]        //bear candle identified
            && Open[1] < Close[1]  //bull candle identified
            && Open[1] <= Close[2]  //bull engulfing condition
            && Open[2] < Close[1]) //open of previous bear lower then bull close = engulfing condition    
               {
               Print(Close[1], " Bullish Engulfing Candle ", " and bullsize = ",DoubleToStr(Close[1] - Open[1],Digits));  //DoubleToStr( Close[1]-Open[1],Digits) forums help
               return(true);
               }
       else
       Print(" No Bullish Engulfing Candle Found");
       return(false);        
       
    }

bool bearishengulfing() //Bearish Engulfing Candle
   {
      if(Open[2] < Close[2]     //bull candle identified
            && Open[1] > Close[1]  //bear candle identified
            && Open[1] >= Close[2]  //bear engulfing condition
            && Open[2] > Close[1]) //bear engulfing condition
               {
               Print (Close[1], " Bearish Engulfing Candle "); 
               return(true);
               }
      else
      Print (" No Bearish Engulfing Candle Found");
      return(false);
    }

//+------------------------------------------------------------------+
//| Writing variables below my functions                             |
//+------------------------------------------------------------------+

bool bulls;
double      faster = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,3), //MODE_MAIN
            slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,3); //MODE_SIGNAL


//++++ These are adjusted for 5 digit brokers.

int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150

    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

int OnInit()
  {
  
   if (Digits == 5 || Digits == 3)   //Digits reads how many digits my broker has
      {    // Adjust for five (5) digit brokers.
         pips2dbl    = Point*10; pips2points = 10;  //Points converts the number to decimal tradeable number we use *10 for 5 digit
      } 
   else 
      {    
         pips2dbl    = Point;    pips2points =  1;
      }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
  
//---
 
//---
   return(INIT_SUCCEEDED);
  }
  
   
  
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }


int start()
   {
   static datetime Time0Last;
   if (Time0Last == Time[0])
      return(0); //return; use to work but now says function must return a value
   
   if(bullishengulfing())
      {
      //return;
      }
   else
   Time0Last = Time[0];
   return(0);
   
   }



//+------------------------------------------------------------------+
//NOTES:
//My attempt to make a function true and test the condition has failed
//I need to rethink this because the function call is always true and prints the else statement everytime.


   

Thanks for looking
 

The statement:

 if(function()) .. 

will only evaluate to true if function() returns true.

 

Also use OnTick() instead of start().. (possibly this will sort some probs)

Reason: