NexusFi: Find Your Edge


Home Menu

 





MultiSMAs "Dashboard"...


Discussion in ThinkOrSwim

Updated
    1. trending_up 1,700 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 1 posts
    2. attach_file 0 attachments




 
Search this Thread

MultiSMAs "Dashboard"...

  #1 (permalink)
netarchitech
NY, NY
 
Posts: 68 since Dec 2011
Thanks Given: 27
Thanks Received: 19

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);



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?

Comments/modifications are certainly welcome

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
48 thanks
Just another trading journal: PA, Wyckoff & Trends
35 thanks
Tao te Trade: way of the WLD
26 thanks
Bigger Wins or Fewer Losses?
24 thanks
GFIs1 1 DAX trade per day journal
20 thanks
  #2 (permalink)
netarchitech
NY, NY
 
Posts: 68 since Dec 2011
Thanks Given: 27
Thanks Received: 19

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


In my prior post, I speculated about this:


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?

Reply With Quote




Last Updated on February 24, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts