Indicate a new bar - page 4

 
Donald Gibson:

Enhanced-MQL4 ?

Never heard of that. 


Me neither since yesterday ;) And the correct name seems to be "Updated MQL4". MQ writes:

(..) Starting from build 600, MQL4 programming language has been completely revised reaching the level of MQL5 - now you can develop trading robots in MQL4/5 using the unified MetaEditor development environment, single style, libraries and debugging tools.

(...) Therefore, we decided to implement in it the maximum possible amount of MQL5 language functions and features fully preserving MQL4 functionality. In other words, all powerful MQL5 functions, including ООP and the native code compiler, will become available in MQL4. (...)

To achieve this, we have developed a unified compiler that automatically supports both MQL4 and MQL5 languages. (...) 

The problem in the definition is the word "languages". The language is MQL, same way as C++ is a language and Basic is a language. Updated-MQL4/MQL5 is are just platform specific mods of MQL, no more no less, whereby the comparison of (native) MQL4 and Updated-MQL4 is pretty much the same as with C and C++. And the migration of MQL4.com into MQL5.com just made the confusion perfect. As these postings show, the most people do not associate OOP with MQL4, same as I did. For me this was always MQL5 which supports both platforms, MT4 and MT5.

But anyway, it works pretty fine and MQLWhatever is far the best interface in comparison to all the other crappy stuff around.  

 

@Lorentzos Roussos

Alain can correct me on this but you may find gaps in instances where on the time horizon of a bar there where no ticks , so no bar will be in place

Upppsss ... I haven't seen such a gab. (Which doesn't mean anything).

I use my "NewBar-indicator"  to pull the stopps automatically on the high or low of the previous bar.

(In fact, it's is a little more difficult, as I consider "Innenstaebe and Aussenstaebe" (eng. "inside and outside movements"   ???).  No idea what the correct translation is.

But I am going to use this only in liquid markets which have at least twenty - up to some hundred ticks per minute.

I don't think I will find a periode of ten minutes without any tick.

Anyway, the program should be able to handles this.

Thanks!

Willbur

 
Willbur:

@Lorentzos Roussos

Upppsss ... I haven't seen such a gab. (Which doesn't mean anything).

I use my "NewBar-indicator"  to pull the stopps automatically on the high or low of the previous bar.

(In fact, it's is a little more difficult, as I consider "Innenstaebe and Aussenstaebe" (eng. "inside and outside movements"   ???).  No idea what the correct translation is.

But I am going to use this only in liquid markets which have at least twenty - up to some hundred ticks per minute.

I don't think I will find a periode of ten minutes without any tick.

Anyway, the program should be able to handles this.

Thanks!

Willbur

you are using iTime , if there is no new bar it wont fire anyway.you are safe 
 
you are using iTime , if there is no new bar it wont fire anyway.you are safe

What do you mean by "You are using iTime"?   I understood "iTime" is just a variable in your program - you can name it "Bert" or "Clarly" if you want to ?!?

- - - - -

Today I did some tests. And I found some of the gaps you mentioned.

e.g. S&P500 at 20:34 there is a bar, for 20:35 and 20:36 I got no ticks and no bars from the server (ActiveTrades). Next ticks arrived at 20:37.

Subsequently there are no bars in the chart for this periods.  (see attached M1 chart)

I didn't check, but I think there are also no bars within the CopyRates() function for this time.



I think, you should check your code at this point.

I would guess, it's going to indicate the three first tick of the 20:37 bar as new bars.

(TimeCurrent() jumps from 20:34 to 20:37 !   You need to add PeriodeSeconds()  three times to get there).

void OnTick()  
{
//---   if(TimeCurrent()>=projection)   
    {Print("New Bar "+TimeToString(projection,TIME_DATE|TIME_MINUTES));   
     projection=projection+PeriodSeconds();   
    }

Willbur


 

Hello all,

In case anyone is still looking...here's a snipet from my code to ensure that only one trade is opened per bar.

  if (iBars(Symbol(),0) == BarsCurr)DisableTrading = 1;
  
  for(i=0;i<OrdersTotal();i++)
  {
  if (OrderSelect (i,SELECT_BY_POS,MODE_TRADES) == True && OrderMagicNumber() == MagicNumber) DisableTrading = 1;
  }

  for(i=OrdersTotal();i>0;i--)
  {
  if (OrderSelect (i,SELECT_BY_POS,MODE_HISTORY) == True && OrderMagicNumber() == MagicNumber)
  {
  if ((OrderClosePrice() >= Open[0] && OrderClosePrice() <= Close[0]) && (OrderOpenPrice() >= Open[0] && OrderOpenPrice()<= Close[0]))
  {
  DisableTrading = 1;
  }
   }
      }

The ibars can be replaced with bars and the disabletrading = 1 means don't do anything. The bars part can be further understood using what is posted normally. Put BarsCurr = 0 at the initialization part and BarsCurr = Bars at the buy/sell order part of your code.

I do have a problem though, i'm trying to implement close order by signal reversal...any ideas?

 

Since the debate on the recognition of NewBars has become a little longer, I will summarize the results shortly.

Technical environment:

If a change (new trade or new price determination) is detected by the server, the server sends a signal to the terminal. The terminal program triggers the OnTick () routine.

With this signal we get the following information:

Time Current () - the server time when the tick has been sent.

Information about the last tick - SymbolInfoTick()
• Server time when the tick has arisen
• Ask
• Bid
• Last Price (not with all providers)
• a flag that indicates what was changed.

Information about the current bar
– CopyRates()
• "name" for the bar e.g. "10:20:00".
• Open-High-Low-Close

Recognizing a new bars (e. g. Period = M1)

Because the server only sends a signal if something has changed,
the bars with the name “hh.mm:00” may apprear later than “hh:mm:00”

This may cause special situations for symbols with little liquidity.

Solutions dealing with the period’s duration don’t detect this:

               TimeCurrent()    bars “name”
Last Tick    10:10:07          10.10:00
Next Tick    10:11:30          10:11:00

Nether with that (Zero ticks in a period):

              TimeCurrent()          bars “name”
Last Tick    10:10:30          10:10:00
Next Tick   10:13:40           10:13:00  The 10:12:00 bar is missing!

Very rarely I saw situations (during very high load on the server?)  in which the server time is already switched into the next period while the bars isn’t.

             TimeCurrent()          bars “name”
Last Tick    10:10:00                10:09:00
Next Tick    10:10:00               10:10:00

Conclusion:

It’s ok to go with the TimeCurrent() in order to suppress  unnecessary CopyRates().

Ones the TimeCurent() reaches the new period one has to check whether the bar is also switches over.

This brings me back to code Alain brought into discussion very early:

https://www.mql5.com/en/forum/22983

Willbur

Improve your time execution by removing Bars function calls
Improve your time execution by removing Bars function calls
  • www.mql5.com
After a basic profiling I get the following results :.
 

@emeka Mbanefo

my manual doesn't mention a function named "iBars".

Are yousure this is MQL5 code?

Willbur

 
Willbur:

@emeka Mbanefo

my manual doesn't mention a function named "iBars".

Are yousure this is MQL5 code?

Willbur

Ah, its not for mql5. it's for mql4, i think. Still, the iBars is me playing around. Its Bars as a general function, as i've previously stated.

Still waiting for assistance with the signal reversal code.

Thanks.

 
emeka Mbanefo:

Ah, its not for mql5. it's for mql4, i think. Still, the iBars is me playing around. Its Bars as a general function, as i've previously stated.

Still waiting for assistance with the signal reversal code.

Thanks.

  • Please don't hijack other topic with unrelated content.
  • This topic is about mql5, as already stated.
  • This topic is about detecting new bar, not trading only once per bar.
  • iBars is unreliable to detect new bar.
Indicate a new bar
Indicate a new bar
  • www.mql5.com
Another idea could be the check wether the number of bars has been incremented.
Reason: