RSM Indicator for ThinkorSwim

cos251

Well-known member

Update - Version 1.9
Added Feature (thanks to @SleepZ)
  1. Added feature to only plot current ADR Targets and stoploss
Y0XlbTF.png


Update - Version 1.8
Fixed the following:
  1. Plot Up/Down arrows on weekly chart
  2. Plot uptrend/downtrend stoploss target and price targets on weekly chart
  3. Adjusted shading and trend detection to be greater than 50 or less than 50 (not equal to) per original strategy (thx community)


Update - Version 1.7
A quick update to this indicator for those of you that may be using it. See below for changes in this version.

Added the following:
  1. Added additional price targets (7, 8, 9) as an input option (ShowExtraTargets789) - can be turned on and off independent of targets 1-6 but dependent on trend
  2. Added ADX triangle plot to stoploss in either direction. Indicates if ADX is greater than previous ADX[1] and denotes if ADR has crossed above ADXR for trend confirmation/strength
    1. ADX Uptrend - White = ADX > ADX[1], RED = ADX crossed above ADXR, CYAN = ADX > 35
    2. ADX DownTrend - Purple = ADX > ADX[1], GREEN = ADX crossed above ADXR, YELLOW = ADX > 35
    3. Added ability to show ADX triangles without plotting ADR Targets and Shading

CHuyWZE.png


After quite a bit of collaboration from several members - we wanted to provide a central reference point for this indicator. The original request for this write up came from @Joseph Patrick 18 to replicate a well known strategy known as Power X. For the purposes of this indicator, it is being referred to as RSM (RSI, Stochastic,MACD) Indicator.

I'd like to thank the following members for their contributions: @Joseph Patrick 18 , @SuryaKiranC, @RickAns, @TradeUp (and many others, sorry if I forgot you)

Basic requirements for this indicator:
  1. Use RSI, Stochastic and MACD standard indicators (with minor settings tweak) to identify trends
  2. RSI - Set to 7, EXPONENTIAL MOVING AVERAGE
  3. Stochastic Slow- Set to 14 and 3, WILDERS AVERAGE
  4. MACD - Set to 12,26,9 - WEIGHTED AVERAGE
  5. Paint Candles accordintly - (GREEN/UP, RED/DOWN)
Trend Identification
UpTrend = RSI > 50, SlowK > 50, MACD Value > Avg - (Candle color green)
DownTrend = RSI < 50, SlowK < 50, MACD Value < Avg - (Candle color red)
All other instances, candle color gray

Reference material for strategy: https://rockwell-files.s3.amazonaws.com/PXCompanionGuide2ndEd_cover.pdf

Indicators Available (See below for code). The following scripts are provided for this indicator:
  1. RSM Upper - works on any TF and TICK Charts
    1. Color candles, Plots Arrows and displays informational labels
    2. Most settings can be turned off if desired
  2. RSM Lower
    1. 3 Indicators in 1 - can be added to chart seperatly and choose indicator desired
    2. Can plot RSI, Stochastic, RSI & Stochastic, or MACD Only as lower study with shading and candle painting
  3. RSM MTF
    1. Adds Labels for ALL TF's to show current status of RSM Signal
  4. RSM SCAN - Use to scan for the following:
    1. Stocks currently in UpTrend
    2. Stocks just starting UpTrend
    3. Stocks currently in DownTrend
    4. Stocks just starting DownTrend
* - Quick personal note - thanks so much for letting me work on this project and for you patience. I had a chance to learn quite a bit and hopefully improve my trading in the process. Great community here!!!!!!!!!!!

Disclaimer
This indicator may or may not be suitable for you. Constructive criticism welcomed in order to improve. Please report any bugs so we can continue to improve it.

RSM Upper

Features
  1. Paint Bars (Green, Red, Gray)
  2. Shade chart area per trend
  3. Select between trade type (Long,Short,Both)
  4. Dynamic calculation of ADR/ATR at moment of trend start
  5. Select between ADR/ATR for target and stop loss calculations
  6. Plot ADR/ATR target lines while trend is active (on/off)
    1. Plot 3 targets up/down by default
  7. Plot additional targets (4-6) if desired (on/off)
  8. Shade the ADR/ATR zones (on/off)
  9. Stop loss multiplier selection
  10. Show Labels for first 3 targets
  11. Show Labels for Trend info

nxdYhxi.png


Code:
#START OF RSI/Stochastic/MACD Confluence Strategy for ThinkOrSwim
#RSM_STANDARD_UPPER
#
#CHANGELOG
#
# 2021.05.11 V1.9 @cos251 - Added feature to plot only current ADR Targets and Stoploss
#                            - Feature credit goes to @SleepyZ (thx)
#
# 2021.05.04 V1.8 @cos251 - Fixed >= error to match original strategy as noted by community
#                            - Fixed UpTrend and DownTrend Arrows to display on weekly chart
#                            - Fixed StopLoss and UpTrend/DownTrend targets to display on weekly chart
#
# 2021.04.13 V1.7 @cos251 - Added additional price targets (7, 8, 9) as an input option (ShowExtraTargets789) -
#                            - can be turned on and off independent of targets 1-6 but dependent on trend
#                         - Added ADX triangle plot to stoploss in either direction.  Indicates if ADX #                            - is greater than previous ADX[1] and denotes if ADR has crossed
#                            - above ADXR for trend confirmation/strength
#                            - ADX Uptrend - White = ADX > ADX[1], RED = ADX crossed above ADXR, CYAN = ADX > 35
#                            - ADX DownTrend - Purple = ADX > ADX[1], GREEN = ADX crossed above ADXR, YELLOW = ADX > 35
#
# 2021.01.15 V1.6 @SuryaKirnaC
#                         - Modifed ADR Zones shading colors
#                         - Adjusted Indicator and target labels for space
#                         - Made audible alerts user configurable via settings
#
# 2021.01.04 V1.5 @cos251 - Fixed long, short ADR Zone plots to match TradeType selection (Long, Short, BOTH)
#                         - will only plot as selected
#
# 2020.12.21 V1.4 @cos251 - Added input "plotADR"
#                            - plots dynamic ATR/ADR targets- default plots 3 targets - can be turned off by setting #                              "plotADR" to no
#                         - Added input "showExtraTargets"
#                            -  - plots dynamic ATR/ADR targets- for targets 4, 5, and 6
#                         - Added input "showADRZones"
#                            - Dynamic shading of ATR/ADR targets - can be turned off in settings using "showADRZones"
#                         - Added dynamic calculation of both ATR and ADR. User can select between ATR and ADR in #                              settings
#                         - Added input "showADRLabels"
#                            - Added Dynamic Target labels for UpTrend or DownTrend; they will be green or red #                              depending on Up or Down trend
#                         - Added input "showTodayOnly"
#                            - Added option to display shaded ADR/ATR zones for today only "showTodayOnly"
#                            - if set to no - ADR/ATR plots will be plotted for all available data on chart
#                         - Added ability to plot ATR or ADR on DAY chart - MUST TURN OFF "showTodayOnly"
#                         - Added Labels that can be used for "debug" - MUST change "debug" setting to yes
#                         - Added Trend information labels that can be turned on/off
#                       
#
# 2020.11.30 V1.3 @cos251 - Stripped down TICK Version; No ADR since time based aggregation period do not work on TICK #                           Charts
#
# 2020.11.30 V1.2 @cos251 - Add ADR plots and shading per request; will tweak these settings to improve overall
#                           options
# 2020.11.12 V1.1 @cos251 - Changed from strategy to standard study. Added Green Arrow UP
#                           and Red Arrow down when trend starts.  Added option to change to high
#                           timeframe but this WILL repaint; if used, should be used with other
#                           indicators to confirm an entry/exit.
#
# 2020.10.27 V1.0 @cos251 - Added RSI, StochasticSlow and MACD to same indicator
#                         - also calculates MACD;
#                         - Will shade the lower plot area of the following conditions are met
#                           Shade GREEN = RSI > 50 and SlowK > 50 and (macd)Value > (macd)Avg
#                           Shade RED = RSI < 50 and SlowK < 50 and (macd)Value < (macd)Avg
#
#               
#REQUIREMENTS - RSI Set to 7, EXPONENTIAL
#               Stoch Slow 14 and 3 WILDERS
#               MACD 12,26,9 WEIGHTED


declare upper;
################################################################
##########                 Variables                   #########
################################################################

input paintBars = yes;
input showRSMShade = no;
input tradetype = { "long", "short", default "both" };
input rangeType = { default "ADR", "ATR" };
input stopLossMultiplier = 1.0;
input plotADR = yes;
input showADRZones = yes;
input showCurrentTargetsOnly = yes;
input showTodayOnly = yes;
input showTrendLabels = no;
input showADRLabels = no;
input showExtraTargets = no;
input showExtraTargets789 = no;
input showADXTriangle = yes;
input lengthADX = 21;
input showIndicatorLabels = no;
input audibleAlerts = yes;
input debug = no; # change to "NO" after testing



################################################################
##########              ATR/ADR Calc                   #########
################################################################
input ATRlength = 14;
input ATRaverageType = AverageType.WILDERS;
def Range;
if rangeType == rangeType.ATR {
    Range = MovingAverage(ATRaverageType, TrueRange(high, close, low), ATRlength);
} else {
    Range = Average(high - low, 7);
}

################################################################
##########         Booleans Set for Plot Use           #########
################################################################
def afterStart;
def beforeEnd;
def today;
def openPrice;
if GetAggregationPeriod() <= AggregationPeriod.DAY {
    afterStart = GetTime() > RegularTradingStart(GetYYYYMMDD());
    beforeEnd = GetTime() < RegularTradingEnd(GetYYYYMMDD());
    today = if GetLastDay() == GetDay() then 1 else Double.NaN;
    openPrice = DailyOpen();
} else {
    afterstart = Double.NaN;
    beforeEnd = Double.NaN;
    today = Double.NaN;
    openPrice = Double.NaN;
}

plot DailyO = if openPrice then openPrice else Double.NaN;
AddLabel(if debug then yes else no, "Day = :" + today);
AddLabel(if debug then yes else no, "Day = :" + GetDay());


################################################################
##########           ADX Indicator Reference           #########
################################################################
def ADX = reference ADX();
def ADXR = (ADX + ADX[lengthADX - 1]) / 2;

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


################################################################
##########                 Stochastic Slow             #########
################################################################
input over_boughtSt = 80;
input over_soldSt = 20;
input KPeriod = 14;
input DPeriod = 3;
input averageTypeStoch = AverageType.WILDERS;
def SlowK = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high, low, close, 3, averageTypeStoch).FullK;
def SlowD = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high, low, close, 3, averageTypeStoch).FullD;



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



################################################################
##########         Assign Price Color                  #########
################################################################
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);

#################################################################
#####   Up/Down Trend Check/SCAN Variables              #########
#################################################################
plot UpTrend = if RSI > 50 and SlowK > 50 and Value > Avg then 1 else 0;
plot DownTrend = if RSI < 50 and SlowK < 50 and Value < Avg then 1 else 0;
UpTrend.Hide();
DownTrend.Hide();
plot upArrow = if UpTrend == 1 and UpTrend[1] == 0 and (tradetype == tradetype.long or tradetype == tradetype.both) then low else Double.NaN;
upArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
upArrow.SetDefaultColor(Color.GREEN);
upArrow.SetLineWeight(4);
plot downArrow = if DownTrend == 1 and DownTrend[1] == 0 and (tradetype == tradetype.short or tradetype == tradetype.both) then high else Double.NaN;
downArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
downArrow.SetDefaultColor(Color.RED);
downArrow.SetLineWeight(4);

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;
}
def c;
if BarNumber() == bnumUp or BarNumber() == bnumDown {
    c = Range;
} else if UpTrend or DownTrend {
    c = c[1];
} else {
    c = 0;
}
AddLabel(if debug then yes else no, "Current Bar:" + BarNumber());
AddLabel(if debug then yes else no, "C:" + c);
AddLabel( if debug then yes else no, "PlotADR: " + plotADR);
AddLabel( if debug then yes else no, "TodayOnly: " + showTodayOnly);


#################################################################
############        ADR/ATR Targets Shading              #########
#################################################################
def up = if UpTrend   then bnumUp   else Double.NaN;
def dn = if DownTrend then bnumDown else Double.NaN;
# - UpTrend Targets and StopLoss
plot UpTrendStopLoss = if showCurrentTargetsOnly == yes and (bnumUp < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and !showTodayOnly then closeUpTrendStart - (c * stopLossMultiplier) else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeUpTrendStart - c else Double.NaN;
plot oneADRPlus = if showCurrentTargetsOnly == yes and (bnumUp < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and !showTodayOnly then closeUpTrendStart + (c * 1) else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeUpTrendStart + c else Double.NaN;
plot twoADRPlus = if showCurrentTargetsOnly == yes and (bnumUp < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and !showTodayOnly then closeUpTrendStart + (c * 2) else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeUpTrendStart + (c * 2) else Double.NaN;
plot threeADRPlus = if showCurrentTargetsOnly == yes and (bnumUp < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and !showTodayOnly then closeUpTrendStart + (c * 3) else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeUpTrendStart + (c * 3) else Double.NaN;
plot fourADRPlus = if showCurrentTargetsOnly == yes and (bnumUp < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and !showTodayOnly and showExtraTargets then closeUpTrendStart + (c * 4) else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd and showExtraTargets then closeUpTrendStart + (c * 4) else Double.NaN;
plot fiveADRPlus = if showCurrentTargetsOnly == yes and (bnumUp < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and !showTodayOnly and showExtraTargets then closeUpTrendStart + (c * 5) else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd and showExtraTargets then closeUpTrendStart + (c * 5) else Double.NaN;
plot sixADRPlus = if showCurrentTargetsOnly == yes and (bnumUp < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and !showTodayOnly and showExtraTargets then closeUpTrendStart + (c * 6) else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd and showExtraTargets then closeUpTrendStart + (c * 6) else Double.NaN;
plot sevenADRPlus = if showCurrentTargetsOnly == yes and (bnumUp < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and !showTodayOnly and showExtraTargets and showExtraTargets789 then closeUpTrendStart + (c * 7) else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd and showExtraTargets and showExtraTargets789 then closeUpTrendStart + (c * 7) else Double.NaN;
plot eightADRPlus = if showCurrentTargetsOnly == yes and (bnumUp < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and !showTodayOnly and showExtraTargets and showExtraTargets789 then closeUpTrendStart + (c * 8) else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd and showExtraTargets and showExtraTargets789 then closeUpTrendStart + (c * 8) else Double.NaN;
plot nineADRPlus = if showCurrentTargetsOnly == yes and (bnumUp < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and !showTodayOnly and showExtraTargets and showExtraTargets789 then closeUpTrendStart + (c * 9) else if (tradetype == tradetype.both or tradetype == tradetype.long) and UpTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd and showExtraTargets and showExtraTargets789 then closeUpTrendStart + (c * 9) else Double.NaN;

# - DownTrend Targets and StopLoss
plot DownTrendStopLoss = if showCurrentTargetsOnly == yes and (bnumDown < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and !showTodayOnly then closeDownTrendStart + (c * stopLossMultiplier) else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeDownTrendStart + c else Double.NaN;
plot oneADRMinus = if showCurrentTargetsOnly == yes and (bnumDown < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and !showTodayOnly then closeDownTrendStart - c else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeDownTrendStart - c else Double.NaN;
plot twoADRMinus = if showCurrentTargetsOnly == yes and (bnumDown < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and !showTodayOnly then closeDownTrendStart - (c * 2) else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeDownTrendStart - (c * 2) else Double.NaN;
plot threeADRMinus = if showCurrentTargetsOnly == yes and (bnumDown < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and !showTodayOnly then closeDownTrendStart - (c * 3) else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd then closeDownTrendStart - (c * 3) else Double.NaN;
plot fourADRMinus = if showCurrentTargetsOnly == yes and (bnumDown < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and !showTodayOnly and showExtraTargets then closeDownTrendStart - (c * 4) else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd  and showExtraTargets then closeDownTrendStart - (c * 4) else Double.NaN;
plot fiveADRMinus = if showCurrentTargetsOnly == yes and (bnumDown < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and !showTodayOnly and showExtraTargets then closeDownTrendStart - (c * 5) else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd  and showExtraTargets then closeDownTrendStart - (c * 5) else Double.NaN;
plot sixADRMinus = if showCurrentTargetsOnly == yes and (bnumDown < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and !showTodayOnly and showExtraTargets then closeDownTrendStart - (c * 6) else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd  and showExtraTargets then closeDownTrendStart - (c * 6) else Double.NaN;
plot sevenADRMinus = if showCurrentTargetsOnly == yes and (bnumDown < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and !showTodayOnly and showExtraTargets and showExtraTargets789 then closeDownTrendStart - (c * 7) else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd  and showExtraTargets and showExtraTargets789 then closeDownTrendStart - (c * 7) else Double.NaN;
plot eightADRMinus = if showCurrentTargetsOnly == yes and (bnumDown < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and !showTodayOnly and showExtraTargets and showExtraTargets789 then closeDownTrendStart - (c * 8) else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd  and showExtraTargets and showExtraTargets789 then closeDownTrendStart - (c * 8) else Double.NaN;
plot nineADRMinus = if showCurrentTargetsOnly == yes and (bnumDown < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and !showTodayOnly and showExtraTargets and showExtraTargets789 then closeDownTrendStart - (c * 9) else if (tradetype == tradetype.both or tradetype == tradetype.short) and DownTrend and plotADR and showTodayOnly  and today and afterStart and beforeEnd  and showExtraTargets and showExtraTargets789 then closeDownTrendStart - (c * 9) else Double.NaN;

UpTrendStopLoss.SetDefaultColor(Color.LIGHT_RED);
oneADRPlus.SetDefaultColor(Color.LIGHT_GREEN);
twoADRPlus.SetDefaultColor(Color.LIGHT_GREEN);
threeADRPlus.SetDefaultColor(Color.LIGHT_GREEN);
fourADRPlus.SetDefaultColor(Color.LIGHT_GREEN);
fiveADRPlus.SetDefaultColor(Color.LIGHT_GREEN);
sixADRPlus.SetDefaultColor(Color.LIGHT_GREEN);
sevenADRPlus.SetDefaultColor(Color.LIGHT_GREEN);
eightADRPlus.SetDefaultColor(Color.LIGHT_GREEN);
nineADRPlus.SetDefaultColor(Color.LIGHT_GREEN);

DownTrendStopLoss.SetDefaultColor(Color.LIGHT_GREEN);
oneADRMinus.SetDefaultColor(Color.LIGHT_RED);
twoADRMinus.SetDefaultColor(Color.LIGHT_RED);
threeADRMinus.SetDefaultColor(Color.LIGHT_RED);
fourADRMinus.SetDefaultColor(Color.LIGHT_RED);
fiveADRMinus.SetDefaultColor(Color.LIGHT_RED);
sixADRMinus.SetDefaultColor(Color.LIGHT_RED);
sevenADRMinus.SetDefaultColor(Color.LIGHT_RED);
eightADRMinus.SetDefaultColor(Color.LIGHT_RED);
nineADRMinus.SetDefaultColor(Color.LIGHT_RED);


########### ADX Triangle Plot ###################################
plot ADXTriangleUp = if showCurrentTargetsOnly == yes and (bnumUp < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if showADXTriangle and UpTrend and ADX > ADX[1] and !showTodayOnly then closeUpTrendStart - (c * stopLossMultiplier) else if showADXTriangle and UpTrend and ADX > ADX[1] and showTodayOnly and today then closeUpTrendStart - (c * stopLossMultiplier)  else Double.NaN;
ADXTriangleUp.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
ADXTriangleUp.SetDefaultColor(Color.WHITE);
ADXTriangleUp.AssignValueColor(if ADX > ADXR and ADX[1] < ADXR[1] then Color.RED else if ADX > 35 then Color.CYAN else Color.CURRENT);
ADXTriangleUp.SetLineWeight(1);
plot ADXBubbleDown = if showCurrentTargetsOnly == yes and (bnumUp < Max(HighestAll(dn), HighestAll(up)))
                         then Double.NaN
                         else if showADXTriangle and DownTrend and ADX > ADX[1] and !showTodayOnly then closeDownTrendStart + (c * stopLossMultiplier) else if showADXTriangle and DownTrend and ADX > ADX[1] and showTodayOnly and today then closeDownTrendStart + (c * stopLossMultiplier) else Double.NaN;
ADXBubbleDown.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
ADXBubbleDown.SetDefaultColor(Color.MAGENTA);
ADXBubbleDown.AssignValueColor(if ADX > ADXR and ADX[1] < ADXR[1] then Color.GREEN else if ADX > 35 then Color.YELLOW else Color.CURRENT);
ADXBubbleDown.SetLineWeight(1);


#################################################################
############          ADR/ATR Zone Shading              #########
#################################################################
def u = if UpTrend then closeUpTrendStart else Double.NaN;
def d = if DownTrend then closeDownTrendStart else Double.NaN;
def bnumUpCheck = if bnumUp != 0 then 1 else Double.NaN;
def bnumDownCheck = if bnumDown != 0 then 1 else Double.NaN;

AddCloud(if showADRZones and UpTrend and bnumUpCheck and showExtraTargets and showExtraTargets789 then nineADRPlus else if showADRZones and UpTrend and bnumUpCheck and showExtraTargets then sixADRPlus else if showADRZones and UpTrend and bnumUpCheck then threeADRPlus else Double.NaN, if showADRZones and UpTrend and bnumUpCheck then u else Double.NaN , CreateColor(213, 252, 213));
AddCloud(if showADRZones and UpTrend then u else Double.NaN, if showADRZones and UpTrend then UpTrendStopLoss else Double.NaN , CreateColor(255, 174, 174));

# - Shade Downtrend ADR/ATR zones
AddCloud( if showADRZones and DownTrend and bnumDownCheck then d else Double.NaN ,if showADRZones and DownTrend and bnumDownCheck and showExtraTargets and showExtraTargets789 then nineADRminus else if showADRZones and DownTrend and bnumDownCheck and showExtraTargets then sixADRMinus else if showADRZones and DownTrend and bnumDownCheck then threeADRMinus else Double.NaN, CreateColor(213, 252, 213));

AddCloud(if showADRZones and DownTrend then DownTrendStopLoss else Double.NaN, if showADRZones and DownTrend then d else Double.NaN, CreateColor(255, 174, 174));


#################################################################
####    RSM shade areas based on criteria; adjust as needed  ####
#################################################################
AddCloud(if showRSMShade and RSI > 50 and SlowK >= 50 and Value > Avg then Double.POSITIVE_INFINITY else Double.NaN, if RSI > 50 and SlowK > 50 and Value > Avg then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_GREEN);
AddCloud(if showRSMShade and RSI < 50 and SlowK < 50 and Value < Avg then Double.POSITIVE_INFINITY else Double.NaN, if RSI < 50 and SlowK < 50 and Value < Avg then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_RED);


#################################################################
############   Labels disable/blockout as needed        #########
#################################################################
# - Trend Labels
AddLabel(showTrendLabels and (bnumDown != 0 or bnumUp != 0), "Trend BAR#: " + (if bnumUp > 0 then bnumUp else + bnumDown), if bnumUp > 0 then Color.GREEN else Color.RED);
AddLabel(showTrendLabels and (bnumDown != 0 or bnumUp != 0), "Trend @ $:" + (if bnumUp > 0 then closeUpTrendStart else  + closeDownTrendStart), if bnumUp > 0 then Color.GREEN else Color.RED);
AddLabel(showTrendLabels, "Tot Bars:" + (if bnumUp > 0 then UpTrendBarCount else DownTrendBarCount), if bnumUp > 0 then Color.GREEN else Color.RED);
AddLabel(showTrendLabels, "RSM:" + (if UpTrend == 1 then "L" else if DownTrend == 1 then "S" else "I"), if UpTrend == 1 then Color.GREEN else if DownTrend == 1 then Color.RED else Color.GRAY);

# - ADR/ATR Labels Targets
AddLabel(openPrice and showADRLabels, "Open:" + dailyO, Color.ORANGE);

AddLabel(showADRLabels and (UpTrend or DownTrend), "Target #1: " + (if UpTrend then Round(oneADRPlus, 2) else if DownTrend then Round(oneADRMinus, 2) else Double.NaN) + " ", if UpTrend then Color.GREEN else if DownTrend then Color.RED else Color.GRAY);
AddLabel(showADRLabels and (UpTrend or DownTrend), "Target #2: " + (if UpTrend then Round(twoADRPlus, 2) else if DownTrend then Round(twoADRMinus, 2) else Double.NaN) + " ", if UpTrend then Color.GREEN else if DownTrend then Color.RED else Color.GRAY);
AddLabel(showADRLabels and (UpTrend or DownTrend), "Target #3: " + (if UpTrend then Round(threeADRPlus, 2) else if DownTrend then Round(threeADRMinus, 2) else Double.NaN) + " ", if UpTrend then Color.GREEN else if DownTrend then Color.RED else Color.GRAY);

# - Indicator Label
AddLabel(if showIndicatorLabels then yes else no, "RSI:" + Round (RSI, 2) + " | sK:" + Round(SlowK, 2) + " | Macd:" + Round(Value, 4) + "  ", Color.ORANGE);




#### ALERTS Sound
Alert(audibleAlerts and upArrow, "RSM UpTrend Started", Alert.BAR, Sound.Ding);
Alert(audibleAlerts and downArrow, "RSM DownTrend Started", Alert.BAR, Sound.Ding);

RSM Lower

Update - Version 1.5 (Lower)

  1. Added Stochastic Divergence Indicator (in addition to RSI)
  2. Added labels for selected plot
  3. Added RSI Drivergence indicator
    1. Credit to @BenTen - https://usethinkscript.com/threads/rsi-divergence-indicator-with-scanner-for-thinkorswim.136/
    2. Identifies Divergence for RSI only
    3. Plotted by ORANGE Dots and Orange Dashed Line
    4. Requested by - @bigshow3

JiL9nLw.jpg


xMmw0lS.jpg

Features
  1. 3 Indicators in 1
    1. RSI - Only
    2. Stochastic - Only
    3. RSI & Stochastic
    4. MACD - Only
  2. Will shade lower area when trend is confirmed for each indicator individually
  3. All settings for each indicator made avaiable in settings for user configuration
  4. Paint Bars if not used with upper study - user configurable
KptvfY5.png


Code:
#RSM_Lower_v1.5
#
#CHANGELOG
#
# 2021.07.06 V1.5 @SuryaKiranC - Updated code to use existing variables; added Stochastic Slow Divergence (in addition
#                           to RSI Divergence - added Labeles to show which plot is enabled; can be turned off
#
# 2021.07.06 V1.4 @cos251 - Added RSI Divergence indicator from "RSI Dirvergence Indicator" from BenTen code
#                           Please note that the overbought and oversold used for divergence is 70/30 and can be adjusted in
#                           settings
#
# 2021.01.11 V1.3 @cos251 - Addjusted lower shading to shade trends when individual indicator crosses respective midline
#                           Shading will match if stochPlots is set to "Both" (RSI & Stochastci)
#
# 2020.11.30 V1.2 @cos251 - Added quick option to select plot(s) (RSI, Stochastic, Both or MACDOnly), set SlowD to enabled,
#                           user can uncheck SlowD plot if desired; adjusted coloring and shading to work with
#                           any plot selected; Combined plots for ease of use.
#
# 2020.10.30 V1.1 @cos251 - Added UpTrend and DownTrend variables that can be used for a SCAN (HAS BEEN REMOVED)
# 2020.10.27 V1.0 @cos251 - Added RSI, StochasticSlow and MACD to same indicator; this
#                           will plot only RSI and Stochastic but also
#                         - calculates MACD; Will shade the lower plot area of the following conditions are met
#                           Shade GREEN = RSI > 50 and SlowK > 50 and (macd)Value > (macd)Avg
#                           Shade RED = RSI < 50 and SlowK < 50 and (macd)Value < (macd)Avg
#                  
#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/
#
#USAGE
#



declare lower;

input paintBars = yes;
input selectPlots = { default "RSI", "Stochastic", "Both", "MACDOnly" };

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

input lengthRSI = 7;
input over_BoughtRSI = 80;
input over_SoldRSI = 20;
input price = close;
input averageTypeRSI = AverageType.EXPONENTIAL;
input showBreakoutSignalsRSI = no;
input showRSI_obos = no;


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 calcRSI = 50 * (ChgRatio + 1);

plot RSI = if selectPlots == selectPlots.RSI or selectPlots == selectPlots.Both then calcRSI else Double.NaN;
plot OverSold_RSI = if (selectPlots == selectPlots.RSI or selectPlots == selectPlots.Both) and showRSI_obos then over_SoldRSI else Double.NaN;
plot OverBought_RSI = if (selectPlots == selectPlots.RSI or selectPlots == selectPlots.Both) and showRSI_obos then over_BoughtRSI else Double.NaN;
plot UpSignalRSI = if RSI crosses above OverSold_RSI then OverSold_RSI else Double.NaN;
plot DownSignalRSI = if RSI crosses below OverBought_RSI then OverBought_RSI else Double.NaN;
UpSignalRSI.SetHiding(!showBreakoutSignalsRSI);
DownSignalRSI.SetHiding(!showBreakoutSignalsRSI);
RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", Color.YELLOW);
RSI.DefineColor("OverSold", GetColor(1));
#RSI.AssignValueColor(if RSI > rsiover_Bought then RSI.Color("OverBought") else if RSI < rsiover_Sold then RSI.Color("OverSold") else RSI.Color("Normal"));
OverSold_RSI.SetDefaultColor(GetColor(8));
OverBought_RSI.SetDefaultColor(GetColor(8));
UpSignalRSI.SetDefaultColor(Color.UPTICK);
UpSignalRSI.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignalRSI.SetDefaultColor(Color.DOWNTICK);
DownSignalRSI.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

def BN = barNumber();
def RSI_H = if RSI > over_BoughtRSI then fold Ri = 1 to Floor(lengthRSI / 2) with Rp = 1 while Rp do RSI > GetValue(RSI, -Ri) else 0;
def RSI_PivotH = if (BN > lengthRSI and RSI == Highest(RSI, Floor(lengthRSI / 2)) and RSI_H) then RSI else Double.NaN;
def RSI_L = if RSI < over_SoldRSI then fold Rj = 1 to Floor(lengthRSI / 2) with Rq = 1 while Rq do RSI < GetValue(RSI, -Rj) else 0;
def RSI_PivotL = if (BN > lengthRSI and RSI == Lowest(RSI, Floor(lengthRSI / 2)) and RSI_L) then RSI else Double.NaN;
def RSI_PHBar = if !IsNaN(RSI_PivotH) then BN else RSI_PHBar[1];
def RSI_PLBar = if !IsNaN(RSI_PivotL) then BN else RSI_PLBar[1];
def RSI_PHPoint = if !IsNaN(RSI_PivotH) then RSI_PivotH else RSI_PHPoint[1];
def RSI_LastPHBar = if RSI_PHPoint != RSI_PHPoint[1] then RSI_PHBar[1] else RSI_LastPHBar[1];
def RSI_PLPoint = if !IsNaN(RSI_PivotL) then RSI_PivotL else RSI_PLPoint[1];
def RSI_LastPLBar = if RSI_PLPoint != RSI_PLPoint[1] then RSI_PLBar[1] else RSI_LastPLBar[1];

def RSI_HighPivots = BN >= HighestAll(RSI_LastPHBar);
def RSI_LowPivots = BN >= HighestAll(RSI_LastPLBar);
def RSI_pivotHigh = if RSI_HighPivots then RSI_PivotH else Double.NaN;

plot RSI_plotHline = if selectPlots == selectPlots.RSI then RSI_pivotHigh else Double.NaN;
RSI_plotHline.EnableApproximation();
RSI_plotHline.SetDefaultColor(Color.LIME);
RSI_plotHline.SetStyle(Curve.SHORT_DASH);

plot RSI_pivotLow = if selectPlots == selectPlots.RSI and RSI_LowPivots then RSI_PivotL else Double.NaN;
RSI_pivotLow.EnableApproximation();
RSI_pivotLow.SetDefaultColor(Color.LIME);
RSI_pivotLow.SetStyle(Curve.SHORT_DASH);

plot RSI_pivotDot = if !IsNaN(selectPlots == selectPlots.RSI and RSI_pivotHigh) then RSI_pivotHigh else if !IsNaN(RSI_pivotLow) then RSI_pivotLow else Double.NaN;
RSI_pivotDot.SetDefaultColor(Color.LIME);
RSI_pivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);
RSI_pivotDot.SetLineWeight(3);


################################################################
##########                 Stochastic Slow             #########
################################################################
input over_boughtSt = 80;
input over_soldSt = 20;
input KPeriod = 14;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input averageTypeStoch = AverageType.WILDERS;
input showBreakoutSignalsStoch = {default "No", "On SlowK", "On SlowD", "On SlowK & SlowD"};
input showStochastic_ob_os = no;

def calcSlowK = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullK;
def calcSlowD = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullD;
plot SlowK = if selectPlots == selectPlots.Stochastic or selectPlots == selectPlots.Both then calcSlowK else Double.NaN;
plot SlowD = if selectPlots == selectPlots.Stochastic or selectPlots == selectPlots.Both then calcSlowD else Double.NaN;
plot OverBoughtSt = if (selectPlots == selectPlots.Stochastic or selectPlots == selectPlots.Both) and showStochastic_ob_os then over_boughtSt else Double.NaN;
plot OverSoldSt = if (selectPlots == selectPlots.Stochastic or selectPlots == selectPlots.Both) and showStochastic_ob_os then over_soldSt else Double.NaN;

def upK = SlowK crosses above OverSoldSt;
def upD = SlowD crosses above OverSoldSt;
def downK = SlowK crosses below OverBoughtSt;
def downD = SlowD crosses below OverBoughtSt;

plot UpSignalSt;
plot DownSignalSt;
switch (showBreakoutSignalsStoch) {
case "No":
    UpSignalSt = Double.NaN;
    DownSignalSt = Double.NaN;
case "On SlowK":
    UpSignalSt = if upK then OverSoldSt else Double.NaN;
    DownSignalSt = if downK then OverBoughtSt else Double.NaN;
case "On SlowD":
    UpSignalSt = if upD then OverSoldSt else Double.NaN;
    DownSignalSt = if downD then OverBoughtSt else Double.NaN;
case "On SlowK & SlowD":
    UpSignalSt = if upK or upD then OverSoldSt else Double.NaN;
    DownSignalSt = if downK or downD then OverBoughtSt else Double.NaN;
}
UpSignalSt.SetHiding(showBreakoutSignalsStoch == showBreakoutSignalsStoch."No");
DownSignalSt.SetHiding(showBreakoutSignalsStoch == showBreakoutSignalsStoch."No");
SlowK.SetDefaultColor(Color.WHITE);
SlowD.SetDefaultColor(Color.DARK_ORANGE);
OverBoughtSt.SetDefaultColor(GetColor(1));
OverSoldSt.SetDefaultColor(GetColor(1));
UpSignalSt.SetDefaultColor(Color.UPTICK);
UpSignalSt.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignalSt.SetDefaultColor(Color.DOWNTICK);
DownSignalSt.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

def SlowK_H = if SlowK > over_boughtSt then fold Si = 1 to Floor(KPeriod / 2) with Sp = 1 while Sp do SlowK > getValue(SlowK, -Si) else 0;
def SlowK_PivotH = if (BN > KPeriod and SlowK == highest(SlowK, Floor(KPeriod/2)) and SlowK_H) then SlowK else double.NaN;
def SlowK_L = if SlowK < over_soldSt then fold Sj = 1 to Floor(KPeriod / 2) with Sq = 1 while Sq do SlowK < getValue(SlowK, -Sj) else 0;
def SlowK_PivotL = if (BN > KPeriod and SlowK == lowest(SlowK, Floor(KPeriod/2)) and SlowK_L) then SlowK else double.NaN;
def SlowK_PHBar = if !isNaN(SlowK_PivotH) then BN else SlowK_PHBar[1];
def SlowK_PLBar = if !isNaN(SlowK_PivotL) then BN else SlowK_PLBar[1];
def SlowK_PHPoint = if !isNaN(SlowK_PivotH) then SlowK_PivotH else SlowK_PHPoint[1];
def SlowK_LastPHBar = if SlowK_PHPoint != SlowK_PHPoint[1] then SlowK_PHBar[1] else SlowK_LastPHBar[1];
def SlowK_PLPoint = if !isNaN(SlowK_PivotL) then SlowK_PivotL else SlowK_PLPoint[1];
def SlowK_LastPLBar = if SlowK_PLPoint != SlowK_PLPoint[1] then SlowK_PLBar[1] else SlowK_LastPLBar[1];

def SlowK_HighPivots = BN >= highestAll(SlowK_LastPHBar);
def SlowK_LowPivots = BN >= highestAll(SlowK_LastPLBar);
def SlowK_PivotHigh = if SlowK_HighPivots then SlowK_PivotH else double.NaN;

plot SlowK_plotHline = SlowK_PivotHigh;
     SlowK_plotHline.enableApproximation();
     SlowK_plotHline.SetDefaultColor(Color.LIME);
     SlowK_plotHline.SetStyle(Curve.Short_DASH);

plot SlowK_pivotLow = if SlowK_LowPivots then SlowK_PivotL else double.NaN;
     SlowK_pivotLow.enableApproximation();
     SlowK_pivotLow.SetDefaultColor(Color.LIME);
     SlowK_pivotLow.SetStyle(Curve.Short_DASH);

plot SlowK_pivotDot = if !isNaN(SlowK_pivotHigh) then SlowK_pivotHigh else if !isNaN(SlowK_pivotLow) then SlowK_pivotLow else double.NaN;
     SlowK_pivotDot.SetDefaultColor(Color.LIME);
     SlowK_pivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);
     SlowK_pivotDot.SetLineWeight(3);


################################################################
##########                 MACD                        #########
################################################################
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.WEIGHTED;
input showBreakoutSignalsMACD = no;
def calcValue = MovingAverage(averageTypeMACD, close, fastLength) - MovingAverage(averageTypeMACD, close, slowLength);
def calcAvg = MovingAverage(averageTypeMACD, calcValue, MACDLength);
def calcDiff = calcValue - calcAvg;
plot ZeroLine = if selectPlots == selectPlots.MACDOnly then 0 else Double.NaN;
plot Value = if selectPlots == selectPlots.MACDOnly then calcValue else Double.NaN;
plot Avg = if selectPlots == selectPlots.MACDOnly then calcAvg else Double.NaN;
plot Diff = if selectPlots == selectPlots.MACDOnly then calcDiff else Double.NaN;
plot UpSignalMACD = if calcDiff crosses above 0 then 0 else Double.NaN;
plot DownSignalMACD = if calcDiff crosses below 0 then 0 else Double.NaN;

UpSignalMACD.SetHiding(!showBreakoutSignalsMACD);
DownSignalMACD.SetHiding(!showBreakoutSignalsMACD);

Value.SetDefaultColor(Color.GREEN);
Avg.SetDefaultColor(Color.RED);
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(4);
Diff.DefineColor("Positive and Up", Color.CYAN);
Diff.DefineColor("Positive and Down", Color.BLUE);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.YELLOW);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.Color("Positive and Up") else Diff.Color("Positive and Down") else if Diff < Diff[1] then Diff.Color("Negative and Down") else Diff.Color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));
UpSignalMACD.SetDefaultColor(Color.UPTICK);
UpSignalMACD.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignalMACD.SetDefaultColor(Color.DOWNTICK);
DownSignalMACD.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);


# Check Each Signal for over 50 and MACD for Value > Avg
def rsiGreen = if calcRSI > 50 then 1 else Double.NaN;
def rsiRed = if calcRSI < 50 then 1 else Double.NaN;
def stochGreen = if calcSlowK >= 50 then 1 else Double.NaN;
def stochRed = if calcSlowK < 50 then 1 else Double.NaN;
def macdGreen = if calcValue > calcAvg then 1 else Double.NaN;
def macdRed = if calcValue < calcAvg then 1 else Double.NaN;
def green = if rsiGreen and stochGreen and macdGreen then 1 else Double.NaN;
def red = if rsiRed and stochRed and macdRed then 1 else Double.NaN;


#RSI Color Assignment per requeset
RSI.AssignValueColor(if calcRSI > 50 and calcSlowK > 50 and calcValue > calcAvg then Color.GREEN else if calcRSI < 50 and calcSlowK < 50 and calcValue < calcAvg then Color.RED else Color.DARK_GRAY);

#AssignPriceColor
AssignPriceColor(if paintBars and calcRSI > 50 and calcSlowK > 50 and calcValue > calcAvg then Color.GREEN else if paintBars and calcRSI < 50 and calcSlowK < 50 and calcValue < calcAvg then Color.RED else if paintBars then Color.DARK_GRAY else Color.CURRENT);

#################################################################
############  Shade areas based on criteria; adjust as needed  ##
#################################################################
AddCloud(if rsiGreen and stochGreen and selectPlots == selectPlots.Both then Double.POSITIVE_INFINITY else Double.NaN, if rsiGreen and stochGreen and selectPlots == selectPlots.Both then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_GREEN);


AddCloud(if rsiRed and stochRed and selectPlots == selectPlots.Both then Double.POSITIVE_INFINITY else Double.NaN, if rsiRed and stochRed and selectPlots == selectPlots.Both then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_RED);

AddCloud(if rsiGreen and selectPlots == selectPlots.RSI then Double.POSITIVE_INFINITY else Double.NaN, if rsiGreen and selectPlots == selectPlots.RSI then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_GREEN);
AddCloud(if rsiRed and selectPlots == selectPlots.RSI then Double.POSITIVE_INFINITY else Double.NaN, if rsiRed and selectPlots == selectPlots.RSI then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_RED);

AddCloud(if stochGreen and selectPlots == selectPlots.Stochastic then Double.POSITIVE_INFINITY else Double.NaN, if stochGreen and selectPlots == selectPlots.Stochastic then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_GREEN);
AddCloud(if stochRed and selectPlots == selectPlots.Stochastic then Double.POSITIVE_INFINITY else Double.NaN, if stochRed and selectPlots == selectPlots.Stochastic then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_RED);

AddCloud(if macdGreen and selectPlots == selectPlots.MACDOnly then Double.POSITIVE_INFINITY else Double.NaN, if macdGreen and selectPlots == selectPlots.MACDOnly then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_GREEN);
AddCloud(if macdRed and selectPlots == selectPlots.MACDOnly then Double.POSITIVE_INFINITY else Double.NaN, if macdRed and selectPlots == selectPlots.MACDOnly then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_RED);


plot fifty = if selectPlots == selectPlots.RSI or selectPlots == selectPlots.Stochastic or selectPlots == selectPlots.Both then 50 else Double.NaN;
fifty.SetDefaultColor(Color.RED);



input showLabels = yes;
AddLabel(if showLabels then yes else no,if selectPlots == selectPlots.RSI then "RSM: RSI PLOT" else if selectPlots == selectPlots.Stochastic then "RSM: Stochastic Plot" else if selectPlots == selectPlots.Both then "RSM: RSI & Stochastic Plot" else "RSM: MACD PLOT", Color.ORANGE);

RSM MTF (Labels)

Features
  1. Provides chart labels (upper left corner of price chart) with current status of MTF RSM Trend for the following TF's
    1. 1m, 2m, 3m, 4m, 5m, 10m, 15m, 20m, 30m, 1h, 2h, 4h, 1d, 2d, 3d, 4d, 1wk, 1mnth
    2. Add indicator for each time frame you would like shown
p4lADl8.png


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.
#
# 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/
#
#

input period = AggregationPeriod.DAY;

DefineGlobalColor("UpTrend", Color.Green);
DefineGlobalColor("DownTrend", Color.RED);
DefineGlobalColor("NoTrend", Color.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;

if period >= currentPeriod {
    RSM = RSM_(aP = period);

} else {
    RSM = Double.NaN;

}

AddLabel(!IsNaN(RSM), if period == AggregationPeriod.MONTH then "M"
else if period == AggregationPeriod.WEEK then "W"
else if period == AggregationPeriod.FOUR_DAYS then "4D"
else if period == AggregationPeriod.THREE_DAYS then "3D"
else if period == AggregationPeriod.TWO_DAYS then "2D"
else if period == AggregationPeriod.DAY then "D"
else if period == AggregationPeriod.FOUR_HOURS then "4H"
else if period == AggregationPeriod.TWO_HOURS then "2H"
else if period == AggregationPeriod.HOUR then "60m"
else if period == AggregationPeriod.THIRTY_MIN then "30m"
else if period == AggregationPeriod.TWENTY_MIN then "20m"
else if period == AggregationPeriod.FIFTEEN_MIN then "15m"
else if period == AggregationPeriod.TEN_MIN then "10m"
else if period == AggregationPeriod.FIVE_MIN then "5m"
else if period == AggregationPeriod.FOUR_MIN then "4m"
else if period == AggregationPeriod.THREE_MIN then "3m"
else if period == AggregationPeriod.TWO_MIN then "2m"
else if period == AggregationPeriod.MIN then "1m"
else "", if RSM == 1 then GlobalColor("UpTrend") else if RSM == 0 then GlobalColor("DownTrend") else GlobalColor("NoTrend"));

RSM SCAN

  • Scanner Setup Instructions:
    1. Click Create (Create New Study)
    2. Remove the default plot statement and past the code block from RSM_SCAN.
    3. Save the study with name "RSM_SCAN", make sure it is not loaded in your studies on the right, if it is loaded by default when you saved it, please remove we don't need this on chart study.
    4. Go to Scan, Remove all the filters and add a new filter, select "Study" as a filter, Default study selected will be "ADXCrossOver", Click on Pencil Icon next to Default TimeFrame "D" and click "ThinkScript Editor".
    5. Here you can past one of the scan query RSM_SCAN().UpTrendJustStarted or RSM_SCAN().DownTrendJustStarted.
    6. You can even limit the scan results, select a default narrowed down list as "S&P 500" under "Scan In, on the scan tab itself.
    7. Finally you can save the scan query with a name.
    8. Repeat Step 4 to 7, for other scan queries.
  • The following scan queries are available
    1. RSM_Scan().UpTrend (UpTrend in Progress, in the selected timeframe for Scan)
    2. RSM_Scan().UpTrendJustStarted (Uptrend Just started, in the selected timeframe for Scan)
    3. RSM_Scan().DownTrend (DownTrend in Progress, in the selected timeframe for Scan)
    4. RSM_Scan().DownTrendJustStarted (DownTrend Just started, in the selected timeframe for Scan)
    5. RSM_Scan().UpTrendJustEnded (UpTrend finished, in the selected timeframe for Scan)
    6. RSM_Scan().DownTrendJustEnded (DownTrend finished, in the selected timeframe for Scan)
  • As always, please match the chart timeframe to your Scanner Settings for review.

Code:
#START OF RSI/Stochastic/MACD Confluence combo for ThinkOrSwim
#
# RSM_SCAN
#
#CHANGELOG
# 2020.12.05 - V1.0 @cos251 - RSM SCANS study - to be used to scan for following conditions:
#            - 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/
#
#USAGE
#
declare lower;

plot fiftyLine = 50;
################################################################
##########                 RSI                         #########
################################################################

input lengthRSI = 7;
input over_BoughtRSI = 80;
input over_SoldRSI = 20;
input price = close;
input 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             #########
################################################################
input over_boughtSt = 80;
input over_soldSt = 20;
input KPeriod = 14;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input averageTypeStoch = AverageType.WILDERS;
def SlowK = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullK;
def SlowD = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullD;


#################################################################
############           MACD Calculation                 #########
#################################################################
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input 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
plot UpTrend = if RSI > 50 and SlowK > 50 and Value > Avg then 1 else Double.NaN;
plot DownTrend = if RSI < 50 and SlowK < 50 and Value < Avg then 1 else Double.NaN;
UpTrend.Hide();
DownTrend.Hide();

# 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;
plot UpTrendJustStarted = if UpTrendJustStartedBool == 1 and UpTrendJustStartedBool[1] == 0 then 1 else Double.NaN;
plot DownTrendJustStarted = if DownTrendJustStartedBool == 1 and DownTrendJustStartedBool[1] == 0 then 1 else Double.NaN;
UpTrendJustStarted.Hide();
DownTrendJustStarted.Hide();
plot UpTrendJustEnded= if UpTrendJustStartedBool[1] == 1 and UpTrendJustStartedBool == 0 then 1 else Double.NaN;
plot DownTrendJustEnded= if DownTrendJustStartedBool[1] == 1 and DownTrendJustStartedBool == 0 then 1 else Double.NaN;
UpTrendJustEnded.Hide();
DownTrendJustEnded.Hide();


STRATEGY

Below is code for a basic start to a strategy. Please use as you wish.
The orders are set to only open and close during RTH. Please adjust for what you may be looking for. Thanks.
Code:
#START OF RSI/Stochastic/MACD Confluence Strategy for ThinkOrSwim
# RSM Strategy - BASIC
#CHANGELOG
# 2020.10.27 V1.0 @cos251 - Added RSI, StochasticSlow and MACD to same indicator
#             - also calculates MACD;
#               Will shade the lower plot area of the following conditions are met
#                    Shade GREEN = RSI > 50 and SlowK > 50 and (macd)Value > (macd)Avg
#                    Shade RED = RSI < 50 and SlowK < 50 and (macd)Value < (macd)Avg
#        
#REQUIREMENTS - RSI Set to 7, EXPONENTIAL
#               Stoch Slow 14 and 3 WILDERS
#               MACD 12,26,9 WEIGHTED

declare upper;


################################################################
##########            AddOrder Prep                    #########
################################################################
def bar = BarNumber();
def CloseAllCondition = SecondstillTime(1558) == 0;
def EOD = if SecondsTillTime(1558) == 0 and SecondsFromTime(1558) == 0 then 1 else 0;
def NotActive = if SecondsFromTime(1550) > 0 then 1 else 0;
def Active1 = if SecondsFromTime(0930) > 0 then 1 else 0;
def notrades = if SecondstillTime(1500) > 0 then 1 else 0;


################################################################
##########                 RSI                         #########
################################################################
input paintBars = yes;
input showShade = no;
input tradetype = { default "long", "short", "both" };
input lengthRSI = 7;
input price = close;
input 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             #########
################################################################
input over_boughtSt = 80;
input over_soldSt = 20;
input KPeriod = 14;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input averageTypeStoch = AverageType.WILDERS;
def SlowK = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullK;
def SlowD = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullD;



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


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

#################################################################
############  Shade areas based on criteria; adjust as needed  ##
#################################################################
AddCloud(if showShade and RSI >= 50 and SlowK >= 50 and Value > Avg then Double.POSITIVE_INFINITY else Double.NaN, if RSI >= 50 and SlowK >= 50 and Value > Avg then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_Green);
AddCloud(if showShade and RSI < 50 and SlowK < 50 and Value < Avg then Double.POSITIVE_INFINITY else Double.NaN, if RSI < 50 and SlowK < 50 and Value < Avg then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_RED);



#################################################################
############          SCAN Variables                    #########
#################################################################
plot UpTrend = if RSI >= 50 and SlowK >= 50 and Value > Avg then 1 else 0;
plot DownTrend = if RSI < 50 and SlowK < 50 and Value < Avg then 1 else 0;
def LongBuy = if UpTrend == 1 and UpTrend[1] == 0 then 1 else 0;
def LongExit = if UpTrend[1] == 1 and UpTrend == 0 then 1 else 0;
def ShortSell = if DownTrend == 1 and DownTrend[1] == 0 then 1 else 0;
def ShortExit = if DownTrend == 0 and DownTrend[1] == 1 then 1 else 0;
UpTrend.Hide();
DownTrend.Hide();
AddLabel(yes, if UpTrend == 1 then "::RSM-Signal:LONG" else if DownTrend == 1 then "::RSM-Signal:SHORT" else "::RSM-Signal:IDLE", if UpTrend == 1 then Color.GREEN else if DownTrend == 1 then Color.RED else Color.GRAY);

plot upArrow = if UpTrend == 1 and UpTrend[1] == 0 then low else Double.NaN;
upArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
upArrow.SetDefaultColor(Color.GREEN);

plot downArrow = if DownTrend == 1 and DownTrend[1] == 0 then high else Double.NaN;
downArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
downArrow.SetDefaultColor(Color.RED);


### BUY
#AddOrder(OrderType.BUY_TO_OPEN, LongBuy == 1 and (tradetype == tradetype.long or tradetype == tradetype.both), open, tickcolor = GetColor(9), #arrowcolor = GetColor(9), name = "LONG");

#AddOrder(OrderType.SELL_TO_CLOSE, LongExit == 1 and (tradetype == tradetype.long or tradetype == tradetype.both), open, tickcolor = #GetColor(9), arrowcolor = GetColor(9), name = "LONG_EXIT");

AddOrder(OrderType.BUY_AUTO, LongBuy == 1 and (tradetype == tradetype.long or tradetype == tradetype.both) and Active1 and notrades, price = close, tickcolor = Color.ORANGE, arrowcolor = Color.ORANGE, name = "BUY");

AddOrder(OrderType.Sell_To_Close, LongExit == 1 and (tradetype == tradetype.long or tradetype == tradetype.both), price = open[-1], tickcolor = Color.ORANGE, arrowcolor = Color.ORANGE, name = "Sell To Close");


AddOrder(OrderType.Sell_TO_CLOSE, EOD or closeAllCondition, price = close, tickcolor = Color.ORANGE, arrowcolor = Color.ORANGE, name = "SELL EOD");

### SELL
#AddOrder(OrderType.SELL_TO_OPEN, ShortSell == 1 and (tradetype == tradetype.short or tradetype == tradetype.both), open, tickcolor = #GetColor(9), arrowcolor = GetColor(8), name = "SHORT");
#AddOrder(OrderType.BUY_TO_CLOSE, ShortExit == 1 and (tradetype == tradetype.short or tradetype == tradetype.both), open, tickcolor = #GetColor(9), arrowcolor = GetColor(8), name = "Short_EXIT");

AddOrder(OrderType.SELL_AUTO, ShortSell == 1 and (tradetype == tradetype.short or tradetype == tradetype.both)  and Active1 and notrades , price = close, tickcolor = Color.YELLOW, arrowcolor = Color.YELLOW, name = "SELL");

AddOrder(OrderType.Buy_To_Close, ShortExit == 1 and (tradetype == tradetype.short or tradetype == tradetype.both), price = open[-1], tickcolor = Color.ORANGE, arrowcolor = Color.ORANGE, name = "Buy To Close");

AddOrder(OrderType.BUY_TO_CLOSE, EOD or closeAllCondition, price = close, tickcolor = Color.ORANGE, arrowcolor = Color.ORANGE, name = "BUY EOD");
 
Last edited by a moderator:
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);
 
Last edited:
Does anyone use this indicator to trade live? It looks nice backtesting but when I tested it in real time I found that you have to wait three bars after the initial signal for confirmation that the signal is actually valid. By that time you're usually too late. If anyone does use it, I'd be interested to know how you are able to compensate for this disadvantage.
I backtested on SPY and it shows a mixed signal for each time frame. For example, It shows " No trend" on a daily while it is on a downtrend. Hope the developer looks into it.
 
@Alkkkz there is nothing wrong with the indicator, trend in each timeframe can be different, generally we refer to higher frames to see how far trend is or if trend is starting from lower frames to higher and take the trade or not.

As described it works on all 3 indicators crossing over their mid line and stay in the direction of crossover.

I use this for live trading and been using it for 5 - 6 weeks. As always when entering a trade always look for where the stock is with respective of atleast 21 days.

Please note, do not paste the whole code in scanner, please check the video and instructions for the scanner setup in the original post.
 
Last edited by a moderator:
All of you that are getting stated with this setup, I would recommend keeping the whole of the code block in your studies, as it was posted, including the headers and Version info, @cos251 is doing a fantastic job of keeping the Version history and comments for improvement. It will help you in future, if and when there are any further enhancements posted.
 
Last edited by a moderator:
For those that worked on this, I just want to say thank you. In the last few weeks I have become very intrigued with this strategy and these studies make it fantastic to evaluate. I also love tinkering with the scripts, although the syntax leaves me frustrated at times, but I'm getting there.

One thing I'll point out, not saying it's a problem, but just making folks aware. I like to use White as opposed to Gray for the candles in the Upper price chart. I changed the Upper script from DARK_GRAY to WHITE in the AssignPriceColor function and the chart did not change color. I realized that there is a second AssignPriceColor function call in the lower script, once I changed that all was good.
 
@cos251 How do I enable the target labels?

Go to Upper Indicator Properties and make sure the settings are as following.
Plot ADR = Yes
Show ADR Zones = Yes
Show Today only = Yes, if you want only to see today's ADR Zones, but if you want for all the Days in chart frame, Set it to No.
Show Extra Tragets = Yes, only if you want to see more than default 3 Targets.

Honestly, there are lot of properties at each of these scripts, I would recommend the playing around with this a bit more, specially the once the are yes/no options and see what you line on the charts. Use the weekend enable/disable things a bit and see what you like.

Also use ondemand and play with it a bit. make the trades in ondemand. I know it is slow and painful, if you don't put in the time, you never know what's the worth of this information.

-S
 
@Chence27 I start with 5m and 15m, if 5m Trend Start is catching up on 15m I make my moves, Use ADR Levels for Setting Stop losses and will let the trade play out it's trend, While keeping any eye if higher Frames are catching up with the trend or not. That's what I real on MTF Labels not having to move to higher time frames frequently, I do look at Higher timeframes on occasions to see what are higher frame ADR Levels.

In addition to this, Always keep an eye on where we are at the individual Ticker price levels in comparison to 21 Days high/lows

Hope this helps.
-S
 
Hi bro @cos251 Thank you very much for this great job. I tell you I am trying to use this Scan type script in TOS but the system says: Exactly one plot expected, could you please tell me how to fix it. Thanks ,)

cec6e30823192195a233dc76b25f88ebf02f4dc76b7d5c6e18.jpg
 
hi bro @cos251 Thank you very much for this great job. I tell you I am trying to use this Scan type script in TOS but the system says: Exactly one plot expected, could you please tell me how to fix it
Thanks ,)
@hexis777 I am assuming this repeated post is accidental, if yes please delete you duplicate post, and I will do the same to the response too. But if you still need help with the Scanner Setup. You are doing it wrong, you don't copy the code in Scanner ThinkScript. Please look at the instructions posted in the original post also Look at the short video, that tell you what exactly you need to do with Scanners Thinkscript Editor.

RSM SCAN​

  • Scanner Setup Instructions:
    1. Click Create (Create New Study)
    2. Remove the default plot statement and past the code block from RSM_SCAN.
    3. Save the study with name "RSM_SCAN", make sure it is not loaded in your studies on the right, if it is loaded by default when you saved it, please remove we don't need this on chart study.
    4. Go to Scan, Remove all the filters and add a new filter, select "Study" as a filter, Default study selected will be "ADXCrossOver", Click on Pencil Icon next to Default TimeFrame "D" and click "ThinkScript Editor".
    5. Here you can past one of the scan query RSM_SCAN().UpTrendJustStarted or RSM_SCAN().DownTrendJustStarted.
    6. You can even limit the scan results, select a default narrowed down list as "S&P 500" under "Scan In, on the scan tab itself.
    7. Finally you can save the scan query with a name.
    8. Repeat Step 4 to 7, for other scan queries.
  • The following scan queries are available
    1. RSM_Scan().UpTrend (UpTrend in Progress, in the selected timeframe for Scan)
    2. RSM_Scan().UpTrendJustStarted (Uptrend Just started, in the selected timeframe for Scan)
    3. RSM_Scan().DownTrend (DownTrend in Progress, in the selected timeframe for Scan)
    4. RSM_Scan().DownTrendJustStarted (DownTrend Just started, in the selected timeframe for Scan)
    5. RSM_Scan().UpTrendJustEnded (UpTrend finished, in the selected timeframe for Scan)
    6. RSM_Scan().DownTrendJustEnded (DownTrend finished, in the selected timeframe for Scan)
  • As always, please match the chart timeframe to your Scanner Settings for review.
 
Amazing work you have done with this @cos251 , top notch! Thanks for all your hard work on this. Appreciate the mention as a contributor, glad to be of some small help in the larger scheme of things. :)

Thanks a lot Guys, I got the PowerX book after reading these posts. It has been very helpful!.
I got his book too because of all this (y) . Have you seen Markus' latest video (Jan 20, 2021) on his PowerX book / strategy? It goes into more detail than an earlier video he did.

 
@Chence27 That means if the up/down trend starts in m and eventually catches up in 15m and based on 21 day price range i would take the trade.

Lets say nflx past er made it go to 590's and a downtrend started in 5m 3 days after and eventually 15m starts the same downtrend, i would trade that.

Note: this is not a trade advise please use this as a reference for chart analysis for your DD.
 
Quick post here. I understand that not every indicator is perfect ( hahah), including this one, but this I thought this would be a good post on the aspect of learning how to trade. (Which I am still doing for the record). I ended up trading puts on SPY this morning and was on the positive side. I came across this trade while doing other work and figured it was a good example of waiting for setups. I did not take this trade for the record, buts shows how an indicator can be used to assist in trading. The first part of this is finding the setups or letting them work themselves out. All the books on candle patterns exist for a reason and you have to continuously draw them out so you can get better a spotting them.

I would like to say one of the key benefits of this indicator is that it helps with entry (once you've identified a proper one, this indicator is not going to tell you if the entry will ultimately be good or not), the indicator at least is plotting a stop loss for you to adhere to incase it does not work out and help you preserver your capital. If it does work out, then you have some targets to look to for profit. Some of those targets should already be in your head. The break of the first resistance point, break of second resistance (HOD) and then the targets provided by the dynamic ADR/ATR calculation.

I've read a couple of posts on here over the weekend of folks looking for that holy grail indicator, guess what guys, it does not exist!!!!

It's called learning how to trade. I have to be honest, I am writing this for me as much as I am for anyone else. Just figured I would give a quick opinion. Constructive criticism always welcomed.

EDIT - I've been toying with the idea of incorporating ADX into the indicator to help with trend identification and improve the signal. There are times when this indicator misses the mark, but once you do find a good trade, I think it does a good job of keeping you safely in the trade and providing an adequate exit.

EDIT #2 - I went back and looked at this on 2m chart (which is where I took the PUT trade this morning) and the setup is very nice for the long position as well.

DAIDBUn.jpg
 
Last edited:
@cos251 @SuryaKiranC if you want to do swing trading with power what time frame do you use. For one of the ticker ($SOL) i see i can swing on 1 hr where as on a daily chart i see price target is down. Can you please explain your strategy?
 
@cos251 @SuryaKiranC if you want to do swing trading with power what time frame do you use. For one of the ticker ($SOL) i see i can swing on 1 hr where as on a daily chart i see price target is down. Can you please explain your strategy?
If I am looking for Swing, I would normally look for RSL/Stoch/ MACD if they were starting from bottom and cracking their mid lines or dropping from top and turned around any crossing mid lines, if it is the later I would be cautious. Timeframes 1D, 4H,2H & 1H.

-S
 
If I am looking for Swing, I would normally look for RSL/Stoch/ MACD if they were starting from bottom and cracking their mid lines or dropping from top and turned around any crossing mid lines, if it is the later I would be cautious. Timeframes 1D, 4H,2H & 1H.

-S
on all time frames RSI?Stoc/MACD should be above mid lines coming from bottom?
 

New Indicator: Buy the Dip

Check out our Buy the Dip indicator and see how it can help you find profitable swing trading ideas. Scanner, watchlist columns, and add-ons are included.

Download the indicator

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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