Repaints MTF Trend following indicator For ThinkOrSwim

Repaints

petergluis

Active member
I use open, high, low and close of yesterday and today's open to generate a trend following indicator. It is more sensitive to trend changes than Hull moving averages. It should be used in daily chart in order to follow the trends. The part code is from toshelper.com.

Ruby:
input offset = 1;
input offset2 = 1;
input offset3=0;
input period = {default DAY, “2 DAYS”, “3 DAYS”, “4 DAYS”, WEEK, MONTH, “OPT EXP”};
plot Data = high(period = period)[offset];
Data.AssignValueColor(if Data > Data[1] then Color.green else Color.magenta);
plot Data2 = low(period = period)[offset2];
Data2.AssignValueColor(if Data2 > Data2[1] then Color.green else Color.magenta);
plot Data3 = close(period = period)[offset];
Data3.AssignValueColor(if Data3 > Data3[1] then Color.green else Color.magenta);
plot Data4 = open(period = period)[offset2];
Data4.AssignValueColor(if Data4 > Data4[1] then Color.green else Color.magenta);
plot Data5 = open(period = period)[offset3];
Data5.AssignValueColor(if Data5 > Data5[1] then Color.green else Color.magenta);
 
Last edited by a moderator:
I use open, high, low and close of yesterday and today's open to generate a trend following indicator. It is more sensitive to trend changes than Hull moving averages. It should be used in daily chart in order to follow the trends. The part code is from toshelper.com.

Ruby:
#by www.toshelper.com
input offset = 1;
input offset2 = 1;
input offset3=0;
input period = {default DAY, “2 DAYS”, “3 DAYS”, “4 DAYS”, WEEK, MONTH, “OPT EXP”};
input period2 = {default DAY, “2 DAYS”, “3 DAYS”, “4 DAYS”, WEEK, MONTH, “OPT EXP”};
plot Data = high(period = period)[offset];
Data.AssignValueColor(if Data > Data[1] then Color.green else Color.magenta);
plot Data2 = low(period = period)[offset2];
Data2.AssignValueColor(if Data2 > Data2[1] then Color.green else Color.magenta);
plot Data3 = close(period = period)[offset];
Data3.AssignValueColor(if Data3 > Data3[1] then Color.green else Color.magenta);
plot Data4 = open(period = period)[offset2];
Data4.AssignValueColor(if Data4 > Data4[1] then Color.green else Color.magenta);
plot Data5 = open(period = period)[offset3];
Data5.AssignValueColor(if Data5 > Data5[1] then Color.green else Color.magenta);
Peter your use of input period2 is not used in the code? Are we missing something?
 
Henry1223, I deleted period2 since we do not need it. Thank you very much for your reminder.
1st post updated.
 
Last edited by a moderator:
I use open, high, low and close of yesterday and today's open to generate a trend following indicator. It is more sensitive to trend changes than Hull moving averages. It should be used in daily chart in order to follow the trends. The part code is from toshelper.com.

Ruby:
input offset = 1;
input offset2 = 1;
input offset3=0;
input period = {default DAY, “2 DAYS”, “3 DAYS”, “4 DAYS”, WEEK, MONTH, “OPT EXP”};
plot Data = high(period = period)[offset];
Data.AssignValueColor(if Data > Data[1] then Color.green else Color.magenta);
plot Data2 = low(period = period)[offset2];
Data2.AssignValueColor(if Data2 > Data2[1] then Color.green else Color.magenta);
plot Data3 = close(period = period)[offset];
Data3.AssignValueColor(if Data3 > Data3[1] then Color.green else Color.magenta);
plot Data4 = open(period = period)[offset2];
Data4.AssignValueColor(if Data4 > Data4[1] then Color.green else Color.magenta);
plot Data5 = open(period = period)[offset3];
Data5.AssignValueColor(if Data5 > Data5[1] then Color.green else Color.magenta);
You might want to add a combined Plot to your formula instead of all of the separate lines
Code:
Plot Comb = (Data + Data2 + Data3+ Data4 + Data5)/5;
Comb.AssignValueColor(if Comb > Comb[1] then Color.green else Color.magenta);

Comb.SetLineWeight(3);
 
Hello Peter, I believe that this version is what you are trying to achieve my final v
Code:
input agg1 = AggregationPeriod.FIVE_MIN;
input agg2 = AggregationPeriod.Ten_MIN;
input offset = 1;
input offset2 = 0;
input APC = No;
input Arrows = no;
input Dotsize = 3;
def C = Close(Period = AGG1)[offset2];
def O = Open(Period = AGG2)[offset2];
def Oa = Open(Period = AGG2)[offset];
def Ca = Close(Period = AGG2)[offset];
def Ha = High(Period = AGG2)[offset];
def La = Low(Period = AGG2)[offset];
Plot Comb =if IsNaN(C) then Double.NaN else (O + Oa+ Ca+ Ha + La)/5;
Comb.AssignValueColor(if C > Comb[1] then Color.green else Color.magenta);
Comb.SetLineWeight(3);
AssignPriceColor(if APC == yes and C > Comb[1] then Color.green else if apc == yes and C < Comb[1] then Color.magenta else Color.Current); 
#ARROWS
plot ArrowDown = if arrows and (C Crosses below Comb[1]) then Comb[1] else double.nan;
ArrowDown.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown.setDefaultColor(color.Magenta);
ArrowDown.setLineWeight(dotsize);

plot ArrowUp = if arrows and (C crosses above Comb[1]) then Comb[1] else double.nan;
ArrowUp.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp.setDefaultColor(color.Green);
ArrowUp.setLineWeight(dotsize);
 
Last edited:
Hello, thank you for posting this code. Does this indicator repaint? Because with certain settings that I input and the time frame and the trading instrument I am looking at, it seems too good to be true.
Thanks.
 
Hello, thank you for posting this code. Does this indicator repaint? Because with certain settings that I input and the time frame and the trading instrument I am looking at, it seems too good to be true.
Thanks.

This is an MTF (multi-timeframe) indicator.
It overlays a higher timeframe on your lower timeframe chart.

As it is not possible to know what the close of the higher timeframe candle is going to be; so yes, it will repaint in the interim.
If you overlay 5min candles on a 1min chart, five 1min candles will repaint until the 5min candle closes.

Regarding the indicators with a "repaints" prefix on this forum, it's important to note that they do indeed repaint.
 
if you set the first agg period to the same as the chart then only the second Agg will continue to repaint until the second agg completes its bar
 

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