NexusFi: Find Your Edge


Home Menu

 





Script to add a moving average


Discussion in ThinkOrSwim

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




 
Search this Thread

Script to add a moving average

  #1 (permalink)
TradingForALiving
Miami Florida US
 
Posts: 16 since Oct 2015
Thanks Given: 6
Thanks Received: 1

Can someone please show me how to add a 50 bar simple moving average to the following relative strength script that is found in TOS:


declare lower;

input CorrelationWithSecurity = "SPX";
def close2 = close(CorrelationWithSecurity);

plot RS = if close2 == 0 then 0 else close/close2;
RS.setDefaultColor(GetColor(6));

def sr = CompoundValue("historical data" = RS, "visible data" = if isNaN(sr[1]) then RS else sr[1]);
plot SRatio = sr;
SRatio.setDefaultColor(GetColor(5));

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Quantum physics & Trading dynamics
The Elite Circle
MC PL editor upgrade
MultiCharts
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Better Renko Gaps
The Elite Circle
 
  #2 (permalink)
 
TrendFollower1's Avatar
 TrendFollower1 
Austin, TX
 
Experience: Advanced
Platform: ThinkOrSwim
Trading: Currency, index, commodity futures
Posts: 9 since Mar 2012
Thanks Given: 18
Thanks Received: 8

Hi, this seems to work. You can adjust the length and type of moving average if needed. The additional code is shown in bold.

Best of luck to you.

# RelativeStrength_with_MA

declare lower;

input length = 50;
input averageType = AverageType.Simple;
input CorrelationWithSecurity = "SPX";
def close2 = close(CorrelationWithSecurity);

plot RS = if close2 == 0 then 0 else close/close2;
plot RSavg = MovingAverage(averageType, RS, length);

RS.setDefaultColor(GetColor(6));
RSavg.setDefaultColor(Color.RED);

def sr = CompoundValue("historical data" = RS, "visible data" = if isNaN(sr[1]) then RS else sr[1]);
plot SRatio = sr;
SRatio.setDefaultColor(GetColor(5));

Reply With Quote
Thanked by:




Last Updated on July 27, 2021


© 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