# 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:
• • GRCOH and MerryDay
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:
• Pensar
I actually got it coded but I will check out yours also and let you know! Thanks!

• Pensar
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!

• barbaros and Pensar

### Not the exact question you're looking for?

87k+ Posts
113 Online ## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?