NexusFi: Find Your Edge


Home Menu

 





moving average of RSI in ThinkOrSwim


Discussion in ThinkOrSwim

Updated
      Top Posters
    1. looks_one jeffro with 2 posts (4 thanks)
    2. looks_two SinSanDiego with 2 posts (0 thanks)
    3. looks_3 kburks with 2 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 15,205 views
    2. thumb_up 5 thanks given
    3. group 8 followers
    1. forum 10 posts
    2. attach_file 1 attachments




 
Search this Thread

moving average of RSI in ThinkOrSwim

  #1 (permalink)
 
kburks's Avatar
 kburks 
Boynton Beach
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES,TF,CL
Posts: 203 since Mar 2012
Thanks Given: 327
Thanks Received: 146

how to create a moving average of RSI in ThinkOrSwim PLEASE

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
Quant vue
Trading Reviews and Vendors
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Cheap historycal L1 data for stocks
Stocks and ETFs
REcommedations for programming help
Sierra Chart
 
  #3 (permalink)
 jeffro 
San Diego, CA/United States
 
Experience: Intermediate
Platform: TOS
Trading: ES, CL, 6A
Posts: 17 since Apr 2015
Thanks Given: 2
Thanks Received: 11


Here you go:

declare lower;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input RSI_smoothing_averageType = AverageType.exponential;
input RSI_smoothing_length = 10;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);
plot OverSold = over_Sold;
plot OverBought = over_Bought;

plot RSI_moving_average = MovingAverage(RSI_smoothing_averageType, RSI, RSI_smoothing_length);

RSI_moving_average.DefineColor("OverBought", GetColor(5));
RSI_moving_average.DefineColor("Normal", GetColor(7));
RSI_moving_average.DefineColor("OverSold", GetColor(1));
RSI_moving_average.AssignValueColor(if RSI > over_Bought then RSI_moving_average.color("OverBought") else if RSI < over_Sold then RSI_moving_average.color("OverSold") else RSI_moving_average.color("Normal"));
OverSold.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(8));

Reply With Quote
Thanked by:
  #4 (permalink)
 
kburks's Avatar
 kburks 
Boynton Beach
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES,TF,CL
Posts: 203 since Mar 2012
Thanks Given: 327
Thanks Received: 146

Thanks so much, how to I get the code from here to the platform?

Started this thread Reply With Quote
  #5 (permalink)
 jeffro 
San Diego, CA/United States
 
Experience: Intermediate
Platform: TOS
Trading: ES, CL, 6A
Posts: 17 since Apr 2015
Thanks Given: 2
Thanks Received: 11

No worries.

Highlight and copy all the code I supplied. Open ThinkorSwim and go to charts, then click studies-->edit studies. A window will pop up and select "new" in the bottom left corner. A new script window will pop up. Clear out the window of any text code in there and paste the code you copied. You can change the name at the top of the window if you like. Hit "ok" and the indicator is now available.

Keep me posted on how it works for you. If you need any others let me know. I may be able to code it or already may have it coded.
-Jeff

Reply With Quote
Thanked by:
  #6 (permalink)
SinSanDiego
Del Mar, CA
 
Posts: 4 since Mar 2021
Thanks Given: 2
Thanks Received: 0

Not sure if this is the most appropriate place to ask this question, but stumbled on this thread and am hoping someone can help me create a ThinkorSwim script which will chart RSI with 2 (two) moving averages, rather than just one--a 9 period SMA (shown in green) and 45 period WMA (shown in red), atop the raw RSI (in black). Am happy to pay someone to help me with this if necessary. Many thanks.

Reply With Quote
  #7 (permalink)
 JayC 
San Diego, CA
 
Experience: Beginner
Platform: TOS, Sierra
Trading: Emini ES, Crude CL
Posts: 55 since Mar 2019
Thanks Given: 9
Thanks Received: 43

Let me know if this is what you wanted. I used the TOS RSI code as a starting point and added the averages at the bottom.

 
Code
declare lower;

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

plot RSI = 50 * (ChgRatio + 1);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", GetColor(1));
RSI.AssignValueColor(if RSI > over_Bought then RSI.color("OverBought") else if RSI < over_Sold then RSI.color("OverSold") else RSI.color("Normal"));
OverSold.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(8));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

input average1Type = AverageType.SIMPLE;
input average1Length = 9;
input average2Type = AverageType.WILDERS;
input average2Length = 45;

plot avg1 = MovingAverage(average1Type, RSI, average1Length);
avg1.setDefaultColor(Color.GREEN);
plot avg2 = MovingAverage(average2Type, RSI, average2Length);
avg2.setDefaultColor(Color.RED);

Reply With Quote
Thanked by:
  #8 (permalink)
SinSanDiego
Del Mar, CA
 
Posts: 4 since Mar 2021
Thanks Given: 2
Thanks Received: 0

Thank you, JayC. Your code works nicely. Wishing you good fortune with your trading.

Reply With Quote
  #9 (permalink)
AstroTuna
Chicago, IL
 
Posts: 12 since Jan 2020
Thanks Given: 0
Thanks Received: 8

Sometimes I like to overlay a 5 SMA on top of the RSI. The crosses often present some interesting opportunities.

Reply With Quote
  #10 (permalink)
peachfuzz
San Francisco CA USA
 
Posts: 5 since Sep 2015
Thanks Given: 2
Thanks Received: 0


Why can't I simply drag and drop the moving average on top of the RSI like it's done on other platform? Why do I even need to code for such a simple task?

Reply With Quote




Last Updated on September 8, 2022


© 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