Download MetaTrader 5

Help me fix an alert

To add comments, please log in or register
paul.doberan
23
paul.doberan  

I am trying to include an alert into an inside bar indicator but I can't get it to work.

I do get an alert, (which is what I am focusing on right now). There are also no errors in the compiler. 

However, what I want to achieve:

  • Get an alert for every new (closed) inside bar.

What I get:

  • An alert for every new bar that is starting. (5M - every 5min an alert for an inside bar)


What I assume is that since a new bar always starts as an inside bar this prompts the alert. What I don't get is that I am using HighBuffer[1] so it should focus only on the second candle not the current.

Also it could be that the Buffer is drawn to a candle while it is in the current state. However, since I am using HighBuffer[1] not HighBuffer[0] I don't see why this should matter. 

It could be another problem I don't see, because I'm not so familiar with programming.

As I understand the code, a candle that is not an inside bar gets a value of EMPTY_VALUE and the test HighBuffer[1] > 0 should not execute the if statement (alert). Somehow it does.


input int    TriggerCandle 	= 1;
input bool   EnableNativeAlerts = true;
input bool   EnableSoundAlerts  = true;
input bool   EnableEmailAlerts  = true;
input string AlertEmailSubject  = "";
input string AlertText  	= "";
input string SoundFileName	= "alert.wav";
 
datetime LastAlertTime = D'01.01.1970';


//At the end of the onCalculate function

if ((TriggerCandle > 0) && (Time[0] > LastAlertTime))
{
	string Text;
	
	if (HighBuff[TriggerCandle] > 0)
	{
		Text = AlertText + "Inside Bar: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period());
		if (EnableNativeAlerts) Alert(Text);
		if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Inside Bar", Text);
		if (EnableSoundAlerts) PlaySound(SoundFileName);
		LastAlertTime = Time[0];
	}

}

This is the code I was using.


The indicator I am using is from Tecciztecatl's inside bar indicator.

https://www.mql5.com/en/code/16533


I hope someone can help

Best,

Paul

Inside Bar
Inside Bar
  • votes: 13
  • 2016.10.13
  • Taras Slobodyanik
  • www.mql5.com
The indicator determines the inside bar and marks its High/Low. It is plotted based on the closed candles (does not redraw). The identified inside bar can be displayed on smaller periods. You may set a higher period (to search for the inside bar) and analyze on a smaller one.
Jose Francisco Casado Fernandez
4648
Jose Francisco Casado Fernandez  
paul.doberan:

As I understand the code, a candle that is not an inside bar gets a value of EMPTY_VALUE and the test HighBuffer[1] > 0 should not execute the if statement (alert).  <---------  No, this is wrong.

if (HighBuff[TriggerCandle] > 0)
        {
          //==========

        }



In mql4, EMPTY_VALUE = 2147483647  ( =  INT_MAX,  that is, the maximal value, which can be represented by an int type variable).  Obviously this value is greater than zero.


EMPTY_VALUE

Empty value in an indicator buffer. Default custom indicator empty value

2147483647 (0x7FFFFFFF)


Source Link:  https://docs.mql4.com/constants/namedconstants/otherconstants


Therefore, your condition will always be true (HighBuff[1]  is always > 0, since, if it takes some other value, normally this value will be greater than 0, and if it takes the EMPTY_VALUE, it is also greater than 0) ,  that is why it always produces the alert. 

You could change your condition to something like this:


if (HighBuff[TriggerCandle] < EMPTY_VALUE)
        {
          //==========

        }


Regards.

Other constants - Named Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
Other constants - Named Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
Used with array functions. Indicates that all array elements will be processed. Means the number of items remaining until the end of the array, i.e., the entire array will be processed The NULL constant can be assigned to a variable of any simple type or to an object structure or class pointer. The NULL assignment for a string variable means...
paul.doberan
23
paul.doberan  

Thank you I have written it again and it seems to work.

Jose Francisco Casado Fernandez
4648
Jose Francisco Casado Fernandez  
paul.doberan:

Thank you I have written it again and it seems to work.

You are welcome. Regards.
To add comments, please log in or register