AGG CODE FOR ADDING A HIGHER TIME FRAME TO THIS CODE

younglove06

Member
2019 Donor
I am not sure why I struggle with this so much, but I can never get it to work. I am trying to add a higher time frame to this code, so that if I am looking at 30min candles, I will be able to plot when the pivot has reached its high/low points for the hourly candle(for example).

input swing_back = 8;
input swing_forward = 2;
input maxbars = 30;
input showlevels = Yes;
def sb = swing_back;
def sf = swing_forward;
def na = Double.NaN;

def lfor = Lowest(low, sf)[-sf];
def lback = Lowest(low, sb)[1];
def swinglow = if low < lfor and low <= lback then 1 else 0;
plot sl = if swinglow then low else na;
def hfor = Highest(high, sf)[-sf];
def hback = Highest(high, sb)[1];
def swinghigh = if high > hfor and high >= hback then 1 else 0;
plot sh = if swinghigh then high else na;

sh.SetStyle(Curve.POINTS);
sh.SetLineWeight(5);
sh.SetDefaultColor(Color.WHITE);
sl.SetStyle(Curve.POINTS);
sl.SetLineWeight(5);
sl.SetDefaultColor(Color.WHITE);

rec lsl = if IsNaN(close[-sf]) then lsl[1] else if swinglow then low else lsl[1];
rec lsh = if IsNaN(close[-sf]) then lsh[1] else if swinghigh then high else lsh[1];

def bn = BarNumber();
rec hcount = if swinghigh then 1 else hcount[1] + 1;
rec lcount = if swinglow then 1 else lcount[1] + 1;

plot lasthigh = if hcount <= maxbars and IsNaN(close[-sf]) then lsh[1] else if hcount > maxbars then na else if hcount < 2 then na else lsh;
plot lastlow = if lcount <= maxbars and IsNaN(close[-sf]) then lsl[1] else if lcount > maxbars then na else if lcount < 2 then na else lsl;

lasthigh.SetStyle(Curve.SHORT_DASH);
lasthigh.SetDefaultColor(Color.WHITE);
lasthigh.SetHiding(!showlevels);

lastlow.SetStyle(Curve.SHORT_DASH);
lastlow.SetDefaultColor(Color.WHITE);
lastlow.SetHiding(!showlevels);

I am adding:
input agg = AggregationPeriod.HOUR;

But that doesnt seem to be working from what I can tell. Any assistance would be greatly appreciated :)
 
Last edited by a moderator:
Solution

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
202 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