STDEV_MA_Diff For ThinkOrSwim

rs00205

New member
VIP
Author states:
Standard Deviation and 20 Moving Avergae Difference.
This could help some Buy & Sell with Difference between STDEV and 20 MA.
Author suggest timeframes: Daily, 6-hr, hourly

NWAC6U3.png


Hi Looking to see if someone can make this tradingview script into a thinkorswim script.
https://www.tradingview.com/script/e0x4sXiX/
 
Last edited by a moderator:
Hi Looking to see if someone can make this tradingview script into a thinkorswim script.
https://www.tradingview.com/script/e0x4sXiX/

//@version=3
study(title = "STDEV_MA_Diff", shorttitle = "STDEVDIFF")
length = input(20, minval=1)
src = input(close, title="Source")
stdev = stdev(src, length)
ma20 = sma(close, 20)
diff = ((stdev)-close+(ma20))
diff_colorchange = input(true)
diff_isAbove = diff >= 0
diff_isBelow = diff < 0
diff_color = diff_colorchange ? diff_isAbove ? red : green : green
plot(diff, color = diff_color)
plot(0.000000001, title='Zero')
plot(50, title='50STDEV BUY', color=green)
plot(30, title='30STDEV BUY', color=green)
plot(20, title='20STDEV BUY', color=green)
plot(15, title='15STDEV BUY', color=green)
plot(10, title='10STDEV BUY', color=green)
plot(7.5, title='7.5STDEV SELL', color=red)
plot(5, title='5STDEV SELL', color=red)
plot(2.5, title='2.5STDEV SELL', color=red)
plot(1, title='1STDEV SELL', color=red)
plot(-1, title='-1STDEV BUY', color=green)
plot(-2.5, title='-2.5STDEV BUY', color=green)
plot(-5, title='-5STDEV BUY', color = green)
plot(-7.5, title='-7.5STDEV BUY', color=green)
plot(-10, title = '-10STDEV SELL', color=red)
plot(-15, title = '-15STDEV SELL', color=red)
plot(-20, title = '-20STDEV SELL', color=red)
plot(-30, title = '-30STDEV SELL', color=red)
plot(-50, title = '-50STDEV SELL', color=red)
check the below:

CSS:
#//@version=3
#study(title = "STDEV_MA_Diff", shorttitle = "STDEVDIFF")
# converted by Sam4Cok@Samer800    - Request from useThinkScript.com member
Declare lower;

input colorBars = yes;
input movAvgType = AverageType.SIMPLE;
input src = close; #, title="Source")
input length = 20; #, minval=1)
input multi1 = 1.0;
input multi2 = 2.0;
input multi3 = 3.0;

def na = Double.NaN;
def last = isNaN(Close);

def stdev = stdev(src, length);
def ma20 = MovingAverage(movAvgType, src, length);
def diff = (stdev)- close + (ma20);

def col = if diff < 0 then -1 else 1;

plot diffLine = diff; #, color = diff_color)
diffLine.AssignValueColor(if col > 0 then if diff>diff[1] then Color.GREEN else COlor.DARK_GREEN else
                          if diff<diff[1] then Color.RED else Color.DARK_RED);

plot zero = if last then na else 0;
zero.SetDefaultColor(Color.DARK_GRAY);

def diffUp = if diff > 0 then diffUp[1] + diff else diffUp[1];
def diffDn = if diff < 0 then diffDn[1] + diff else diffDn[1];
def cntUp = if diff > 0 then cntUp[1] + 1 else cntUp[1];
def cntDn = if diff < 0 then cntDn[1] + 1 else cntDn[1];
def AvgUp = diffUp / cntUp;
def AvgDn = diffDn / cntDn;

plot hh1 = if last then na else AvgUp * multi1;
plot ll1 = if last then na else AvgDn * multi1;
plot hh2 = if last then na else AvgUp * multi2;
plot ll2 = if last then na else AvgDn * multi2;
plot hh3 = if last then na else AvgUp * multi3;
plot ll3 = if last then na else AvgDn * multi3;
hh1.SetDefaultColor(Color.CYAN);
ll1.SetDefaultColor(Color.MaGENTA);
hh2.SetDefaultColor(Color.CYAN);
ll2.SetDefaultColor(Color.MaGENTA);
hh3.SetDefaultColor(Color.CYAN);
ll3.SetDefaultColor(Color.MaGENTA);

AssignPriceColor(if !colorBars then COlor.CURRENT else
                 if col > 0 then if diff>diff[1] then Color.GREEN else COlor.DARK_GREEN else
                 if diff<diff[1] then Color.RED else Color.DARK_RED);

#-- END of CODE
 
check the below:

CSS:
#//@version=3
#study(title = "STDEV_MA_Diff", shorttitle = "STDEVDIFF")
# converted by Sam4Cok@Samer800    - Request from useThinkScript.com member
Declare lower;

input colorBars = yes;
input movAvgType = AverageType.SIMPLE;
input src = close; #, title="Source")
input length = 20; #, minval=1)
input multi1 = 1.0;
input multi2 = 2.0;
input multi3 = 3.0;

def na = Double.NaN;
def last = isNaN(Close);

def stdev = stdev(src, length);
def ma20 = MovingAverage(movAvgType, src, length);
def diff = (stdev)- close + (ma20);

def col = if diff < 0 then -1 else 1;

plot diffLine = diff; #, color = diff_color)
diffLine.AssignValueColor(if col > 0 then if diff>diff[1] then Color.GREEN else COlor.DARK_GREEN else
                          if diff<diff[1] then Color.RED else Color.DARK_RED);

plot zero = if last then na else 0;
zero.SetDefaultColor(Color.DARK_GRAY);

def diffUp = if diff > 0 then diffUp[1] + diff else diffUp[1];
def diffDn = if diff < 0 then diffDn[1] + diff else diffDn[1];
def cntUp = if diff > 0 then cntUp[1] + 1 else cntUp[1];
def cntDn = if diff < 0 then cntDn[1] + 1 else cntDn[1];
def AvgUp = diffUp / cntUp;
def AvgDn = diffDn / cntDn;

plot hh1 = if last then na else AvgUp * multi1;
plot ll1 = if last then na else AvgDn * multi1;
plot hh2 = if last then na else AvgUp * multi2;
plot ll2 = if last then na else AvgDn * multi2;
plot hh3 = if last then na else AvgUp * multi3;
plot ll3 = if last then na else AvgDn * multi3;
hh1.SetDefaultColor(Color.CYAN);
ll1.SetDefaultColor(Color.MaGENTA);
hh2.SetDefaultColor(Color.CYAN);
ll2.SetDefaultColor(Color.MaGENTA);
hh3.SetDefaultColor(Color.CYAN);
ll3.SetDefaultColor(Color.MaGENTA);

AssignPriceColor(if !colorBars then COlor.CURRENT else
                 if col > 0 then if diff>diff[1] then Color.GREEN else COlor.DARK_GREEN else
                 if diff<diff[1] then Color.RED else Color.DARK_RED);

#-- END of CODE
Thank you I will give it a try
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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