Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

How to execute code only once per hourly bar Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
Power9999
Posted : Thursday, July 23, 2009 6:07:27 PM
Registered User
Joined: 10/7/2004
Posts: 12

On the hourly chart, I want to execute certain code only once at the end of an hourly bar.  How do I get code to execute only once per hourly bar?

Bruce_L
Posted : Friday, July 24, 2009 10:27:28 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
I really don't understand the request.

Do you want the code to run only once an hour?

Do you want the code to run once for every hourly bar?

Do you want the code to run in a particular hourly bar?

Or do you want something else entirely?

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Power9999
Posted : Saturday, July 25, 2009 11:44:11 AM
Registered User
Joined: 10/7/2004
Posts: 12
Bruce,

I want to execute this particular code to execute once for every hourly bar.  How would I specify I want the code to execute at the beginning of the bar versus the end of the bar (ie - on the first tick of the bar or the last tick of the bar)?
Bruce_L
Posted : Monday, July 27, 2009 5:58:02 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
If you have 1-Hour Charts up, anything in the Code tab should exectute once during each 1-Hour Bar. There is no way to differentiate between the beginning or end of the Bar as it is a single Bar with a single time and date.

If you have Charts up with a Time Frame that is shorter than 1-Hour, you can differentiate the first Bar of the hour by manually determining when the hour starts and stops in your RealCode. For example, the following RealCode Rule would return True on the first Bar shorter than an hour but at least as long as 1-Minute that ends within a 1-Hour Bar:

If Price.DateValue(1).Minute = 0 OrElse _
    (Price.DateValue.Minute <> 0 AndAlso _
    Price.DateValue.Minute < Price.DateValue(1).Minute) Then Pass

While the following RealCode Rule would return True on the last Bar shorter than an hour but at least as long as 1-Minute that ends within a 1-Hour Bar:

If Price.DateValue.Minute = 0 OrElse _
    (Price.DateValue(-1).Minute <> 0 AndAlso _
    Price.DateValue.Minute > Price.DateValue(-1).Minute) Then Pass

The second version (while displaying properly on the Charts) will not know that it is True until the next Bar starts however if the last Bar in the 1-Hour Bar does not have a time ending in :00 as it relies on the value of the next Bar for the second part of its test if the first part does not return True.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.