What is wrong with this code?

 

I have the following code below, but i cannot get to work. Can anyone see what's wrong?

Everytime we have a new bar i want an alert to pop up if it's an inside bar, but it pop up evertime we have a new bar and not only when we have aninside bar.

//+------------------------------------------------------------------+
//|                                                    Insidebar.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_chart_window

datetime LastAlertTime;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
   LastAlertTime = TimeCurrent();
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
//----
   
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   if (LastAlertTime < Time[0])
   {
      // Check if we have an inside bar
      if (High[0] <= High[1] && Low[0] >= Low[1])
      {
         Alert("We have an inside bar ",Symbol());
         LastAlertTime = Time[0];
      }
   }
   return(0);
}
//+------------------------------------------------------------------+
 

u shouldn't use current bar high low compare with previous bar, because every time new bar start, open is = high or low, so if compare with previous bar, it is equal with previous close, so still within previous high/low.

use

if (High[1] <= High[2] && Low[1] >= Low[2])
 
mancai:

u shouldn't use current bar high low compare with previous bar, because every time new bar start, open is = high or low, so if compare with previous bar, it is equal with previous close, so still within previous high/low.

use

YES! Why haven't i thougt of that before?

But it still comes up sometimes saying that it's an inside even that it's not.

I will test it on M5 chart and see if it works correctly.

Thanks mancai.

 

No it doesn't work.

It pops up when a new bar is on the screen.

What else can be the problem?

 
EagleEye:

No it doesn't work.

It pops up when a new bar is on the screen.

What else can be the problem?


just now i try on GJ M1 is working, it will prompt alert after inside bar formed, but when i try on GU and GJ, when only GJ formed inside bar, alert show both GU and GJ.

 
mancai:


just now i try on GJ M1 is working, it will prompt alert after inside bar formed, but when i try on GU and GJ, when only GJ formed inside bar, alert show both GU and GJ.


my mistake, code working, u modify and recompile again or change filename and makesure u detached all previous version insidebar.mq4 from charts, I observed so many bar, it only prompt when inside bar formed :)

 
mancai:

just now i try on GJ M1 is working, it will prompt alert after inside bar formed, but when i try on GU and GJ, when only GJ formed inside bar, alert show both GU and GJ.


It doesn't work for me. It keeps popping up when it see an inside bar. And some other problems as well.

 


my screenshot, for your reference

 

Yeah i look great, but i have just tried it again and it keeps popping up even when there no inside bar.

 
EagleEye:

Yeah i look great, but i have just tried it again and it keeps popping up even when there no inside bar.


I didn't encounter this problem, maybe u close all chart, reopen MT4, open all charts and re-attach modified inside_bar.mq4

if u are using vista or windows 7, makesure your indicator only in compatibility files, if u found the same indicator not in compatibility files, just remove it :)

//+------------------------------------------------------------------+
//| Insidebar.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""

#property indicator_chart_window

datetime LastAlertTime;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
LastAlertTime = TimeCurrent();
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if (LastAlertTime < Time[0])
{
// Check if we have an inside bar
if (High[1] <= High[2] && Low[1] >= Low[2])
{
Alert("We have an inside bar ",Symbol());
LastAlertTime = Time[0];
}
}
return(0);
}
//+------------------------------------------------------------------+

 

The when and where you update the LastAlertTime is wrong use.

//+------------------------------------------------------------------+
//| Insidebar.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""

#property indicator_chart_window

datetime LastAlertTime;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
LastAlertTime = TimeCurrent();
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if (LastAlertTime < Time[0])
  {
   LastAlertTime = Time[0];

   // Check if we have an inside bar
   if (High[1] <= High[2] && Low[1] >= Low[2])
     {
      Alert("We have an inside bar ",Symbol());
     }
  }
return(0);
}
//+------------------------------------------------------------------+
Reason: