Download MetaTrader 5

Calculate the range exclude the sunday

To add comments, please log in or register
M
93
M  

I have a problem

i want to calculate the range form X day like NRangeday=3....50

but i want to esclude the sunday how i can do it??

An example if NRangeday=4 i wnat to calculate the 4 previus range so,began to yesteraday 7 july Tuesday , 6 Monday, 3 Friday, 2 Thursday

Because the Day of week only say wich day are today, not say the pevius day etc etc

a possibile solution, (but there is a problem with sunday)

for(i=1;i<=NRangeday;i++)
{
      R5    =    R5  +  (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;

}

Or use a fix version but i can't change the NRangeday

if (DayOfWeek() == 1)
      {
  double range=10000*(iHigh(NULL,PERIOD_D1,2)+iHigh(NULL,PERIOD_D1,3)+iHigh(NULL,PERIOD_D1,4)-iLow(NULL,PERIOD_D1,2)-iLow(NULL,PERIOD_D1,3)-iLow(NULL,PERIOD_D1,4))/3;
  }
    if (DayOfWeek() == 2)
      {
   range=10000*(iHigh(NULL,PERIOD_D1,1)+iHigh(NULL,PERIOD_D1,3)+iHigh(NULL,PERIOD_D1,4)-iLow(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,3)-iLow(NULL,PERIOD_D1,4))/3;
  }

The problem is iHigh(NULL,PERIOD_D1,i) how to contro the shif number i

Huck Finn
175
Huck Finn  

I suggest that you implement a counting variable that starts on Sunday when the market opens. Then utilize that variable to adjust the parameter in the iHighest() function.


Or, alternatively, implement a variable that calcs the time from say 8AM CET to the present then convert that time to bars (ie 12 x hrs for M5 bars, etc.) and then utilize that variable to adjust the parameter in the iHighest() function.


Cheers

M
93
M  
FXtrader2008:

I suggest that you implement a counting variable that starts on Sunday when the market opens. Then utilize that variable to adjust the parameter in the iHighest() function.


Or, alternatively, implement a variable that calcs the time from say 8AM CET to the present then convert that time to bars (ie 12 x hrs for M5 bars, etc.) and then utilize that variable to adjust the parameter in the iHighest() function.


Cheers



i don't undertand how to use this counting variable....how add it??

an example

on sunday this variable is 0, when i increment it??

Huck Finn
175
Huck Finn  
The_Matrix:

i don't undertand how to use this counting variable....how add it??

an example

on sunday this variable is 0, when i increment it??

Disregard my previous post --- I only glanced at your code prior to posting and thought I understood your question.


I initially thought you were scanning time periods less than the daily chart, however now when I look at your code and your question more carefully it appears you actually want to look at trading ranges on the daily chart. If that is the case I do not understand your question. There is no trading on Sunday and the charts already skip the weekend. What you call "Sunday" trading is actually "Monday" trading in the orient. But if you live somewhere in the western hemisphere it appears as "Sunday" trading because MT4 is functioning.


My demo broker starts recording trades at 00:00AM on Monday (GMT+1), but in the (GMT-8) time zone that is 3:00PM Sunday. As a result, there is no "Sunday" data to overlook --- it only seems like Sunday


However, if you want to look at time frames less than daily, you could exclude the orient trading that occurs in the early GMT AM hours on Monday, but then you would be only looking at a partial day.


Please describe your need more clearly. What trading are you trying to exclude? Hourly data, etc for the early GMT AM hours on Monday?

M
93
M  

yeah my problem is that i live in europe so some broker have sunday, this means 2 hour trading start at 10/11 pm and finish to 12pm and this mean a false range like 20/30pt, other broker start the monday at 0 pm

Is possible to shift the hour on the broker?? so i solve the problem easly


I want to calculate the daily range ok? possible 2/3 day range or more like 10 or more, but when u are in begin of the week in the range i have the small bar daily of sunday....so how i can delete it??


An exemple of Daily Range is: friday 180pt; sunday is 30 pt; monday is 200 pt and thuesday is 250 pt, if i calculate the daily range about 3 previus day (it's mean friday monday and thuesday) but the broker consider sunday like the last 3day and not friday!!, i have (20+200+250)/3 and this sunday add a stupid noise!!! but the real range is (180+200+250)/3 it's clear now??

Dadas
182
Dadas  
M:

I have a problem

i want to calculate the range form X day like NRangeday=3....50

but i want to esclude the sunday how i can do it??

An example if NRangeday=4 i wnat to calculate the 4 previus range so,began to yesteraday 7 july Tuesday , 6 Monday, 3 Friday, 2 Thursday

Because the Day of week only say wich day are today, not say the pevius day etc etc

a possibile solution, (but there is a problem with sunday)

Or use a fix version but i can't change the NRangeday

The problem is iHigh(NULL,PERIOD_D1,i) how to contro the shif number i



//+------------------------------------------------------------------+
int ExcludeSunday (int index) 
{
   int i = index ;
   datetime time ;
  
   time = iTime(NULL,PERIOD_D1,i);
   
   if(TimeDayOfWeek(time) == 0)
   {
      i++;
   }
         
  return(i);
}
//+------------------------------------------------------------------+
Roberto Jacobs
48617
Roberto Jacobs  
M:

I have a problem

i want to calculate the range form X day like NRangeday=3....50

but i want to esclude the sunday how i can do it??

An example if NRangeday=4 i wnat to calculate the 4 previus range so,began to yesteraday 7 july Tuesday , 6 Monday, 3 Friday, 2 Thursday

Because the Day of week only say wich day are today, not say the pevius day etc etc

a possibile solution, (but there is a problem with sunday)

Or use a fix version but i can't change the NRangeday

The problem is iHigh(NULL,PERIOD_D1,i) how to contro the shif number i

On the Meta Trader there is no bar by the timeday Saturday and Sunday, why are you trying to exclude calculation timeday of bar that does not exist?
whroeder1
17124
whroeder1  
Roberto Jacobs: On the Meta Trader there is no bar by the timeday Saturday and Sunday, why are you trying to exclude calculation timeday of bar that does not exist?
False, it depends on your broker's time zone.
  • FX opens 5pm ET Sunday and ends 5pm ET Friday. Some brokers start after (6pm is common/end before (up to 15 minutes) due to low volatility.

    Swap is computed 5pm ET. No swap if no open orders at that time.


  • Brokers use a variety of timezones. Their local time (with or without DST,) GMT/UTC, GMT+2, NY+7.

    Only with NY+7 does the broker's 00:00 equals 5pm ET and the start of a daily bar is the start of a new FX day.

    GMT brokers, means there is a 1 or 2 hour D1/H4 bar on Sunday (depending on NY DST,) and a short Friday bar.

    GMT+2 is close but doesn't adjust for NY DST.

    EET is closer except when their DST doesn't match NY's. Last Sunday of March and 1:00 on the last Sunday of October vs second Sunday in March and return at 2:00 a.m. EDT to 1:00 a.m. EST on the first Sunday in November.

  • Non-NY+7, means the chart daily bar overlaps the start, and converting broker time to NY time requires broker to GMT to NY timezone conversions.


  • If you search the web you will find differing answers. Those are all wrong (half the year) because they do not take NY DST into account (or that it changed in 2007 [important when testing history.])
Roberto Jacobs
48617
Roberto Jacobs  
whroeder1:
False, it depends on your broker's time zone.
Thanks for the enlightenment. I use point 1.
To add comments, please log in or register