Archives: RSM Indicator for ThinkorSwim

Status
Not open for further replies.
I have updated the MTF Labels script. The updated script needs to be added only once per chart and it gives you labels for RSM MTF for all timeframes higher than the current time frame. I did not want to add the previous script multiple times per chart and change the aggregation period.

Just add this script once per chart. No need for setting any parameters.

https://www.screencast.com/t/RLBkXhmjpo



Code:
#START OF RSI/Stochastic/MACD Confluence Strategy for ThinkOrSwim
# RSM_MTF_Labels
#
#CHANGELOG
# 2020.12.30 V2.1 @SuryaKiranC - Fork from @cos251 Version, to reduce the number of lines in code and optimize for performance.
#
# 2021.07.24 V1.2 @speedydooo - Updated script to work with all timeframes without
#                             - setting aggregation period. Shows RSM Labels for all
#                             - timeframes highter than the current chart
# 2020.12.11 V1.1 @cos251 - Added 2D, 3D, 4D, 1WK, 1MNTH Agg Period Labels
#
# 2020.12.02 V1.0 @cos251 - Added RSM signal calculation for following timeframes:
#                         - 1m, 2m, 5m, 15m, 30m, 1h, 2h, 4h, D
#                         - Label will be added to top of chart for every allowed TF
#                         - Label will read "TF:L(Long):S(Short):I(Idle)"
#                         - Label Color will be green, red or gray accordingly
#
#
#REQUIREMENTS - RSI Set to 7, EXPONENTIAL
#               Stoch Slow 14 and 3 WILDERS
#               MACD 12,26,9 WEIGHTED
#
#ORIGINAL REQUEST - @Joseph Patrick 18
#                 - Link: https://usethinkscript.com/threads/mimicking-power-x-strategy-by-markus-heitkoetter.4283/
#
#


DefineGlobalColor("UpTrend", Color.Green);
DefineGlobalColor("DownTrend", Color.Dark_RED);
DefineGlobalColor("NoTrend", Color.Dark_GRAY);

script RSM_ {

    input aP = AggregationPeriod.DAY;
    # RSI
    def lengthRSI = 7;
    def averageTypeRSI = AverageType.EXPONENTIAL;
    # Stochastic
    def over_boughtSt = 80;
    def over_soldSt = 20;
    def KPeriod = 14;
    def DPeriod = 3;
    input averageTypeStoch = AverageType.WILDERS;
    # MACD
    def fastLength = 12;
    def slowLength = 26;
    def MACDLength = 9;
    def averageTypeMACD = AverageType.WEIGHTED;

    ###############################################################
    ##########                 RSI                         #########
    ################################################################

    def NetChgAvg = MovingAverage(averageTypeRSI, close(period = aP) - close(period = aP)[1], lengthRSI);
    def TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(close(period = aP) - close(period = aP)[1]), lengthRSI);
    def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
    def RSI_ = 50 * (ChgRatio + 1);

    ################################################################
    ##########                 Stochastic Slow             #########
    ################################################################

    def SlowK_ = reference StochasticFull(over_boughtSt,  over_soldSt,  KPeriod,  DPeriod,  high(period = aP),  low(period = aP),  close(period = aP),  3, if (averageTypeStoch == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullK;
    def SlowD_ = reference StochasticFull(over_boughtSt,  over_soldSt,  KPeriod,  DPeriod,  high(period = aP),  low(period = aP),  close(period = aP),  3, if (averageTypeStoch == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullD;

    ################################################################
    ##########                 MACD                      ###########
    ################################################################

    def Value_ = MovingAverage(averageTypeMACD, close(period = aP), fastLength) - MovingAverage(averageTypeMACD, close(period = aP), slowLength);
    def Avg_ = MovingAverage(averageTypeMACD, Value_, MACDLength);
    def Diff_ = Value_ - Avg_;

    #################################################################
    ##########          Trend  & Labels                   #########
    #################################################################
    def UpTrend_ = if RSI_ >= 50 and SlowK_ >= 50 and Value_ > Avg_ then 1 else 0;
    def DownTrend_ = if RSI_ < 50 and SlowK_ < 50 and Value_ < Avg_ then 1 else 0;
    plot Trend_ = if UpTrend_ then 1 else if DownTrend_ then 0 else -1;

}

def currentPeriod = GetAggregationPeriod();
#def RSM;
def monthRSM;
def monthAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Month {
    monthRSM = RSM_(aP = AggregationPeriod.Month);
    monthAggregationPeriod = 1;
}
else {
    monthRSM = Double.NaN;
    monthAggregationPeriod = 0;
}
AddLabel(monthRSM and monthAggregationPeriod, "RSM-M",  if monthRSM == 1 then GlobalColor("UpTrend") else if monthRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));


def weekRSM;
def WeekAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.week {
    weekRSM = RSM_(aP = AggregationPeriod.Week);
    weekAggregationPeriod = 1;
}
else {
    weekRSM = Double.NaN;
    weekAggregationPeriod = 0;
}
AddLabel(weekRSM and weekAggregationPeriod, "RSM-W",  if weekRSM == 1 then GlobalColor("UpTrend") else if weekRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));


def fourdaysRSM;
def fourdaysAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_DAYS {
    fourdaysRSM = RSM_(aP = AggregationPeriod.FOUR_DAYS);
    fourdaysAggregationPeriod = 1;
}
else {
    fourdaysRSM = Double.NaN;
    fourdaysAggregationPeriod = 0;
}
AddLabel(fourdaysRSM and fourdaysAggregationPeriod, "RSM-4D",  if fourdaysRSM == 1 then GlobalColor("UpTrend") else if fourdaysRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));



def threedaysRSM;
def threedaysAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.THREE_DAYS {
    threedaysRSM = RSM_(aP = AggregationPeriod.THREE_DAYS);
    threedaysAggregationPeriod = 1;
}
else {
    threedaysRSM = Double.NaN;
    threedaysAggregationPeriod = 0;
}
AddLabel(threedaysRSM and threedaysAggregationPeriod, "RSM-3D",  if threedaysRSM == 1 then GlobalColor("UpTrend") else if threedaysRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));


def twodaysRSM;
def twodaysAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.TWO_DAYS {
    twodaysRSM = RSM_(aP = AggregationPeriod.TWO_DAYS);
    twodaysAggregationPeriod = 1;
}
else {
    twodaysRSM = Double.NaN;
    twodaysAggregationPeriod = 0;
}
AddLabel(twodaysRSM and twodaysAggregationPeriod, "RSM-2D",  if twodaysRSM == 1 then GlobalColor("UpTrend") else if twodaysRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));


def dayRSM;
def dayAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.DAY {
    dayRSM = RSM_(aP = AggregationPeriod.DAY);
    dayAggregationPeriod = 1;
}
else {
    dayRSM = Double.NaN;
    dayAggregationPeriod = 0;
}
AddLabel(dayRSM and dayAggregationPeriod, "RSM-D",  if dayRSM == 1 then GlobalColor("UpTrend") else if dayRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));



def fourhoursRSM;
def fourhoursAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS {
    fourhoursRSM = RSM_(aP = AggregationPeriod.FOUR_HOURS);
    fourhoursAggregationPeriod = 1;
}
else {
    fourhoursRSM = Double.NaN;
    fourhoursAggregationPeriod = 0;
}
AddLabel(fourhoursRSM and fourhoursAggregationPeriod, "RSM-4H",  if fourhoursRSM == 1 then GlobalColor("UpTrend") else if fourhoursRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));



def twohoursRSM;
def twohoursAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.TWO_HOURS {
    twohoursRSM = RSM_(aP = AggregationPeriod.TWO_HOURS);
    twohoursAggregationPeriod = 1;
}
else {
    twohoursRSM = Double.NaN;
    twohoursAggregationPeriod = 0;
}
AddLabel(twohoursRSM and twohoursAggregationPeriod, "RSM-2H",  if twohoursRSM == 1 then GlobalColor("UpTrend") else if twohoursRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));



def hourRSM;
def hourAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.HOUR {
    hourRSM = RSM_(aP = AggregationPeriod.HOUR);
    hourAggregationPeriod = 1;
}
else {
    hourRSM = Double.NaN;
    hourAggregationPeriod = 0;
}
AddLabel(hourRSM and hourAggregationPeriod, "RSM-1H",  if hourRSM == 1 then GlobalColor("UpTrend") else if hourRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));


def thirtyminsRSM;
def thirtyminAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN {
    thirtyminsRSM = RSM_(aP = AggregationPeriod.THIRTY_MIN);
    thirtyminAggregationPeriod = 1;
}
else {
    thirtyminsRSM = Double.NaN;
    thirtyminAggregationPeriod = 0;
}
AddLabel(thirtyminsRSM and thirtyminAggregationPeriod, "RSM-30m",  if thirtyminsRSM == 1 then GlobalColor("UpTrend") else if thirtyminsRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));


def twentyminsRSM;
def twentyminAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.TWENTY_MIN {
    twentyminsRSM = RSM_(aP = AggregationPeriod.TWENTY_MIN);
    twentyminAggregationPeriod = 1;
}
else {
    twentyminsRSM = Double.NaN;
    twentyminAggregationPeriod = 0;
}
AddLabel(twentyminsRSM and twentyminAggregationPeriod, "RSM-20m",  if twentyminsRSM == 1 then GlobalColor("UpTrend") else if twentyminsRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));


def tenminsRSM;
def tenminAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.TEN_MIN {
    tenminsRSM = RSM_(aP = AggregationPeriod.TEN_MIN);
    tenminAggregationPeriod = 1;
}
else {
    tenminsRSM = Double.NaN;
    tenminAggregationPeriod = 0;
}
AddLabel(tenminsRSM and tenminAggregationPeriod, "RSM-10m",  if tenminsRSM == 1 then GlobalColor("UpTrend") else if tenminsRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));



def fiveminsRSM;
def fiveminAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN {
    fiveminsRSM = RSM_(aP = AggregationPeriod.FIVE_MIN);
    fiveminAggregationPeriod = 1;
}
else {
    fiveminsRSM = Double.NaN;
    fiveminAggregationPeriod = 0;
}
AddLabel(fiveminsRSM and fiveminAggregationPeriod, "RSM-5m",  if fiveminsRSM == 1 then GlobalColor("UpTrend") else if fiveminsRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));



def fourminsRSM;
def fourminAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_MIN {
    fourminsRSM = RSM_(aP = AggregationPeriod.FOUR_MIN);
    fourminAggregationPeriod = 1;
}
else {
    fourminsRSM = Double.NaN;
    fourminAggregationPeriod = 0;
}
AddLabel(fourminsRSM and fourminAggregationPeriod, "RSM-4m",  if fourminsRSM == 1 then GlobalColor("UpTrend") else if fourminsRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));



def threeminsRSM;
def threeminAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.THREE_MIN {
    threeminsRSM = RSM_(aP = AggregationPeriod.THREE_MIN);
    threeminAggregationPeriod = 1;
}
else {
    threeminsRSM = Double.NaN;
    threeminAggregationPeriod = 0;
}
AddLabel(threeminsRSM and threeminAggregationPeriod, "RSM-3m",  if threeminsRSM == 1 then GlobalColor("UpTrend") else if threeminsRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));



def twominsRSM;
def twominAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.TWO_MIN {
    twominsRSM = RSM_(aP = AggregationPeriod.TWO_MIN);
    twominAggregationPeriod = 1;
}
else {
    twominsRSM = Double.NaN;
    twominAggregationPeriod = 0;
}
AddLabel(twominsRSM and twominAggregationPeriod, "RSM-2m",  if twominsRSM == 1 then GlobalColor("UpTrend") else if twominsRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));



def oneminsRSM;
def oneminAggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.MIN {
    oneminsRSM = RSM_(aP = AggregationPeriod.MIN);
    oneminAggregationPeriod = 1;
}
else {
    oneminsRSM = Double.NaN;
    oneminAggregationPeriod = 0;
}
AddLabel(oneminsRSM and oneminAggregationPeriod, "RSM-1m",  if oneminsRSM == 1 then GlobalColor("UpTrend") else if oneminsRSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));
 

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

I have updated the MTF Labels script. The updated script needs to be added only once per chart and it gives you labels for RSM MTF for all timeframes higher than the current time frame. I did not want to add the previous script multiple times per chart and change the aggregation period.

Just add this script once per chart. No need for setting any parameters.

https://www.screencast.com/t/RLBkXhmjpo
We had this version initially, Well a version like this, reasons we walked away from this, is to give the flexibility for users to choose the timeframes they are more interested in, as well as conserve the system resources by not initializing and tone of variables that are not needed and consume more system resources.

Personally the final straw for me was, when there is a code change, the amount of places you have to make changes and make sure the changes are done in all the places to get it right. Nevertheless, I Like it.

Thanks for your Contribution.

-S
 
We had this version initially, Well a version like this, reasons we walked away from this, is to give the flexibility for users to choose the timeframes they are more interested in, as well as conserve the system resources by not initializing and tone of variables that are not needed and consume more system resources.

Personally the final straw for me was, when there is a code change, the amount of places you have to make changes and make sure the changes are done in all the places to get it right. Nevertheless, I Like it.

Thanks for your Contribution.

-S

All of the logic is still in the function which has been untouched. I have just repeated the timeframes and added labels if the RSM is true for those periods. I don't anticipate that code ever changing (never say never though).

That said, if someone just wants one timeframe then they can use the original script. I personally like MTF to show me all timeframes as I trade on multi-timeframe charts so it's easier for me that way to have visibility. I guess just depends on the user's preference.
 
First of all, this is awesome, been looking at the PowerX strategy for awhile and just getting started with TOS and happened upon this. I do have a question though. When I run this script on ticker COST, it seems to be showing "gray" color on specific days when the 3 indicators seem to be pretty clearly in agreement and showing uptrend. Screenshot is below, see the red ovals, those days are gray but the 3 indicators seem to all be in agreement. When I go to the script and look at the below:


AssignPriceColor(if paintBars and RSI > 50 and SlowK > 50 and Value > Avg then Color.GREEN else if paintBars and RSI < 50 and SlowK < 50 and Value < Avg then Color.RED else if paintBars then Color.DARK_GRAY else Color.CURRENT);

If I remove the 'and Value > Avg' then they go green, which seems to indicate the false signal is with the MACD. I can't figure out what is wrong with the MACD calculation though.

Any idea what could be the problem?
 
AssignPriceColor(if paintBars and RSI > 50 and SlowK > 50 and Value > Avg then Color.GREEN else if paintBars and RSI < 50 and SlowK < 50 and Value < Avg then Color.RED else if paintBars then Color.DARK_GRAY else Color.CURRENT);

If I remove the 'and Value > Avg' then they go green, which seems to indicate the false signal is with the MACD. I can't figure out what is wrong with the MACD calculation though.

Any idea what could be the problem?
You would have to tune your lower study parameter to match RSM parameters.

R -RSI 7, Avg Type :Exponential
S - Stochastic K 14, D 3, Avg Type :WILDERS
M - Avg Type: WEIGHTED

On those specific candles, atleast one of these is below respective Mid line, hence the gray candle. As per the Strategy Definition.
 
Perfect.
Code for Watchlist Posed per Request.

Code:
# RSM_WL
#
#CHANGELOG
# 2021.1.31 - V1.0 @SuryaKiranC - RSM Watch List study - to be used as watchlist:
#              Based on @Cos251 RSM_SCAN Code.
#            - Stocks currently in UpTrend
#            - Stocks currently in DownTrend
#            - Stocks where UpTrendJustSarted - first bar of UpTrend for scanend TF
#            - Stocks where DownTrendJustStarted - first bar of DownTrend for scanned TF
#            - Stocks where UpTredJustEnded - first NO Trend bar after UpTrend
#            - Stocks where DownTrendJustEnded - first NO Trend bar after DownTrend
#            - Recommend using default studies for SCANS of RSI, Stochastics or MACD for efficiency
#          
#REQUIREMENTS - RSI Set to 7, EXPONENTIAL
#               Stoch Slow 14 and 3 WILDERS
#               MACD 12,26,9 WEIGHTED
#
#
#CREDITS
# requesed by "@Joseph Patrick 18"
#
#LINK
# https://rockwell-files.s3.amazonaws.com/PXCompanionGuide2ndEd_cover.pdf
# Markus Heikoetter who is the author of the Power X Strategy
# https://usethinkscript.com/threads/mimicking-power-x-strategy-by-markus-heitkoetter.4283/
#
################################################################
##########                 RSI                         #########
################################################################

def lengthRSI = 7;
def price = close;
def averageTypeRSI = AverageType.EXPONENTIAL;
def NetChgAvg = MovingAverage(averageTypeRSI, price - price[1], lengthRSI);
def TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(price - price[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

################################################################
##########                 Stochastic Slow             #########
################################################################
def over_boughtSt = 80;
def over_soldSt = 20;
def KPeriod = 14;
def DPeriod = 3;
def priceH = high;
def priceL = low;
def priceC = close;
def averageTypeStoch = AverageType.WILDERS;
def SlowK = reference StochasticFull(over_boughtSt,  over_soldSt,  KPeriod,  DPeriod,  priceH,  priceL,  priceC,  3, if (averageTypeStoch == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullK;
def SlowD = reference StochasticFull(over_boughtSt,  over_soldSt,  KPeriod,  DPeriod,  priceH,  priceL,  priceC,  3, if (averageTypeStoch == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullD;

#################################################################
############           MACD Calculation                 #########
#################################################################
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
def averageTypeMACD = AverageType.WEIGHTED;
def Value = MovingAverage(averageTypeMACD, close, fastLength) - MovingAverage(averageTypeMACD, close, slowLength);
def Avg = MovingAverage(averageTypeMACD, Value, MACDLength);
def Diff = Value - Avg;

#################################################################
############          SCAN Variables                    #########
#################################################################

# If you want to scan for stocks that are not in either trend you can add two filters and scan for false for both conditions

# The UpTrend and DownTrend plots can be used to scan for stocks that are currently in that trend
def UpTrend = if RSI > 50 and SlowK > 50 and Value > Avg then 1 else 0;
def DownTrend = if RSI < 50 and SlowK < 50 and Value < Avg then 1 else 0;

# The UpTrendJustStarted and DownTrendJustStarted plots can be used to find stocks that have just started
# a trend in either direction
def UpTrendJustStartedBool = if RSI > 50 and SlowK > 50 and Value > Avg then 1 else 0;
def DownTrendJustStartedBool = if RSI < 50 and SlowK < 50 and Value < Avg then 1 else 0;
def UpTrendJustStarted = if UpTrendJustStartedBool == 1 and UpTrendJustStartedBool[1] == 0 then 1 else 0;
def DownTrendJustStarted = if DownTrendJustStartedBool == 1 and DownTrendJustStartedBool[1] == 0 then 1 else 0;
def UpTrendJustEnded = if UpTrendJustStartedBool[1] == 1 and UpTrendJustStartedBool == 0 then 1 else 0;
def DownTrendJustEnded = if DownTrendJustStartedBool[1] == 1 and DownTrendJustStartedBool == 0 then 1 else 0;

def GetTrend = if UptrendJustStarted then 3 else if Uptrend then 2 else if UpTrendJustEnded then 1 else if DownTrendJustStarted then -1 else if DownTrend then -2 else if DownTrendJustEnded then -3 else 0;

AddLabel (yes, if GetTrend == 3 then "UpTrendJustStarted" else if GetTrend == 2 then "UpTrend" else if GetTrend == 1 then "UpTrendJustEnded" else if GetTrend == -1  then "DownTrendJustStarted" else if GetTrend == -2  then "DownTrend" else if GetTrend == -3 then "DownTrendJustEnded" else "NoTrend",Color.BLACK);

AssignBackgroundColor( if GetTrend == 3 then Color.LIGHT_GREEN else if GetTrend == 2 then Color.Green else if GetTrend == -1 then Color.LIGHT_RED else if GetTrend == -2 then Color.RED else Color.WHITE);

Version 1.1 For watch list with BarCount Since Up/Down Trend has started. Only for those 2 trends coded for now. Please use Version 1.0 if you have performance concerns, I haven't tested the code during market hours yet.

Code:
# RSM_WL
#
#CHANGELOG
# 2021.3.5  - V1.1 @SuryaKiranC - BarCount for how long Up/Down Trend is in progress.
# 2021.1.31 - V1.0 @SuryaKiranC - RSM Watch List study - to be used as watchlist:
#              Based on @Cos251 RSM_SCAN Code.
#            - Stocks currently in UpTrend
#            - Stocks currently in DownTrend
#            - Stocks where UpTrendJustSarted - first bar of UpTrend for scanend TF
#            - Stocks where DownTrendJustStarted - first bar of DownTrend for scanned TF
#            - Stocks where UpTredJustEnded - first NO Trend bar after UpTrend
#            - Stocks where DownTrendJustEnded - first NO Trend bar after DownTrend
#            - Recommend using default studies for SCANS of RSI, Stochastics or MACD for efficiency
#            
#REQUIREMENTS - RSI Set to 7, EXPONENTIAL
#               Stoch Slow 14 and 3 WILDERS
#               MACD 12,26,9 WEIGHTED
#
#
#CREDITS
# requesed by "@Joseph Patrick 18"
#
#LINK
# https://rockwell-files.s3.amazonaws.com/PXCompanionGuide2ndEd_cover.pdf
# Markus Heikoetter who is the author of the Power X Strategy
# https://usethinkscript.com/threads/mimicking-power-x-strategy-by-markus-heitkoetter.4283/
#
################################################################
##########                 RSI                         #########
################################################################

def lengthRSI = 7;
def price = close;
def averageTypeRSI = AverageType.EXPONENTIAL;
def NetChgAvg = MovingAverage(averageTypeRSI, price - price[1], lengthRSI);
def TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(price - price[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

################################################################
##########                 Stochastic Slow             #########
################################################################
def over_boughtSt = 80;
def over_soldSt = 20;
def KPeriod = 14;
def DPeriod = 3;
def priceH = high;
def priceL = low;
def priceC = close;
def averageTypeStoch = AverageType.WILDERS;
def SlowK = reference StochasticFull(over_boughtSt,  over_soldSt,  KPeriod,  DPeriod,  priceH,  priceL,  priceC,  3, if (averageTypeStoch == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullK;
def SlowD = reference StochasticFull(over_boughtSt,  over_soldSt,  KPeriod,  DPeriod,  priceH,  priceL,  priceC,  3, if (averageTypeStoch == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullD;

#################################################################
############           MACD Calculation                 #########
#################################################################
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
def averageTypeMACD = AverageType.WEIGHTED;
def Value = MovingAverage(averageTypeMACD, close, fastLength) - MovingAverage(averageTypeMACD, close, slowLength);
def Avg = MovingAverage(averageTypeMACD, Value, MACDLength);
def Diff = Value - Avg;



#################################################################
############          SCAN Variables                    #########
#################################################################

# If you want to scan for stocks that are not in either trend you can add two filters and scan for false for both conditions

# The UpTrend and DownTrend plots can be used to scan for stocks that are currently in that trend
def UpTrend = if RSI > 50 and SlowK > 50 and Value > Avg then 1 else 0;
def DownTrend = if RSI < 50 and SlowK < 50 and Value < Avg then 1 else 0;

def bnumUp;
def bnumDown;
def closeUpTrendStart;
def closeDownTrendStart;
def UpTrendBarCount;
def DownTrendBarCount;
if UpTrend and (!UpTrend[1] or DownTrend[1]) {
    bnumUp = BarNumber();
    bnumDown = 0;
    closeUpTrendStart = close;
    closeDownTrendStart = 0;
    UpTrendBarCount = 1;
    DownTrendBarCount = 0;
} else if UpTrend {
    bnumUp = bnumUp[1];
    bnumDown = 0;
    closeUpTrendStart = closeUpTrendStart[1];
    closeDownTrendStart = 0;
    UpTrendBarCount = UpTrendBarCount[1] + 1;
    DownTrendBarCount = 0;
} else if DownTrend and (!DownTrend[1] or UpTrend[1]) {
    bnumUp = 0;
    bnumDown = BarNumber();
    closeDownTrendStart = close;
    closeUpTrendStart = 0;
    UpTrendBarCount = 0;
    DownTrendBarCount = 1;
} else if DownTrend {
    bnumDown = bnumDown[1];
    closeDownTrendStart = closeDownTrendStart[1];
    DownTrendBarCount = DownTrendBarCount[1] + 1;
    bnumUp = 0;
    closeUpTrendStart = 0;
    UpTrendBarCount = 0;
} else {
    bnumUp = 0;
    bnumDown = 0;
    closeUpTrendStart = 0;
    closeDownTrendStart = 0;
    UpTrendBarCount = 0;
    DownTrendBarCount = 0;
}

# The UpTrendJustStarted and DownTrendJustStarted plots can be used to find stocks that have just started
# a trend in either direction
def UpTrendJustStartedBool = if RSI > 50 and SlowK > 50 and Value > Avg then 1 else 0;
def DownTrendJustStartedBool = if RSI < 50 and SlowK < 50 and Value < Avg then 1 else 0;
def UpTrendJustStarted = if UpTrendJustStartedBool == 1 and UpTrendJustStartedBool[1] == 0 then 1 else 0;
def DownTrendJustStarted = if DownTrendJustStartedBool == 1 and DownTrendJustStartedBool[1] == 0 then 1 else 0;
def UpTrendJustEnded = if UpTrendJustStartedBool[1] == 1 and UpTrendJustStartedBool == 0 then 1 else 0;
def DownTrendJustEnded = if DownTrendJustStartedBool[1] == 1 and DownTrendJustStartedBool == 0 then 1 else 0;

def GetTrend = if UptrendJustStarted then 3 else if Uptrend then 2 else if UpTrendJustEnded then 1 else if DownTrendJustStarted then -1 else if DownTrend then -2 else if DownTrendJustEnded then -3 else 0;

AddLabel (yes, if GetTrend == 3 then "UpTrendJustStarted" else if GetTrend == 2 then "BC:" + UpTrendBarCount + " UpTrend" else if GetTrend == 1 then "UpTrendJustEnded" else if GetTrend == -1  then "DownTrendJustStarted" else if GetTrend == -2  then "BC:" + DownTrendBarCount + " DownTrend" else if GetTrend == -3 then "DownTrendJustEnded" else "NoTrend",Color.BLACK);

AssignBackgroundColor( if GetTrend == 3 then Color.LIGHT_GREEN else if GetTrend == 2 then Color.Green else if GetTrend == -1 then Color.LIGHT_RED else if GetTrend == -2 then Color.RED else Color.WHITE);

I have to admit many months ago SuryaKiranC provided me with these three items:

-The RSM scanner.
-The RSM Indicators.
-I'm about to work on and experiment with the strategy section that I have yet to mess with.

I have only been trading for around 1.5 years and this layout with the RSM lowers specifically has been an AMPLE help learning how things worked. I actually can not believe that it helps me so much.

No single indicator will be the holy grail, we all get that, but this was one of the only indicator combos that actually gave me a fighting chance with my style of trading.

I also noticed that when the dark blue bars from the standard squeeze indicator pop up after I'm already in and all colors are aligned on the RSM lowers I noticed that exiting at the dark blue bars helped cut some of the losses at the top ends (so squeeze bars go from light blue to dark blue) it allows me to exit quickly and avoid the heavy pullbacks too.

I know it is all probably confirmation bias but it seems to be working over the long term.

The first post had to say thank you for this because it really did help me get started with trading around the time of the march 2020 dip somewhere around that time.

Look forward to starting from the ground up and learning this stuff.

Michael Garcia
 
Last edited:
Is there ANY WAY THE RSM UPPER INDICATOR CAN USED ON TOS PHONE APP?? How to show then all green indicator are red or green??

No, it won’t work with the TOS app. I’ve tried. Then again, the last thing in the world I am is a thinkscript master. Maybe someone else has a solution but I haven’t been able to figure that one out but then again I’ve never had a detrimental need for such compatibility.
 
Is there ANY WAY THE RSM UPPER INDICATOR CAN USED ON TOS PHONE APP?? How to show then all green indicator are red or green??

@APOT7 Unfortunately, Thinkorswim Mobile doesn't support an entire subset of Look-and-Feel functions needed for this indicator, not to mention the indicators overall complexity...
 
All I gotta say is I love this indicator !! I went and read back on the guys strategy that this thing is built around and makes total sense. Completely awesome and helps confirm levels and points of support\resistance. Combining it with Fib Retrace as well as other trend indicators makes this thing dangerous !!
 
All I gotta say is I love this indicator !! I went and read back on the guys strategy that this thing is built around and makes total sense. Completely awesome and helps confirm levels and points of support\resistance. Combining it with Fib Retrace as well as other trend indicators makes this thing dangerous !!
I have been using it for the ES both 2000 Tics and 30 Minute. It's powerful no question about it.

Markus has a book he wrote about the Power X Strategy, you can get it for shipping and handling of $4.95, I highly recommend you read it. His name is Markus Heitkoetter Google him, also is on youtube.
 
I have been using it for the ES both 2000 Tics and 30 Minute. It's powerful no question about it.

Markus has a book he wrote about the Power X Strategy, you can get it for shipping and handling of $4.95, I highly recommend you read it. His name is Markus Heitkoetter Google him, also is on youtube.
I tested it out on Friday on replay for a random day on ES, played the 5 min chart with the 10\50 EMA crossover\VWAP strategy and on 3 separate days with this indicator as well, crushed it on the random past days that I tested (I did not peek beforehand). I did see one of his youtube vids where he covered the strategy, straightforward and easy to listen to.

I applied it with the Fib retrace strategy on SPY today and paid attention to my other trend indicators and picked up %37 gain. Would've been more but setup a fib retrace and SPY broke\closed under the 38.2% line so I closed out. All in all it has worked great and I've used it to confirm one other trade I entered last week as well as one I entered today.
 
I tested it out on Friday on replay for a random day on ES, played the 5 min chart with the 10\50 EMA crossover\VWAP strategy and on 3 separate days with this indicator as well, crushed it on the random past days that I tested (I did not peek beforehand). I did see one of his youtube vids where he covered the strategy, straightforward and easy to listen to.

I applied it with the Fib retrace strategy on SPY today and paid attention to my other trend indicators and picked up %37 gain. Would've been more but setup a fib retrace and SPY broke\closed under the 38.2% line so I closed out. All in all it has worked great and I've used it to confirm one other trade I entered last week as well as one I entered today.
If your on Ben's Discord Channel it's posted today my setup's.
 
Perfect.
Code for Watchlist Posed per Request.
If I wanted to modify this code to provide a watchlist indicator for trends on the weekly chart rather than the daily, what changes would need to be made? Would it just be a matter of multiplying all the length numbers by 7 or would there be a better way to do it.
 
If I wanted to modify this code to provide a watchlist indicator for trends on the weekly chart rather than the daily, what changes would need to be made? Would it just be a matter of multiplying all the length numbers by 7 or would there be a better way to do it.
Nothing, Just change the Timeframe on WL Column from Day to Week.
 
I am sorry if I am doing something idiotic and missing it - do you think you could screenshot the location for me? Even TOS documentation of the watchlist doesn't mention such a setting.
Simply right click on column and select edit code on the top left you should see the timeframe. Set it to weekly.
 
Last edited:
Status
Not open for further replies.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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