Inverted MovAvgEnvelope

jgj

New member
VIP
Hi halcyonguy,
You helped me with this script
https://usethinkscript.com/threads/inverted-ema-for-thinkorswim.10243/
and it's been working well. Thanks again.
I was wondering if you could do the same (write the script to invert moving average) on the TOS MovAvgEnvelope if you have some time.

# MovAvgEnvelope for TOS

input displace = 0;
input length = 10;
input pctAbove = 10.0;
input pctBelow = 10.0;
input priceH = close;
input priceL = close;
input averageType = AverageType.SIMPLE;

plot UpperBand = MovingAverage(averageType, priceH[-displace], length) * (1 + pctAbove / 100);
UpperBand.SetDefaultColor(GetColor(0));

plot LowerBand = MovingAverage(averageType, priceL[-displace], length) * (1 - pctBelow / 100);
lowerBand.SetDefaultColor(GetColor(0));

Thank you in advance.
 
Last edited by a moderator:
Solution
Hi halcyonguy,
You helped me with this script
https://usethinkscript.com/threads/inverted-ema-for-thinkorswim.10243/
and it's been working well. Thanks again.
I was wondering if you could do the same (write the script to invert moving average) on the TOS MovAvgEnvelope if you have some time.

# MovAvgEnvelope for TOS

input displace = 0;
input length = 10;
input pctAbove = 10.0;
input pctBelow = 10.0;
input priceH = close;
input priceL = close;
input averageType = AverageType.SIMPLE;

plot UpperBand = MovingAverage(averageType, priceH[-displace], length) * (1 + pctAbove / 100);
UpperBand.SetDefaultColor(GetColor(0));

plot LowerBand = MovingAverage(averageType, priceL[-displace], length) * (1 - pctBelow / 100)...
Hi halcyonguy,
You helped me with this script
https://usethinkscript.com/threads/inverted-ema-for-thinkorswim.10243/
and it's been working well. Thanks again.
I was wondering if you could do the same (write the script to invert moving average) on the TOS MovAvgEnvelope if you have some time.

# MovAvgEnvelope for TOS

input displace = 0;
input length = 10;
input pctAbove = 10.0;
input pctBelow = 10.0;
input priceH = close;
input priceL = close;
input averageType = AverageType.SIMPLE;

plot UpperBand = MovingAverage(averageType, priceH[-displace], length) * (1 + pctAbove / 100);
UpperBand.SetDefaultColor(GetColor(0));

plot LowerBand = MovingAverage(averageType, priceL[-displace], length) * (1 - pctBelow / 100);
lowerBand.SetDefaultColor(GetColor(0));

Thank you in advance.


i'm not quite sure what you are asking.
that study has 2 average lines, so i inverted them, flipping them about a horizontal axis in the middle of the chart.

can turn off original band lines and inverted band lines.


Code:
# average_envelope_invert

#https://usethinkscript.com/threads/inverted-movavgenvelope.15332/
#Inverted MovAvgEnvelope
# ref
# https://usethinkscript.com/threads/inverted-ema-for-thinkorswim.10243/

def na = double.nan;

#---------------------------
# MovAvgEnvelope
input displace = 0;
input length = 10;
input pctAbove = 10.0;
input pctBelow = 10.0;
input priceH = close;
input priceL = close;
input averageType = AverageType.SIMPLE;

def UpperBand = MovingAverage(averageType, priceH[-displace], length) * (1 + pctAbove / 100);
def LowerBand = MovingAverage(averageType, priceL[-displace], length) * (1 - pctBelow / 100);

input show_original_envelope_lines = yes;
plot zup = if show_original_envelope_lines then upperband else na;
plot zdwn = if show_original_envelope_lines then lowerband else na;
zup.SetDefaultColor(GetColor(0));
zdwn.SetDefaultColor(GetColor(0));

#---------------------------

def h = highestall(UpperBand);
def l = lowestall(lowerband);

def upr_lowdiff = UpperBand - l;
def upr_inv = h - upr_lowdiff;

def lor_lowdiff = lowerBand - l;
def lor_inv = h - lor_lowdiff;

input show_inverted_bands = yes;
plot z1 = if show_inverted_bands then upr_inv else na;
z1.setdefaultcolor(color.yellow);
z1.SetStyle(Curve.MEDIUM_DASH);

plot z2 = if show_inverted_bands then lor_inv else na;
z2.setdefaultcolor(color.yellow);
z2.SetStyle(Curve.MEDIUM_DASH);

addlabel(1, "original", zup.TakeValueColor());
addlabel(1,"inverted", z1.TakeValueColor());
#

5yIEYoo.jpg
 
Solution
i'm not quite sure what you are asking.
that study has 2 average lines, so i inverted them, flipping them about a horizontal axis in the middle of the chart.

can turn off original band lines and inverted band lines.


Code:
# average_envelope_invert

#https://usethinkscript.com/threads/inverted-movavgenvelope.15332/
#Inverted MovAvgEnvelope
# ref
# https://usethinkscript.com/threads/inverted-ema-for-thinkorswim.10243/

def na = double.nan;

#---------------------------
# MovAvgEnvelope
input displace = 0;
input length = 10;
input pctAbove = 10.0;
input pctBelow = 10.0;
input priceH = close;
input priceL = close;
input averageType = AverageType.SIMPLE;

def UpperBand = MovingAverage(averageType, priceH[-displace], length) * (1 + pctAbove / 100);
def LowerBand = MovingAverage(averageType, priceL[-displace], length) * (1 - pctBelow / 100);

input show_original_envelope_lines = yes;
plot zup = if show_original_envelope_lines then upperband else na;
plot zdwn = if show_original_envelope_lines then lowerband else na;
zup.SetDefaultColor(GetColor(0));
zdwn.SetDefaultColor(GetColor(0));

#---------------------------

def h = highestall(UpperBand);
def l = lowestall(lowerband);

def upr_lowdiff = UpperBand - l;
def upr_inv = h - upr_lowdiff;

def lor_lowdiff = lowerBand - l;
def lor_inv = h - lor_lowdiff;

input show_inverted_bands = yes;
plot z1 = if show_inverted_bands then upr_inv else na;
z1.setdefaultcolor(color.yellow);
z1.SetStyle(Curve.MEDIUM_DASH);

plot z2 = if show_inverted_bands then lor_inv else na;
z2.setdefaultcolor(color.yellow);
z2.SetStyle(Curve.MEDIUM_DASH);

addlabel(1, "original", zup.TakeValueColor());
addlabel(1,"inverted", z1.TakeValueColor());
#

5yIEYoo.jpg

Thanks for the quick reply. This is exactly what i need.

https://1drv.ms/i/s!AvNhOMaz7VP_icZYNYa4crdB-vhaRw?e=sptjW9
 

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

Thread starter Similar threads Forum Replies Date
Bingy Identifying Inverted hammers Questions 3

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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