Clarification on Multi-Timeframe Issue

Let's say I only want to use a higher timeframe on my chart to determine some kind of previous trend, using the ALREADY CLOSED bars of the higher timeframe (to mitigate repainting). The live prices can bounce up and down on the current lower timeframe all it wants, but I want the higher timeframe's data to be lagging by 1 bar, so that there's no repainting. Would that look something like this?

Code:
input currentTimeFrame = AggregationPeriod.Min;
input plus1AggPeriod = AggregationPeriod.Five_Min;
input TrendPeriods = 6;

def currentTFOpen = open(period = currentTimeFrame);
def currentTFHigh = high(period = currentTimeFrame);
def currentTFLow = low(period = currentTimeFrame);
def currentTFClose = close(period = currentTimeFrame);
def currentTFHighestHigh = highest(currentTFHigh, trendPeriods);
def currentTFLowestLow = lowest(currentTFLow, trendPeriods);
def currentTFTrend = (currentTFClose - currentTFLowestLow) / (currentTFHighestHigh - currentTFLowestLow);

def plus1AggOpen = open(period = plus1AggPeriod);
def plus1AggHigh = high(period = plus1AggPeriod);
def plus1AggLow = low(period = plus1AggPeriod);
def plus1AggClose = close(period = plus1AggPeriod);
def plus1AggHighestHigh = highest(plus1AggHigh, trendPeriods);
def plus1AggLowestLow = lowest(plus1AggLow, trendPeriods);
def plus1AggTrend = (plus1AggClose - plus1AggLowestLow) / (plus1AggHighestHigh - plus1AggLowestLow);

AssignPriceColor(if((currentTFTrend + plus1AggTrend[5]) / 2) > .5 then color.blue else color.orange);

I create 2 variables called
Code:
currentTFTrend
and
Code:
plus1AggTrend
, and if their average values are greater than .5, color the bars blue, otherwise orange. In the bottom line, I am referencing the plus1AggTrend from 5 bars ago re: there being 5 x 1-min bars in 1 x 5-min bar. Is this correct? I initially thought that I could reference
Code:
plus1AggTrend[1]
instead of
Code:
plus1AggTrend[5]
, however the previous few bars repaint colours, so thinking either 5 or 6 is necessary to prevent that.
 
Last edited by a moderator:
Solution
You have a rolling 5 bar displacement. but the 5min candle is not necessarily the last 5 bars.
If the time is
9:41 am, the last 5min candle was 1 bar ago
9:42 am, the last 5min candle was 2 bars ago
9:43 am, the last 5min candle was 3 bars ago etc... etc.. etc...
Your method would not work.
You have a rolling 5 bar displacement. but the 5min candle is not necessarily the last 5 bars.
If the time is
9:41 am, the last 5min candle was 1 bar ago
9:42 am, the last 5min candle was 2 bars ago
9:43 am, the last 5min candle was 3 bars ago etc... etc.. etc...
Your method would not work.
 
Last edited:
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
293 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