new bar higher high

 

hi guys,

I am stumped here... I am trying to get an alert when the new bars high is higher than the last bars high or the low lower than the last bars low...

I have tried to do it like this... (it doesnt work...any ideas why? ) im running it on a 5min chart to test it


//+------------------------------------------------------------------+
//|                                                    MB_TESTER.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

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


   double high = High[1];
   double low = Low[1];


   if(NewBar()==true&&Ask<=low) // add day_allowed still to this code
     {  
   Alert("LOWER");
      }
 
    if(NewBar()==true&&Bid>=high)
     {
    Alert("HIGHER");  
     }     
//----
   return(0);
  }
//+------------------------------------------------------------------+
bool NewBar()
{
//////////////////////////
   static datetime lastbar = 0;
   datetime curbar = iTime(NULL,PERIOD_M5,0);
   if(lastbar!=curbar)
   {
      lastbar=curbar;
      return (true);
   }
   else
   {
      return(false);
   }
/////////////////////////
}

 
What does the NewBar function do for you ? (that is a clue . . . )
 

so the newbar function is preventing the ea from alerting me? but i only want to be alerted once per bar... thanx for the tip...ill go look for ways to alert only once per bar instead of using the new bar function.

 
mqlearner:

so the newbar function is preventing the ea from alerting me? but i only want to be alerted once per bar... thanx for the tip...ill go look for ways to alert only once per bar instead of using the new bar function.


Yep, exactly . . .

Set a global variable to true when a new bar forms, if the condition occurs when you want to sound the alert check if the variable is true, if it is perform the alert and set the variable false . . . repeat.

 
Call newbar ONLY once, the second call will ALWAYS return false.
Reason: