Date error in MT4?

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
1213
ggekko 2016.04.10 18:09 #
 
FMIC:

Since you are obviously afraid of showing your code, use my code example (see the script above) as the test code and then give use the results of that code.

Save it as "YearTest.mq4" and place it in the "Scripts" folder and run it against a EUR/USD H1 chart just as I have. It will then serve as the comparison between our two respective systems.

I've already done it, before you did. The script worked fine for me too.

Dear FMIC, please forget my question, I will do it myself later.

Thank you for your time! Cheers

avatar
1197
FMIC 2016.04.10 18:12 #
 
ggekko:

Dear FMIC, I'm not a beginner, please consider this.

I am not trying to treat you as a beginner, but since you supplied no other information about yourself or the test environment, I could not possible know that, and that is why I had to ask many questions.

Please recreate the test conditions using my Test script and provide us with the results and log entries please!

avatar
1197
FMIC 2016.04.10 18:15 #
 
ggekko:
I've already done it, before you did. The script worked fine for me too.

Then, why did you not tell us that? Why hide the information if you want use to help you?

OK! Then, my next point is a suspicion that I have about it being an Indicator!

Where is it being executed? Is it in the OnInit() or the OnCalculate() functions?

What is the earliest date of the chart data to which you are attaching the indicator code?

avatar
1213
ggekko 2016.04.10 18:23 #
 
FMIC:

Then, why did you not tell us that? Why hide the information if you want use to help you?

OK! Then, my next point is a suspicion that I have about it being an Indicator!

Where is it being executed? Is it in the OnInit() or the OnCalculate() functions?

What is the earliest date of the chart data to which you are attaching the indicator code?

You missed my edited earlier post:

"Dear FMIC, please forget my question, I will do it myself later.

Thank you for your time! Cheers

"

Again, thank you! Your help intention is really appreciated!

avatar
1197
FMIC 2016.04.10 18:34 #
 

@ggekko: You may no longer be online, but here is the information for anyone else who is interested!

I have recreated the problem. It seems that the Year() function (and possibly other time/date functions) when first used in the Indicator when first attached to a chart, it returns a value of 1900. Only with subsequent use or when you change the time frame, it then always returns the correct value.

In essence this most probably is a bug that needs to be reported to MetaQuotes. I leave that up to @ggekko to do!

This is the test code I used, and you will notice when first used that the Buffer Label and first data points are set to 1900, but when you change the chart time-frame (effectively recalculating) you then get the correct year:

#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

double         YearBuffer[];

int OnInit()
{
   SetIndexBuffer(0,YearBuffer);
   
   string strYear = StringConcatenate( "Year: ", Year());
   IndicatorShortName( strYear );
   SetIndexLabel( 0, strYear );
      
   return(INIT_SUCCEEDED);
}

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[])
{
   ArraySetAsSeries( YearBuffer, false );
   
   int
      intYear = Year(),
      intLimit = ( prev_calculated == 0 ) ? 0 : prev_calculated - 1;
   
   for( int i = intLimit; i < rates_total; i++ )
      YearBuffer[ i ] = (double) intYear;

   return(rates_total);
}
Back to topics list   | 1 2  

To add comments, please log in or register