How to code past x time Aggregation period ?

amohammedtrade

New member
Hello ,

Need help with Aggregation period to search for current time minus desired time

For example need to code this

input Agg= AggregationPeriod.Four_hours;

As

input Agg = "last 4 hours from now "


Any help is appreciated


Thanks in advance
 
Hello ,

Need help with Aggregation period to search for current time minus desired time

For example need to code this

input Agg= AggregationPeriod.Four_hours;

As

input Agg = "last 4 hours from now "


Any help is appreciated


Thanks in advance

Hopefully this provides some useful information for you.

The first part with data and data1 @4hr agg defines the value of the bar prior to the current 4hr agg

The second part with x and xx finds the value of the candle 4hrs prior to that based upon the agg of the chart being used.

The last part of Time bubbles shows the current time of the last candle and that of 4hrs prior to the last candle.

Capture.jpg
Ruby:
#This displays the bar's value at the 4hr agg prior to the current 4hr bar
input Agg  = AggregationPeriod.FOUR_HOURS;
def data  = high(period = Agg);
def data1 = high(period = Agg)[1];
AddLabel(1, "High @prior 4hr agg candle: " + data1, Color.YELLOW);

#x=last bar being displayed
#xx= high @bar 4hrs before x
def x   = if !IsNaN(close) and IsNaN(close[-1]) then BarNumber() else 0;
plot xx = if BarNumber() == (HighestAll(x) - 4 * 60 / (GetAggregationPeriod() / 60000)) then high else Double.NaN;
xx.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
AddLabel(1, "High 4hrs ago based upon chart agg: " + HighestAll(xx), Color.WHITE);

#######
#Example Time_Gettime
#Sleepz 20210315
#Usethinkscript request

#Time Stamp based upon Gettime and RegularTradingStart. Choose timezone
input timezone = {default "ET", "CT", "MT", "PT"};

def starthour  = (if timezone == timezone."ET"
                        then 9
                        else if timezone == timezone."CT"
                        then 8
                        else if timezone == timezone."MT"
                        then 7
                        else 6) ;
def hour = Floor(((starthour * 60 + 30) + (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000) / 60);
def minutes = (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000 - ((hour - starthour) * 60 + 30) + 60;

AddChartBubble(IsNaN(close[-1]), low, "Time:" + hour + ":" + (if minutes < 10 then "0" else "") + minutes, Color.WHITE, no);
AddChartBubble(IsNaN(close[-1]), low, "Time 4hrs ago :" + (hour - 4) + ":" + (if minutes < 10 then "0" else "") + minutes, Color.WHITE, no);
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
297 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