Repaints Important Note for MTF Studies utilizing script() for Secondary Aggs

Repaints
I believe you can only set th secondary aggs to time frames higher than the chart time frame, otherwise it will be messed up. That it seems is what he is telling you.
@horserider That's what I thought too...so I even stepped down to a 2 min chart and tried to set the 1st AGG to 3 min...2nd to 4 min...and third to 5 min...and that's when I noticed the discrepancies...I thought maybe there was an error in the code. Glad everything was addressed.
 

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

I have to keep reminding myself this. Every here I run into WTF bug which turns out to be this script tied to secondary aggregation
 
I have to keep reminding myself this. Every here I run into WTF bug which turns out to be this script tied to secondary aggregation
curious to determine what causing this issue or bug, if there is a specific documented case or use case which it appears. I've written many scripts functions in the past, and done detail comparison of running them in isolation (e.g. scripts) and in the same global context (non-scripts), and for many of them they work fine. at times, some of them don't work or exhibit different results.
 
Since there are some newcomers who still may not have a grasp on what the issue is, let's run through a quick demonstration using ATR calculations over Day, Week and Month timeframes.

First here is an ATR Values script that uses regular computation method. Run this and note the values produced

Code:
# ATR Values Regular Method
# tomsk
# 11.21.2019

input length = 14;
input averageType = AverageType.WILDERS;
input agg = AggregationPeriod.DAY;

def HDay = High(period = AggregationPeriod.DAY);
def LDay = Low(period = AggregationPeriod.DAY);
def CDay = Close(period = AggregationPeriod.DAY);
def ATRDay = MovingAverage(averageType, TrueRange(HDay, CDay, LDay), length);

def HWeek = High(period = AggregationPeriod.WEEK);
def LWeek = Low(period = AggregationPeriod.WEEK);
def CWeek = Close(period = AggregationPeriod.WEEK);
def ATRWeek = MovingAverage(averageType, TrueRange(HWeek, CWeek, LWeek), length);

def HMonth = High(period = AggregationPeriod.MONTH);
def LMonth = Low(period = AggregationPeriod.MONTH);
def CMonth = Close(period = AggregationPeriod.MONTH);
def ATRMonth = MovingAverage(averageType, TrueRange(HMonth, CMonth, LMonth), length);

AddLabel(1, " ATR("+ length + ") DAY: " + Round(ATRDay,2) + " WEEK: " + Round(ATRWeek,2) + " MONTH: " + Round(ATRMonth,2), Color.White);
# End ATR Values Regular Method

Next, here is the same study but using the script function() to compute the values

Code:
# ATR Values Script Function
# tomsk
# 11.21.2019

input length = 14;
input averageType = AverageType.WILDERS;
input agg = AggregationPeriod.DAY;

script ATRScr {
    input agg2 = AggregationPeriod.DAY;
    input length2 = 14;
    input averageType2 = AverageType.WILDERS;

    def highP = High(period = agg2);
    def lowP = Low(period = agg2);
    def closeP = Close(period = agg2);

    plot ATR = MovingAverage(averageType2, TrueRange(highP, closeP, lowP), length2);
}

def ATRDay   = ATRScr(AggregationPeriod.DAY, length, averageType).ATR;
def ATRWeek  = ATRScr(AggregationPeriod.WEEK, length, averageType).ATR;
def ATRMonth = ATRScr(AggregationPeriod.MONTH, length, averageType).ATR;

AddLabel(1, " ATR("+ length +") DAY: " + Round(ATRDay,2) + "  WEEK: " + + Round(ATRWeek,2) + " MONTH: " + Round(ATRMonth,2), Color.White);
# End ATR Script Method

Take note of both sets of numbers produced and compare it
You might also like to check this out @diazlaz @skynetgen that this is indeed an issue
Thanks for responding to this thread. Much appreciated
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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