A Useful MA Weighting Function For Controlling Lag & Smoothness "BWMA" For ThinkOrSwim

MichaelR

Member
Hi Everyone,

Can somebody convert this indicator into thinkscript? Or, are there similar indicators you can please share? Here are the link:
 
Last edited by a moderator:
Well, I'm not entirely certain this is correct, and I'm no expert on using fold() functions... but this seems to plot something. The colors are crude as I don't want to create 200 colors in ToS.

I left the original code in place as part of the process and to show attribution. and what I tried to do.

EDITED to make a correction to the second fold

Code:
# // This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License https://creativecommons.org/licenses/by-sa/4.0/
# //@version=4
# study("A Useful MA Weighting Function For Controlling Lag & Smoothness","BWMA",true)
# length = input(50)
# beta   = input(3.,"-Lag",minval=1,maxval=10)
# alpha  = input(3.,"+Lag",minval=1,maxval=10)
# src    = input(close)
input length = 20;
input beta = 3.0;
input alpha = 3.0;
input src = CLOSE;

# //----
# var b = array.new_float(0)
# var css = array.new_color(na)
# if barstate.isfirst
#     for i = 0 to length-1
#         x = i/(length-1)
#         w = pow(x,alpha-1)*pow(1-x,beta-1)
#         array.push(b,w)
def b = fold i = 0 to (length - 1) with w = 0 do w + (power((i / (length - 1)), alpha - 1 ) * power(1 - (i / (length - 1)), beta - 1));

# den = array.sum(b)
# //----
# sum = 0.
# for i = 0 to length-1
#     sum := sum + src[i]*array.get(b,i)

# def sum = fold j = 0 to (length - 1) with s = 0 do s + src[j] * b[j];

def sum = fold j = 0 to (length - 1) with s = 0 do s + src[j] *  (power((j / (length - 1)), alpha - 1 ) * power(1 - (j / (length - 1)), beta - 1));

# filt = sum/den

def filt = sum / b;
# //----
# os = rsi(filt,length)/100
# plot(filt,"Plot",array.get(css,round(os*199)),2)

plot indicator = filt;
addLabel(yes, indicator);

def os = RSI(length = length, price = filt);
indicator.assignValueColor(
if os > 80 then color.dark_green
else if os > 60 then color.green
else if os > 40 then color.orange
else if os > 20 then color.red
else color.dark_red
);

Let me know if this seems reasonably like the original... or perhaps where I went wrong with the folds.

-mashume
 
Last edited:

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

Thread starter Similar threads Forum Replies Date
samer800 Bernoulli Process - Binary Entropy Function for ThinkOrSwim Custom 0

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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