Fractal Trendline For ThinkOrSwim

Riff

New member
Men of courage and of valor! I need some help with coding this code into ToS. The correct syntax needed is escaping me. I would like the desired ToS code to be based on this code....

Trend = (((average(highest price in past 90 periods, lowest price in past 90 periods))*8)+((average(highest price in past 120 periods, lowest price in past 120 periods))*4)+((average(highest price in past 180 periods, lowest price in past 180 periods))*2))/14

Thanks Much!
 
Solution
@Riff I think I have this right -
Code:
#Trend = (((average(highest price in past 90 periods, lowest price in past 90 periods))*8)
#+((average(highest price in past 120 periods, lowest price in past 120 periods))*4)
#+((average(highest price in past 180 periods, lowest price in past 180 periods))*2))/14

def h = high;
def l = low;
def a1 = (highest(h, 90) + lowest(l, 90)) / 2;
def a2 = (highest(h, 120) + lowest(l, 120)) / 2;
def a3 = (highest(h, 180) + lowest(l, 180)) / 2;

plot trend = ((a1 * 8) + (a2 * 4) + (a3 * 2)) / 14;

Because I had the courage and valor to tackle that, I'm asking since you are a man of honor - how did you think of it? This actually looks really good for finding trend.
@Riff I think I have this right -
Code:
#Trend = (((average(highest price in past 90 periods, lowest price in past 90 periods))*8)
#+((average(highest price in past 120 periods, lowest price in past 120 periods))*4)
#+((average(highest price in past 180 periods, lowest price in past 180 periods))*2))/14

def h = high;
def l = low;
def a1 = (highest(h, 90) + lowest(l, 90)) / 2;
def a2 = (highest(h, 120) + lowest(l, 120)) / 2;
def a3 = (highest(h, 180) + lowest(l, 180)) / 2;

plot trend = ((a1 * 8) + (a2 * 4) + (a3 * 2)) / 14;

Because I had the courage and valor to tackle that, I'm asking since you are a man of honor - how did you think of it? This actually looks really good for finding trend.
 
Last edited:
Solution

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

I believe it’s a weighted average of different length of donchian channel middle lines.
Here it is as a donchian channel

Code:
#Trend = (((average(highest price in past 90 periods, lowest price in past 90 periods))*8)
#+((average(highest price in past 120 periods, lowest price in past 120 periods))*4)
#+((average(highest price in past 180 periods, lowest price in past 180 periods))*2))/14

def h = high;
def l = low;
def a1 = (highest(h, 90) + lowest(l, 90)) / 2;
def a2 = (highest(h, 120) + lowest(l, 120)) / 2;
def a3 = (highest(h, 180) + lowest(l, 180)) / 2;


plot upper = ((highest(h, 90) * 8) + (highest(h, 120) * 4) + (highest(h, 180) * 2)) / 14;
plot middle = ((a1 * 8) + (a2 * 4) + (a3 * 2)) / 14;
plot lower = ((lowest(l, 90) * 8) + (lowest(l, 120) * 4) + (lowest(l, 180) * 2)) / 14;
 
Last edited by a moderator:
Ok Pensar, I tried your code and it drew a Cyan line right on top of the line my code drew!!!! So success to both of us! Thanks Much for your time and effort, I appreciate it.

(It seems we are both brilliant coders :))
 
barbaros, the Donchain Channel thing is interesting, middle line seems to be the same as Pensar's code but now I have a channel above and below it. Thanks. I will leave it on my charts and see how much value I derive from having the extra lines above and below.

BTW guys the original code is for a "fractal" trend line.....(for use on day chart). Thanks again to both of you!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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