Is this a bug?

To add comments, please log in or register
OneDay
115
OneDay  

I have recently developed a custom indicator that counts trading days and plots vertical lines at my prescribed intervals. Works fine within the processed bars, however, as soon as it starts plotting in the future - to the right of the current bar - it adds days?? The code that I use is simply a loop that counts the number of days that aren't Saturday or Sunday, so I am quite sure that there is not a problem with the code. That suggests that the future bars might be referenced in a different manner than those already processed....

So far, it seems that it adds either 4 or six days to the count so I am guessing that it is the future weekends causing my problem. Has anyone else encountered this issue?

bernd
989
bernd  

Not sure what you mean by "adds days" and also without seeing your code (post only the relevant lines, not 500 lines if irrelevant code) it is not easy to see what you are trying do do when you "count trading days".


The line takes an absolute date as a parameter (not "trading days" or something like that) and if you specify the exact date of next Tuesday then it will plot the line at exactly this date. You can either use the date and time functions to calculate the timestamp for next Tuesday by converting a string to a timestamp or you can simply add the number of seconds to some existing timestamp to arrive at some date in the future. To plot a line exactly one week from now you would calculate

TimeCurrent() + 7 * 24 * 60 * 60

OneDay
115
OneDay  
7bit:

Not sure what you mean by "adds days" and also without seeing your code (post only the relevant lines, not 500 lines if irrelevant code) it is not easy to see what you are trying do do when you "count trading days".


The line takes an absolute date as a parameter (not "trading days" or something like that) and if you specify the exact date of next Tuesday then it will plot the line at exactly this date. You can either use the date and time functions to calculate the timestamp for next Tuesday by converting a string to a timestamp or you can simply add the number of seconds to some existing timestamp to arrive at some date in the future. To plot a line exactly one week from now you would calculate

TimeCurrent() + 7 * 24 * 60 * 60


Thank you for your reply 7bit, unfortunately I do not have access to MT4 at the moment, so I'll have to include the code etc, later....

For now, maybe this will clarify:

Add days - I input a starting date and use the loop to cycle through each subsequent bar. If the bar is not a Saturday or Sunday, then I add 1 to my count of trade days. If this integer count has reached a particular value, then I perform the calculation necessary to convert to time and create a vertical line. The loop then continues on in the same manner.

If I were to compare it to a standard tool in MT4, I would say that it is similar to the cycle line tool. But, rather than be limited to the fixed spacing that you have with this tool, I can use my indicator to vary the spacing.

Why do I do this? Well, I don't want to include the Sunday bars that some brokers have in their data - it messes up the cycle!

Anyway, I'll reply later with the code etc.

Regards

OneDay
115
OneDay  

Hi 7bit,

Here is an excerpt from the code:

extern color     Line_colour=Gray;
extern datetime  Origin_date=D'2010.03.25 00:00';
extern string    Ind_Name="Example";

//-------------------------------------------------------------------
int init()
  {
//---- indicators

int Trade_days=0;

for(int count=1;count<=275;count++)
            {
               Origin_date += 86400;//add 1 day and check whether it is a trade day
               int weekday=TimeDayOfWeek(Origin_date);
                     if(weekday==1 || weekday==2 || weekday==3 || weekday==4 || weekday==5)Trade_days+= +1;
               
                     if(Trade_days==11)
                        {
                           ObjectCreate("11 days",OBJ_VLINE,0,Origin_date,0);
                           ObjectSetText("11 days","11 days",11,"Tahoma",Red);
                        }
                     if(Trade_days==22)
                        {
                           ObjectCreate("22 days",OBJ_VLINE,0,Origin_date,0);
                           ObjectSetText("22 days","22 days",11,"Tahoma",Red);
                        }

As I said, it works fine in the processed bars, but, adds in extra days to my count when it is creating the lines in the space to the right of the last bar. I assume that those bars to the right are not indexed in the same manner as those within the processed bars.

Here is an image to demonstrate my point:

I am hoping that as the processed bars catch up with the future vertical bars, they will adjust to the correct position.

Do you have any comments?

zzuegg
1505
zzuegg  

hi,

i assume your indicator works correct, the problem is that in history saturday (and for some brokers sunday) candles are alterd. in the future the daily candles are still there.

i.e. on my broker on the daily chart i have 5 candlse from monay to the next monday, but for the future there is space for 7 candles between monday and the next one. i hope you are getting my point.


//z

OneDay
115
OneDay  
zzuegg:

hi,

i assume your indicator works correct, the problem is that in history saturday (and for some brokers sunday) candles are alterd. in the future the daily candles are still there.

i.e. on my broker on the daily chart i have 5 candlse from monay to the next monday, but for the future there is space for 7 candles between monday and the next one. i hope you are getting my point.


//z


Hi zzuegg,

Yes I understand what you are saying - I had noticed it myself. That is what leads me to believe that it is an indexing issue. The broker that I use included a weekend bar up until August last year - now they have 5 trade bars per week. I cannot remember if the weekend bar was a Saturday or Sunday, either way, by ignoring the 0 and 6 integer value for the TimeDayOfWeek() function, I can plot my lines in the correct location. As this does not work in the future, I assume that the bars do not have the same indexing convention - I'm guessing that it is a continuous count rather than the cyclical count of the TimeDayOfWeek() function. This would obviously throw my count out. It isn't a big problem, just surprised me!

Cheers

bernd
989
bernd  
oneday:

As I said, it works fine in the processed bars, but, adds in extra days

These days are the space that MT4 reserves for the weekend. By default MT4 has no concept of "no bars at the weekend", it will expand the time axis to the right linearly with 7 days per week (move the cross-hair cursor over this area and note the dates!).

If it receives the first tick on Monday it will collapse everything that has been between this tick (Monday) and the tick immediately preceding it (Friday). Generally MT4 will always collapse the space between two ticks to zero and start the new candle immediately after the last one if there has been a pause longer than a candle without ticks between them. This is also visible during the week on M1 charts during quiet sessions you will often see "missing" candles (actually you won't see them because they are missing but the time axis will have "holes" in it), there the "empty space" of several minutes without ticks has been collapsed to zero at the very moment the first tick came in after the pause. Your lines will jump 2 days to the left on Monday and the weekend will disappear on the very first tick after the next weekend.

zzuegg
1505
zzuegg  
7bit:
These days are the space that MT4 reserves for the weekend. By default MT4 has no concept of "no bars at the weekend", it will expand the time axis to the right linearly with 7 days per week. If it receives the first tick on monday it will collapse everything that has been between this tick (Monday) and the tick immediately preceding it (Friday). Generally MT4 will always collapse the space between two ticks to zero and start the new candle immediately after the last one if there has been a pause longer than a candle without ticks between them. This is also visible during the week on M1 charts during quiet sessions you will often see "missing" candles (actually you wont see them because they are missing but the time axis will have "holes" in it), there the "empty space" of several minutes without ticks has been collapsed to zero at the very moment the first tick came in after the pause. Your lines will jump 2 days to the left on Monday and the weekend that is now visible (move the mouse and note the dates!) will disappear.
as always +1 to 7bit. i didn't know that mt4 will collaps also the bars on lower chart when there was no tick. do you maybe know how indicator behave in such periods when they are called by a EA running in a endless loop?
OneDay
115
OneDay  
7bit:

These days are the space that MT4 reserves for the weekend. By default MT4 has no concept of "no bars at the weekend", it will expand the time axis to the right linearly with 7 days per week (move the cross-hair cursor over this area and note the dates!).

If it receives the first tick on Monday it will collapse everything that has been between this tick (Monday) and the tick immediately preceding it (Friday). Generally MT4 will always collapse the space between two ticks to zero and start the new candle immediately after the last one if there has been a pause longer than a candle without ticks between them. This is also visible during the week on M1 charts during quiet sessions you will often see "missing" candles (actually you wont see them because they are missing but the time axis will have "holes" in it), there the "empty space" of several minutes without ticks has been collapsed to zero at the very moment the first tick came in after the pause. Your lines will jump 2 days to the left on Monday and the weekend will disappear on the very first tick after the next weekend.


Thanks 7bit - definitely not a bug!
bernd
989
bernd  
zzuegg:
as always +1 to 7bit. i didn't know that mt4 will collaps also the bars on lower chart when there was no tick. do you maybe know how indicator behave in such periods when they are called by a EA running in a endless loop?

For the indicator it will be the same situation as when you look at the chart: you can count the bars backwards and everything seems to be fine, the bar numbering is the same as you see it in the chart. Only the Time[] values will make bigger jumps from time to time but most indicators dont use them.

Only if you need to correlate older prices several bars back with prices from a different pair you will have to use

i_other = iBarShift("XXXYYY", 0, Time[i_this]);

to get the bar number in the other pair that correlates to a bar in this pair because the index numbers will start to differ the more you go back in time.

zzuegg
1505
zzuegg  
7bit:

For the indicator it will be the same situation as when you look at the chart: you can count the bars backwards and everything seems to be fine, the bar numbering is the same as you see it in the chart. Only the Time[] values will make bigger jumps from time to time but most indicators dont use them.

Only if you need to correlate older prices several bars back with prices from a different pair you will have to use

i_other = iBarShift("XXXYYY", 0, Time[i_this]);

to get the bar number in the other pair that correlates to a bar in this pair because the index numbers will start to differ the more you go back in time.

i think i explaind to bad what i ment.

imagine following:

double stoch.eurusd;
void start(){
  while(true){
    stoch.eurusd=getStochastic(EURUSD,5,3,3,0);
    Sleep(100);
  }
}

what is the expected value for stoch.eurusd if there are periods with no ticks. of course when watching the history the stoch seems good, but does the period of missing ticks influences the value, meaning it goes flat for some time and then (when a new tick arrive) delete this flat period.

12
To add comments, please log in or register