Only once per bar unwanted delay

 

Hi, could you please help me with my notification EA? After action on B1 (call it for example actionBar), should send me an email about it on the current bar B0, but it send it with one bar delay. 


This is how it shloud do: if(B1 == actionBar){SendMail();} => actionBar is actualy B1 and send it on B0 current time

but it is sending mail when actionBar is already B2, so there is a one bar delay.


This is simplified code:

//--

int BarCount = 0;

int start()

{


int Bars = iBars(Symbol(), PERIOD_CURRENT);

if(BarCount != Bars)

{ 
if(B1 == actionBar) {SendMail();}

}

BarCount = Bars;

return(0);

}

//--

I think it's okay, but it's not.

Thank You for your answers.

 
FrKal: , should send me an email about it on the current bar B0, but it send it with one bar delay.
  1. Please use
SRC
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 forum.) Always use time.

    I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
    New candle - MQL4 forum

  3. You can use the last completed candle, which is what you are currently doing. There is no delay.
  4. Or, you can use the forming candle and expect false signals and multiple signals. Your choice.
 
whroeder1:
  1. Please edit your post.

Thanks.


whroeder1:
  1. Always use time.

    I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
    New candle - MQL4 forum

  2. You can use the last completed candle, which is what you are currently doing. There is no delay.
  3. Or, you can use the forming candle and expect false signals and multiple signals. Your choice.

I agree with you, but how to send only one message if I told the EA to send it in first minute in hour for example? EA in one minute will send me multiple signals.

Yes, last completed candle is fine but there is multiple signals problem again. How to send it only once?


Thank you whroeder1.

 

whroeder1:

Always use time. 


Heh.... so instead of iBar use iTime, right?

//--

int TimeCount = 0;

int start()

{


int TimeNow = iTime(Symbol(), PERIOD_CURRENT, 0);

if(TimeCount != TimeNow)

{ 
if(B1 == actionBar) {SendMail();}

}

TimeCount = TimeNow;

return(0);

}

//--

?? :)

 

Well.. in tester works even the old one ("iBar") version. But on demo account in real one bar delay again. I really don't understand. I've put Print() to a sendMail function and will see if there will be delay too...

 
What delay? When the bar closes (was bar zero now bar 1) you see the signal and do whatever on the first tick of the new bar zero. There is no delay and until you get that first tick, there isn't yet a new bar.
 
whroeder1:
What delay? When the bar closes (was bar zero now bar 1) you see the signal and do whatever on the first tick of the new bar zero. There is no delay and until you get that first tick, there isn't yet a new bar.

Hi,

yes, logic of code i right but there was a delay. I rewrote the code and it seems to work now so probably some syntax glitch. But thank you very much!

Can I have one more question off topic please? My notification EA aut. changing symbols  by market watch (true). I deleted approx. 50 stock instruments but last 6 I can't deleted (HP, IBM, Intel, Microsoft, AT&T, Exxon mob.). Not working "delete" from terminal neither CTRL+U and "Hide". Just wan't go away. Do you known the issue?

 
FrKal:

yes, logic of code i right but there was a delay. I rewrote the code and it seems to work now so probably some syntax glitch. But thank you very much!


Well, I thought I had solved it, but not. EA checks 30 instruments and if send approx. 7 notifications per H1 bar then 2 of it has a delay. For each instrument, of course, the same rules apply. Logic is the same, only symbol is changing.


Can I have one more question off topic please? My notification EA aut. changing symbols  by market watch (true). I deleted approx. 50 stock instruments but last 6 I can't deleted (HP, IBM, Intel, Microsoft, AT&T, Exxon mob.). Not working "delete" from terminal neither CTRL+U and "Hide". Just wan't go away. Do you known the issue?

Solved. The stocks probably cache somewhere even I do not used them. I shutdown the charts where was running my "EA changing symbols", shutdown the MT4 a then run again. Then it can be deleted. Source (even I have not open - no positions, orders or charts):

Attention: If there are open positions or pending orders for the symbol, or its chart is open, the symbol cannot be deleted.

Trading - MetaTrader 4 Help
Trading - MetaTrader 4 Help
  • www.metatrader4.com
The fundamental and simple rule of profitable trading at financial markets is to buy cheaper and sell dearer. Thus, the entire trading activities...
Reason: