# Averages - with floating levels for ThinkorSwim

##### New member
Been testing TOS for a couple of days and decided to post something here too ...
A simple indicator with a possible way to filter out the signals from a single average

Usually if a single average is used for trading decisions, the slope of an average is used for that. That has its problems - mainly that most of the averages are not smooth. This is one possible way to avoid that trap.

The indicator is using floating levels to determine the "significance" for average value change and then, based on that, shows :
• trend
• and signals
It uses the usual set of averages types and should not be difficult to use it

Code:
``````#-----------------------------------------------------------------------------------------
#
#-----------------------------------------------------------------------------------------
#     [email protected]
#

input averagePeriod     = 14;
input averagePrice      = close;
input averageType       = AverageType.SMA;
input levelsPeriod      = 35;
input levelsUpPercent   = 90;
input levelsDownPercent = 10;
input showSignals       = yes;

#

plot average = MovingAverage(averageType, averagePrice, averagePeriod);
def minAverage = Lowest(average, Max(levelsPeriod, 1));
def maxAverage = Highest(average, Max(levelsPeriod, 1));
plot levelUp   = minAverage + (maxAverage - minAverage) * levelsUpPercent / 100.0;
plot levelDown = minAverage + (maxAverage - minAverage) * levelsDownPercent / 100.0;

average.SetLineWeight(2);
average.DefineColor("up", GetColor(6));
average.DefineColor("neutral", GetColor(7));
average.DefineColor("down", GetColor(2));
average.AssignValueColor(if average > levelUp then average.Color("up") else if average < levelDown then average.Color("down") else average.Color("neutral"));

levelUp.SetDefaultColor(GetColor(6));
levelDown.SetDefaultColor(GetColor(2));
levelUp.SetStyle(Curve.SHORT_DASH);
levelDown.SetStyle(Curve.SHORT_DASH);

plot upSignalCross   = if average crosses above levelUp then levelUp else Double.NaN;
upSignalCross.SetHiding(!showSignals);
upSignalCross.SetDefaultColor(GetColor(6));
upSignalCross.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
upSignalCross.HideBubble();
plot downSignalCross = if average crosses below levelDown then levelDown else Double.NaN;
downSignalCross.SetHiding(!showSignals);
downSignalCross.SetDefaultColor(GetColor(2));
downSignalCross.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
downSignalCross.HideBubble();``````

Last edited by a moderator:
nice

does not work

@Ramesh16 Please be specific. What doesn't work? Did you get an error message? If so, what does it say?

@Ramesh16 Please be specific. What doesn't work? Did you get an error message? If so, what does it say?
hi Ben, I tried to paste the above code, it gave multiple errors.

@Ramesh16 Please include a screenshot of the error, that way we can look into it and help you troubleshoot.

Here is a link to shared script averages with floating levels https://tos.mx/ZrHBa8u

Works as expected (no errors)

PS: the example picture from post 1 was made using Wilders ema (all the rest of the parameters are default)

Last edited by a moderator:

Yes, I am
I look forward to future post from you, and awesome indicators.

Not saying anyone should do this, but you could have used only this indicator on the /ES today and made a lot of \$\$\$.

Last edited:
Not saying anyone should do this, but you could have used only this indicator on the /ES today and made a lot of \$\$\$.
how would you put an alarm on this so when the down signal cross happens you get one sound and when an up signal cross happens you get another sound and what time frame would you use during a trading day (ticks or minutes)?

how would you put an alarm on this so when the down signal cross happens you get one sound and when an up signal cross happens you get another sound and what time frame would you use during a trading day (ticks or minutes)?
An Alert() in A Chart Study will provide the most instantaneous alert where as other types of alerts can be somewhat delayed, such as text alerts... The alerts would be based on the crossover itself...

For Day Trading the timeframe is up to you and depends on what you are trading as far as Ticks vs Time... I scalp and day trade and I monitor multiple timeframes... My current setup has one 4-up Window that only monitors the chart with a few indicators in 3m, 5m, 10m, and 15m timeframes... I have other windows with additional indicators in 5m, 15m, and 30m timeframes... Then I have a trading window with a 5m chart and my Active Trader and Time & Sales panels... I scalp options but monitor the underlying, primarily, and have two smaller panels on the right... The upper and lower panels can either have a Call on top and Put on the bottom, or can have the option chart in one panel and AT and T&S in the other... It's a versatile setup for not running on extremely high resolution displays... And when I run Renko Bar charts I mainly use ATR for tick count but reduce tick counts across the 4-up charts... I can provide images upon request...

Hope this helps...

@kabira I just testing with the exact same chart setup and all of your symbols displayed perfectly...

@kabira I also had no problem with your chart setup. Perhaps it is your timeframe duration???? 1D5min is not providing very many data points to work with. Consider going up to at least 20 days and see if that solves the issue?
HTH

@kabira I also had no problem with your chart setup. Perhaps it is your timeframe duration???? 1D5min is not providing very many data points to work with. Consider going up to at least 20 days and see if that solves the issue?
HTH

@MerryDay That was how I tested, with the exact same settings overall, and all everything displayed as expected...

@kabira Were you doing all testing on a single chart, or in multiple detached charts...???

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