Get Aggregation period

rvaidyamath

New member
Hello there

let us say .. i need a signal to come when the aggregation period as per the clock (time of the day) is done properly . .ex., if i need a signal to come when at each 5 minute... i need the signal to show up at beginning of hh:6:00, hh:11:00, hh:16 and so on .. this could be any hour of the day … how do i get this .. The following script is what I am attempting, but it is not going as well as I had hoped.

#Code :
input givenMinute = 5;

def currentTime = GetTime();
AddLabel(yes, "Current Time: " + AsText(currentTime), Color.CYAN);
def currentMinute = Floor(currentTime / (1000 * 60));
AddLabel(yes, "Current Minute: " + AsText(currentMinute), Color.CYAN);
def remainder = currentMinute % givenMinute;
AddLabel(remainder == 0, "Remainder is a complete period: " + AsText(remainder), Color.CYAN);
AddLabel(remainder != 0, "Incomplete period: " + AsText(remainder), Color.YELLOW);

def currentHour = Floor(currentTime / (1000 * 60 * 60));
def currentMinuteInHour = Floor((currentTime - (currentHour * 60 * 60 * 1000)) / (1000 * 60));
def currentSecondInMinute = Floor((currentTime - (currentHour * 60 * 60 * 1000) - (currentMinuteInHour * 60 * 1000)) / 1000);

AddLabel(1, "Current Time: " + AsText(currentHour) + ":" + AsText(currentMinuteInHour) + ":" + AsText(currentSecondInMinute), Color.GRAY);

#code End - Appreciate the help
 
Hello there

let us say .. i need a signal to come when the aggregation period as per the clock (time of the day) is done properly . .ex., if i need a signal to come when at each 5 minute... i need the signal to show up at beginning of hh:6:00, hh:11:00, hh:16 and so on .. this could be any hour of the day … how do i get this .. The following script is what I am attempting, but it is not going as well as I had hoped.

#Code :
input givenMinute = 5;

def currentTime = GetTime();
AddLabel(yes, "Current Time: " + AsText(currentTime), Color.CYAN);
def currentMinute = Floor(currentTime / (1000 * 60));
AddLabel(yes, "Current Minute: " + AsText(currentMinute), Color.CYAN);
def remainder = currentMinute % givenMinute;
AddLabel(remainder == 0, "Remainder is a complete period: " + AsText(remainder), Color.CYAN);
AddLabel(remainder != 0, "Incomplete period: " + AsText(remainder), Color.YELLOW);

def currentHour = Floor(currentTime / (1000 * 60 * 60));
def currentMinuteInHour = Floor((currentTime - (currentHour * 60 * 60 * 1000)) / (1000 * 60));
def currentSecondInMinute = Floor((currentTime - (currentHour * 60 * 60 * 1000) - (currentMinuteInHour * 60 * 1000)) / 1000);

AddLabel(1, "Current Time: " + AsText(currentHour) + ":" + AsText(currentMinuteInHour) + ":" + AsText(currentSecondInMinute), Color.GRAY);

#code End - Appreciate the help

sorry, not sure what you want.
what do you want to see on the chart.
what does 5 minutes have to do with 4 hour time periods?

labels only appear if the condition is true on the last bar.

smallest time on a time chart is minute, so calculating seconds is pointless.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

sorry, not sure what you want.
what do you want to see on the chart.
what does 5 minutes have to do with 4 hour time periods?

labels only appear if the condition is true on the last bar.

smallest time on a time chart is minute, so calculating seconds is pointless.
I am looking for the clock hours ; let us say i want this for 5 minutes; candle to come 5th , 10, 15th, 20th, and so on .. not the last 5 minutes or so...
 
I am looking for the clock hours ; let us say i want this for 5 minutes; candle to come 5th , 10, 15th, 20th, and so on .. not the last 5 minutes or so...
sorry, still have no idea what you are asking for. you didn't answer my questions.
5th, 10th,.. of what ? don't know what this means.

do you want bubbles that display the hour of a bar, on every 5th bar of a day?

stare at a chart, pretend you can see what you want, and describe it
 
ex., i need an alert every aggregation period of 5 minutes; ema 3 crosses ema 10 ; if my aggregation period is 5 minutes. i want to be in the trade after the completion of the 5, 10, 15, 20, 25, and so on for the clock hours..... in thinkscript; it gets triggered if that condition is true from prior 5 minutes that can happen any period of the day... but i need this as per the clock hours aggregation ; hope this helps
 
ThinkScript triggers trades at the CLOSE of the bar, if you have your condition set to use the CLOSE price. It is a dangerous game and not recommended to use the current price (rather than the close of the previous bar) to do back testing as it tends to repaint. There are myriad discussions of repainting around here. Trying to use the cross of 2 emas inside the current bar to signal a buy or sell is one of those repainting situations where, should the price change before the close of the bar, the cross would not have happened and therefore your entry conditions are invalidated but you're already in a trade.

As for the alert at the end of 5 minute blocks, so that you would get an alert at 10:00, 10:05, 10:10, etc... the standard 5 minute aggregation period is locked to these increments -- that is, it is NOT the last 5 minutes from whatever point you are at in the day. There are ways to get the last 5 minutes as a rolling window, but they are convoluted and counter to your intents at any rate.

Again, as @halcyonguy says, we're grasping at straws here trying to sort out what exactly you're looking for.

-mashume
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
271 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top