Hi Guys,
Can someone please help me with this.
When the condition is met for the Alert to popup it keeps on popping up every few seconds for the period of the bar. I run this on one hour charts but it keeps on forcing the alert window to pop up.
Also, if I can stop it popping up (so I am only notified once) does the alert reset so if it is triggered in 3 bars time if the condition is true again.
If anyone is able to help I would appreciate it.
Regards
Steve
//+------------------------------------------------------------------+
//| My_First_Indicator.mq4 |
//| http://www.forex-tsd.com |
//+------------------------------------------------------------------+
#property copyright "Steve Dawson"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Green
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
bool buf_alert_already_triggered;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,3);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,3);
SetIndexBuffer(1,ExtMapBuffer2);
string short_name = "MAX - OBOS Histogram with Alerts!";
IndicatorShortName(short_name);
return(1);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- check for possible errors
if (counted_bars<0) return(-1);
//---- last counted bar will be recounted
if (counted_bars>0) counted_bars--;
int pos=Bars-counted_bars;
double dVal , dLow , dResult,value;
Comment("Hi! I'm here on the main chart windows!");
//---- main calculation loop to load the ArrayBsearch
while(pos>=0)
{
dVal = iCustom(NULL,0,"J_TPO",13,0,pos);
if (dVal > 0)
{
dResult = 1;
}
else
{
dResult = -1;
}
//This is where the color is Set
if (dResult == 1)
{
ExtMapBuffer2[pos]= dResult;
}
else
{
ExtMapBuffer1[pos]= dResult;
}
//ExtMapBuffer1[pos]= dResult ;
pos = pos - 1;
}
//---- buffer is now loaded
// Do the alert thing now
if ((((ExtMapBuffer1[0] == 1) || (ExtMapBuffer2[0] == 1)) && ((ExtMapBuffer1[1] == -1) || (ExtMapBuffer2[1] == -1))) && (buf_alert_already_triggered == 0 ))
{
Alert("Possible BUY for ", Symbol(), " on ", Period(), " chart!");
buf_alert_already_triggered = 1;
} else
{
buf_alert_already_triggered = 0;
}
if ((((ExtMapBuffer1[0] == -1) || (ExtMapBuffer2[0] == -1)) && ((ExtMapBuffer1[1] == 1)) || (ExtMapBuffer2[1] == 1))&& (buf_alert_already_triggered == 0 ))
{
Alert("Possible SELL for ", Symbol(), " on ", Period(), " chart!");
buf_alert_already_triggered = 1;
} else
{
buf_alert_already_triggered = 0;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Can someone please help me with this.
When the condition is met for the Alert to popup it keeps on popping up every few seconds for the period of the bar. I run this on one hour charts but it keeps on forcing the alert window to pop up.
Also, if I can stop it popping up (so I am only notified once) does the alert reset so if it is triggered in 3 bars time if the condition is true again.
If anyone is able to help I would appreciate it.
Regards
Steve
//+------------------------------------------------------------------+
//| My_First_Indicator.mq4 |
//| http://www.forex-tsd.com |
//+------------------------------------------------------------------+
#property copyright "Steve Dawson"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Green
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
bool buf_alert_already_triggered;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,3);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,3);
SetIndexBuffer(1,ExtMapBuffer2);
string short_name = "MAX - OBOS Histogram with Alerts!";
IndicatorShortName(short_name);
return(1);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- check for possible errors
if (counted_bars<0) return(-1);
//---- last counted bar will be recounted
if (counted_bars>0) counted_bars--;
int pos=Bars-counted_bars;
double dVal , dLow , dResult,value;
Comment("Hi! I'm here on the main chart windows!");
//---- main calculation loop to load the ArrayBsearch
while(pos>=0)
{
dVal = iCustom(NULL,0,"J_TPO",13,0,pos);
if (dVal > 0)
{
dResult = 1;
}
else
{
dResult = -1;
}
//This is where the color is Set
if (dResult == 1)
{
ExtMapBuffer2[pos]= dResult;
}
else
{
ExtMapBuffer1[pos]= dResult;
}
//ExtMapBuffer1[pos]= dResult ;
pos = pos - 1;
}
//---- buffer is now loaded
// Do the alert thing now
if ((((ExtMapBuffer1[0] == 1) || (ExtMapBuffer2[0] == 1)) && ((ExtMapBuffer1[1] == -1) || (ExtMapBuffer2[1] == -1))) && (buf_alert_already_triggered == 0 ))
{
Alert("Possible BUY for ", Symbol(), " on ", Period(), " chart!");
buf_alert_already_triggered = 1;
} else
{
buf_alert_already_triggered = 0;
}
if ((((ExtMapBuffer1[0] == -1) || (ExtMapBuffer2[0] == -1)) && ((ExtMapBuffer1[1] == 1)) || (ExtMapBuffer2[1] == 1))&& (buf_alert_already_triggered == 0 ))
{
Alert("Possible SELL for ", Symbol(), " on ", Period(), " chart!");
buf_alert_already_triggered = 1;
} else
{
buf_alert_already_triggered = 0;
}
//----
return(0);
}
//+------------------------------------------------------------------+