Download MetaTrader 5

new bar formed?

To add comments, please log in or register
chris
51
chris  

Hello,


How we know when a new bar is formed, please?


It's because I would want to stop analyse, trade...ets when something happened in the last bar.


Regards

Chris

Brian Dee - Random Trader
1759
Brian Dee - Random Trader  

W

> How we know when a new bar is formed

When the current bar gives its first tick

You can detect this with

...

if (Volume[0]==1) 
 {
   // First tick is here so do stuff for new bar



 }

...

Good Luck

-BB-

chris
51
chris  
BarrowBoy:

W

> How we know when a new bar is formed

When the current bar gives its first tick

You can detect this with

...

...

Good Luck

-BB-

Thanks BarrowBoy

Justin Abene
203
Justin Abene  

you could also:



int barsTotal = 0;

int start()
{
   if(Bars > barsTotal){
      //...do stuff..;
      barsTotal = Bars;
   }
}
chris
51
chris  
jmca:

you could also:



I do that in first and I would be sure if something like newBarFormed exists?

also thanks

Chris

Vlad Dinu
54
Vlad Dinu  
jmca:

you could also:




i like this better somehow closer to my style.

Thx

Vlad Dinu
54
Vlad Dinu  
onemore:


i like this better somehow closer to my style.

Thx


but both versions show a new bar even when the price of the current bar changes direction, any reason why?
Dan
4
Dan  

How about:

datetime lastBarOpenTime;
bool IsNewBar()
{
datetime thisBarOpenTime = Time[0];
if(thisBarOpenTime != lastBarOpenTime)
{
lastBarOpenTime = thisBarOpenTime;
return (true);
}
else
return (false);
}

whroeder1
14785
whroeder1  
Bars is unreliable (doesn't change once you reach max bars in chart) Volume is unreliable (you can miss ticks) Always use time.
start(){
   static datetime Time0; if (Time0 == Time[0]) return; Time0 = Time[0];
   ...
Brian Dee - Random Trader
1759
Brian Dee - Random Trader  

Gosh, this is an old topic!

> Always use time..

Is the right answer

-BB-

maindoor
120
maindoor  
BarrowBoy:

Gosh, this is an old topic!

> Always use time..

Is the right answer

-BB-


  Is time really that reliable ?

  The granularity of Time[0] is in seconds, so if

  within the first second you get two ticks, it would

  count as two newbars. :/

123
To add comments, please log in or register