How to count the H1 period of a specified date

Moderator: admin

How to count the H1 period of a specified date

Postby guangho » Sun Jun 14, 2020 10:33 pm

I want to ask: How to count the H1 period of a specified date?

My approach is:
local A=core.dateToTable(core.now());--Today's date
local B=A.year+1;--Date one year ago,year value
--Count the number between B and A of H1 period,I won't write the next

Can you teach me?thank you!
guangho
FXCodeBase: Initiate
 
Posts: 106
Joined: Sat Sep 29, 2012 12:16 pm

Re: How to count the H1 period of a specified date

Postby Apprentice » Mon Jun 15, 2020 4:25 am

Your request is added to the development list.
Development reference 1489.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: How to count the H1 period of a specified date

Postby guangho » Mon Jun 15, 2020 9:39 pm

Apprentice wrote:Your request is added to the development list.
Development reference 1489.


thank you!

Does the bug mentioned in another post really exist?
guangho
FXCodeBase: Initiate
 
Posts: 106
Joined: Sat Sep 29, 2012 12:16 pm

Re: How to count the H1 period of a specified date

Postby Apprentice » Tue Jun 16, 2020 5:52 am

You can't count real number of bar on H1 in a range of a year.
Historical data has a limited side, so you just will not have enough data.
On a small ranges you can have something like this:

local a = core.now();--Today's date
local b = a - 365;--Date one year ago,year value
local a_index = core.findDate(source, a, false);
local b_index = core.findDate(source, b, false);
if b_index < 0 or a_index < 0 then
--not enought data
else
local distance_bars = a_index - b_index;
end
The only thing you can do on the long distances is to approximate.

local range = source:date(NOW) - source:date(0);
local rate = range / source:size();
local distance_bars = (a - b) / rate;
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: How to count the H1 period of a specified date

Postby Apprentice » Tue Jun 16, 2020 5:57 am

You can get last year date using this two lines.
current_date_table=core.dateToTable (core.now())
last_year_date=core.datetime (current_date_table.year-1, current_date_table.month, current_date_table.day, 0, 0, 0)
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: How to count the H1 period of a specified date

Postby guangho » Wed Jun 17, 2020 11:33 pm

Apprentice wrote:You can't count real number of bar on H1 in a range of a year.
Historical data has a limited side, so you just will not have enough data.
On a small ranges you can have something like this:

local a = core.now();--Today's date
local b = a - 365;--Date one year ago,year value
local a_index = core.findDate(source, a, false);
local b_index = core.findDate(source, b, false);
if b_index < 0 or a_index < 0 then
--not enought data
else
local distance_bars = a_index - b_index;
end
The only thing you can do on the long distances is to approximate.

local range = source:date(NOW) - source:date(0);
local rate = range / source:size();
local distance_bars = (a - b) / rate;



Thank you for your answer. Let me test it. :D
guangho
FXCodeBase: Initiate
 
Posts: 106
Joined: Sat Sep 29, 2012 12:16 pm


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 13 guests