Discussion of article ""New Bar" Event Handler" - page 3

 
laplacianlab:

Good article, thanks for sharing! All that was very useful!

Anyway, I have taken your isNewBar function and it throws the following message when compiling: "possible loss of data due to type conversion".

So I have changed the var types from datetime to long this way:

Now it compiles without any notice and seems to work ok. Thank you!


It's probably clearer to change it this way :

   datetime lastbar_time=(datetime)SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE);
 

In the first way of requesting a new column line, I don't understand how the number of new columns can be directly assigned to 1. Please advise;

 //--- Check for new column lines.
   if(m_lastbar_time<newbar_time)       
     { 
      m_new_bars=1;               // Number of new column lines
      m_lastbar_time=newbar_time; // Remember the last bar time
      return(true);
     }
   //--- //--- Check for new column lines.
   if(m_lastbar_time<newbar_time)       
     { 
      m_new_bars=1;               // Number of new column lines
      m_lastbar_time=newbar_time; // Remember the last bar time
      return(true);
     }
   //---
 

According to the rules of object modelling, it's a misnomer to call it CIsNewBar.

Let's see, if car is a class I can create/have a car object. However, if my class is "ÉUmCarroNovo", we can have or own an "ÉUmCarroNovo".

The author should have called it CNewBarChecker. Someone could invent a New Car Checker and create it (our class would be NewCarChecker.

 
You don't use Time, you use Bars
 
There are so many code variations in the article, but in the end it is still not clear, what function is more correct to use on MT4 to increase at least a little bit the correspondence of what the tester draws with the trade. Give me a hint!
 
Pavel Komarovsky:
There are so many code variations in the article, but in the end it is still not clear, what function is more correct to use on MT4 to increase at least a little bit the correspondence of what the tester draws with the trade. Give me a hint!
datetime counted_bar = 0;

int OnInit()
{
   counted_bar = 0; // if you want the last bar to be analysed on restart
   ...

void OnTick()
{
   // If there is a new bar
   if ( iTime( _Symbol, _Period, 0 ) > counted_bar )
   {
      counted_bar = iTime( _Symbol, _Period, 0 );

      // Analyse indicators
      ...
   }
 
Andrey Khatimlianskii:

Andrey, thank you. Tell me why iTime is used now, earlier I remember in all functions and examples, most of them were based on iBars.

DoesiTime work more accurately?

 
Pavel Komarovsky:

Andrey, thank you. Tell me why iTime is used now, earlier I remember in all functions and examples, most of them were based on iBars.

DoesiTime work more accurately?

I have never used iBars for this purpose, I don't know.
 
I wonder why this example cannot get the timeseries data? Copy... always -1 and Bars() always 0. I.e. No access to data from the class
 

This article is so good that it is even used in MQL5 programming classes, including comments and collaborations and bug fixes. Congratulations to all of you.