Alert question

intraforex

Active Trader
Jan 6, 2010
21
0
42
italy
On MT4 I had the code for trigger "alert once on the bar current":

static bool TriggerOnlyThisBar;

...............

...............

if (......trigger condition......) && TriggerOnlyThisBar!=Bars
{
Alert(Symbol()," TEST ");
TriggerOnlyThisBar = Bars;
}


on mt5 I have replaced Bars (MT4) with Bars (symbol (), period_current) but does not work.

Someone explains to me where it is error?

Thanks to all.
 

intraforex

Active Trader
Jan 6, 2010
21
0
42
italy
What? Does it continue to trigger the alert without the new bar coming?
Exact.The alarm should be triggered only the first time there is the bar that is forming.
Example:
bar 5 minutes
trigger alarm at second minute
stop alarm until 5 minutes even if the signal comes back
...on MT4 working bat not in MT5:I do not understand ....
Can you help ?
 

intraforex

Active Trader
Jan 6, 2010
21
0
42
italy
Can you copy the exact code of that part of your indicator? Maybe there is some syntax typo that causes this error.

Yes.This is the code:
MQL5:
#property copyright "Copyright © 2009"
#property link      ""
#property version   ""
#property description ""
 
 
#property indicator_chart_window
#property indicator_buffers 1
double CCIBUFFER[];
 
static bool TriggerOnlyThisBar;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
{
 
//---- indicator buffers mapping  
   SetIndexBuffer(0, CCIBUFFER);
 
}
//+------------------------------------------------------------------+
//| Custom CCI Arrows                                                |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &High[],
                const double &Low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
int handle;
handle = iCCI(NULL, PERIOD_M5, 14, PRICE_CLOSE);
int buffer_num=BarsCalculated(handle);
CopyBuffer(handle,0,0,buffer_num,CCIBUFFER);
ArraySetAsSeries(CCIBUFFER,true);  
 
   {
 
         if((CCIBUFFER[0] > 0)&&
            (CCIBUFFER[1] < 0)&&
            TriggerOnlyThisBar != Bars(Symbol(),PERIOD_M5)) 
    {
      Alert(Symbol()," SIGNAL DOWN ");
       TriggerOnlyThisBar = Bars(Symbol(),PERIOD_M5);
    }     
   }
 
         if ((CCIBUFFER[0] < 0)&&
             (CCIBUFFER[1] > 0)&&
             TriggerOnlyThisBar != Bars(Symbol(),PERIOD_M5))     
    {
      Alert(Symbol(),"SIGNAL UP ");
       TriggerOnlyThisBar = Bars(Symbol(),PERIOD_M5);
        }
 
   return(rates_total);
}
 
Last edited by a moderator:

Enivid

Administrator
Staff member
Nov 30, 2008
18,619
1,366
144
Odesa
www.earnforex.com
You have an extra pair of "{}" in your code for some reason. But that's not the problem. The problem is that you don't take this condition - TriggerOnlyThisBar != Bars(Symbol(),PERIOD_M5) - in the brackets "()". Correct example:

MQL5:
if((CCIBUFFER[0] > 0)&&
            (CCIBUFFER[1] < 0)&&
            (TriggerOnlyThisBar != Bars(Symbol(),PERIOD_M5)))
 
Last edited:

intraforex

Active Trader
Jan 6, 2010
21
0
42
italy
You have an extra pair of "{}" in your code for some reason. But that's not the problem. The problem is that you don't take this condition - TriggerOnlyThisBar != Bars(Symbol(),PERIOD_M5) - in the brackets "()". Correct example:

MQL5:
if((CCIBUFFER[0] > 0)&&
            (CCIBUFFER[1] < 0)&&
            (TriggerOnlyThisBar != Bars(Symbol(),PERIOD_M5)))

Enivid : you have tested the code ?
I do not work: the alarm continues to play until the completion of the bar....
 
Last edited by a moderator:

Enivid

Administrator
Staff member
Nov 30, 2008
18,619
1,366
144
Odesa
www.earnforex.com
Enivid : you have tested the code ?
I do not work: the alarm continues to play until the completion of the bar....
Do you use it on M5?

EDIT: I've found the real problem :). It shouldn't be bool. Make it int or long. And remove static, it's not needed if you declare it as a global variable.
 

intraforex

Active Trader
Jan 6, 2010
21
0
42
italy
Do you use it on M5?

EDIT: I've found the real problem :). It shouldn't be bool. Make it int or long. And remove static, it's not needed if you declare it as a global variable.
thanks Enivid ... Monday I'll try your changes and then I tell you if it works.
 

intraforex

Active Trader
Jan 6, 2010
21
0
42
italy
I have modify the code:
MQL5:
#property indicator_chart_window
#property indicator_buffers 1
double CCIBUFFER[];
 
bool TriggerOnlyThisBar;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
{
 
//---- indicator buffers mapping  
   SetIndexBuffer(0, CCIBUFFER);
 
}
//+------------------------------------------------------------------+
//| Custom CCI Arrows                                                |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &High[],
                const double &Low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
int handle;
handle = iCCI(NULL, PERIOD_M3, 14, PRICE_CLOSE);
int buffer_num=BarsCalculated(handle);
CopyBuffer(handle,0,0,buffer_num,CCIBUFFER);
ArraySetAsSeries(CCIBUFFER,true);  
 
  if((CCIBUFFER[0] > 0)&&
     (CCIBUFFER[1] < 0)&&
     (TriggerOnlyThisBar != Bars(Symbol(),PERIOD_M3)));
      {      
      Alert(Symbol()," UP ");
       TriggerOnlyThisBar = Bars(Symbol(),PERIOD_M3);
      }     
 
   if((CCIBUFFER[0] < 0)&&
      (CCIBUFFER[1] > 0)&&
      (TriggerOnlyThisBar != Bars(Symbol(),PERIOD_M3))) 
      {
      Alert(Symbol()," DOWN ");
       TriggerOnlyThisBar = Bars(Symbol(),PERIOD_M3);
      }
   return(rates_total);
}
....but still sounds alarm continuous incessant on the all bar of trigger :(
 
Last edited by a moderator:

intraforex

Active Trader
Jan 6, 2010
21
0
42
italy
Because it's still bool. Make it int or long:
MQL5:
int TriggerOnlyThisBar;
Good.... with "int" seems to work. :)
But he appeared another problem.
Example: sounds the alarm on EURUSD 5 Minutes, I go to see, then I moving on 10 minutes (always EURUSD) and the alarm still plays. Why?
I have replaced:
MQL5:
(TriggerOnlyThisBar != Bars(Symbol(),PERIOD_M5)))
with
MQL5:
(TriggerOnlyThisBar != Bars(Symbol(),PERIOD_CURRENT)))
but the problem remains
Thanks Enivid
 
Last edited by a moderator: