MultiSMAs "Dashboard"... - ThinkOrSwim | futures io social day trading

MultiSMAs "Dashboard"...
 Updated: February 24th, 2015 (06:24 PM) Views / Replies: 795 / 1 Created: February 23rd, 2015 (11:11 AM) by netarchitech Attachments: 0

 Welcome to futures io.

# MultiSMAs "Dashboard"...

NY, NY

Platform: TOS
Favorite Futures: Stocks, ETFs

Posts: 63 since Dec 2011

MultiSMAs "Dashboard"...

In my continuing efforts to learn Thinkscript, I have cobbled together my first "Hello World"-type script. This script is in response to my wanting to efficiently condense multiple moving average studies/settings/property pages into one single "dashboard", so to speak...

Rather than try to describe what I have tried to accomplish, below is the code and "dashboard" for any/all to review:

Code
 ```declare upper; input price1 = close; input length1 = 8; input displace1 = 0; plot SMA1 = Average(price1[-displace1], length1); SMA1.SetDefaultColor(GetColor(4)); SMA1.SetLineWeight(2); SMA1.SetStyle(Curve.FIRM); SMA1.DefineColor("Up", GetColor(6)); SMA1.DefineColor("Down", GetColor(5)); SMA1.AssignValueColor(if SMA1 > SMA1[1] then SMA1.color("Up" ) else SMA1.color("Down" )); input price2 = close; input length2 = 20; input displace2 = 0; plot SMA2 = Average(price2[-displace2], length2); SMA2.SetDefaultColor(GetColor(1)); SMA2.SetLineWeight(1); SMA2.SetStyle(Curve.FIRM); input price3 = close; input length3 = 50; input displace3 = 0; plot SMA3 = Average(price3[-displace3], length3); SMA3.SetDefaultColor(GetColor(2)); SMA3.SetLineWeight(1); SMA3.SetStyle(Curve.FIRM); input price4 = close; input length4 = 100; input displace4 = 0; plot SMA4 = Average(price4[-displace4], length4); SMA4.SetDefaultColor(GetColor(5)); SMA4.SetLineWeight(2); SMA4.SetStyle(Curve.SHORT_DASH); input price5 = close; input length5 = 200; input displace5 = 0; plot SMA5 = Average(price5[-displace5], length5); SMA5.SetDefaultColor(GetColor(5)); SMA5.SetLineWeight(2); SMA5.SetStyle(Curve.LONG_DASH);```

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

While the script basically works, I have one outstanding issue. I think the lookback is associated with longest SMA length, in this case 200 bars, so charts with fewer than 200 bars will be drawn without any SMAs. Is there a solution/workaround?

NY, NY

Platform: TOS
Favorite Futures: Stocks, ETFs

Posts: 63 since Dec 2011

As a result of further research, I scrapped my original code. I came across TOS' MovAvgTwoLines study, which simply plots two MAs on a chart, with only the length parameter available for individual customization. The AverageType also offers a degree of flexibility/customization, but it applies to both MAs globally.

I wanted to have all the MAs (whether it be 2 or, in my case, 5) be individually customizable with the customizability available from one settings/property page. Now, using the new script below, I can have 5 MAs plotted with different price calculations, different lengths, different displacements and different average types.

Code
 ```declare upper; input price1 = close; input length1 = 8; input displace1 = 0; input averageType1 = AverageType.SIMPLE; input price2 = close; input length2 = 20; input displace2 = 0; input averageType2 = AverageType.SIMPLE; input price3 = close; input length3 = 50; input displace3 = 0; input averageType3 = AverageType.SIMPLE; input price4 = close; input length4 = 100; input displace4 = 0; input averageType4 = AverageType.SIMPLE; input price5 = close; input length5 = 200; input displace5 = 0; input averageType5 = AverageType.SIMPLE; plot MA1 = MovingAverage(averageType1, price1[-displace1], length1); MA1.SetDefaultColor(GetColor(4)); MA1.SetLineWeight(2); MA1.SetStyle(Curve.FIRM); MA1.DefineColor("Up", GetColor(6)); MA1.DefineColor("Down", GetColor(5)); MA1.AssignValueColor(if MA1 > MA1[1] then MA1.color("Up" ) else MA1.color("Down" )); plot MA2 = MovingAverage(averageType2, price2[-displace2], length2); MA2.SetDefaultColor(GetColor(1)); MA2.SetLineWeight(1); MA2.SetStyle(Curve.FIRM); plot MA3 = MovingAverage(averageType3, price3[-displace3], length3); MA3.SetDefaultColor(GetColor(2)); MA3.SetLineWeight(1); MA3.SetStyle(Curve.FIRM); plot MA4 = MovingAverage(averageType4, price4[-displace4], length4); MA4.SetDefaultColor(GetColor(5)); MA4.SetLineWeight(2); MA4.SetStyle(Curve.SHORT_DASH); plot MA5 = MovingAverage(averageType5, price5[-displace5], length5); MA5.SetDefaultColor(GetColor(5)); MA5.SetLineWeight(2); MA5.SetStyle(Curve.LONG_DASH);```

At least now I can access all the MAs on my chart from one centralized "dashboard" or settings/property page, as opposed to keeping track of 5 different applied MA studies. Nothing major, to be sure, but nice from a learning perspective...

While it feels good to create something useful, I came across an issue using the new study. When I plot the study in some cases, it doesn't draw the study to the left edge of the chart. See the sample below:

AAPL 180 d 4h
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Quoting
 I think the lookback is associated with longest SMA length, in this case 200 bars, so charts with fewer than 200 bars will be drawn without any SMAs.

I further thought this may have been a problem with the original code, but it is happening with new code as well. I'm stumped and hoping someone might have an insight or solution to this dilemma...

Any thoughts?

 futures io > MultiSMAs "Dashboard"...

Upcoming Webinars and Events (4:30PM ET unless noted)

Right now

Right now

## Journal in July -- over \$2,500 in prizes w/NinjaTrader

July

 Similar Threads Thread Thread Starter Forum Replies Last Post Naples Trading Reviews and Vendors 2 January 7th, 2015 07:56 AM Quick Summary News and Current Events 0 December 17th, 2011 07:10 PM Quick Summary News and Current Events 0 November 22nd, 2011 01:50 AM javed759 NinjaTrader 1 November 1st, 2011 10:44 PM lokgotkent Traders Hideout 6 September 30th, 2011 01:24 PM

 Tags ai, average, charts, code, dow, lookback, moving average, research, review, sample, short, sma, standing, think or swim, thinkorswim, thinkscript, tos, type