Greetings. I use the RSM
https://usethinkscript.com/threads/rsm-indicator-for-thinkorswim.5407/
every day but can't figure out how to add in the RSM MTF labels a candle count. Is there any way to do this ? Still wondering ....
UPDATE:
# --- Start
# A multi time frame MTF Label with candle count.
#
# Simply name to RSM_MTF_10m and duplicate as desired then change aggregation time add to chart.
# --
#
input Time_Frame = AggregationPeriod.TEN_MIN;
# 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 = Time_Frame) - close(period = Time_Frame)[1], lengthRSI);
def TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(close(period = Time_Frame) - close(period = Time_Frame)[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 = Time_Frame), low(period = Time_Frame), close(period = Time_Frame), 3, if (averageTypeStoch == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullK;
def SlowD_ = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = Time_Frame), low(period = Time_Frame), close(period = Time_Frame), 3, if (averageTypeStoch == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullD;
################################################################
########## MACD ###########
################################################################
def Value_ = MovingAverage(averageTypeMACD, close(period = Time_Frame), fastLength) - MovingAverage(averageTypeMACD, close(period = Time_Frame), 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;
#Color Assignment
#--------------
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(period = Time_Frame);
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(period = Time_Frame);
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;
}
################################################################
########## ATR/ADR Calc #########
################################################################
input ATRlength = 14;
input rangeType = { default "ADR", "ATR" };
input ATRaverageType = AverageType.WILDERS;
def Range;
if rangeType == rangeType.ATR {
Range = MovingAverage(ATRaverageType, TrueRange(high(period = Time_Frame), close(period = Time_Frame), low(period = Time_Frame)), ATRlength);
} else {
Range = Average(high(period = Time_Frame) - low(period = Time_Frame), 7);
}
def c;
if BarNumber() == bnumUp or BarNumber() == bnumDown {
c = Range;
} else if UpTrend or DownTrend {
c = c[1];
} else {
c = 0;
}
input debug = no;
AddLabel(if debug then yes else no, "Current Bar:" + BarNumber());
AddLabel(if debug then yes else no, "C:" + c);
#-----------------------
#}
def currentPeriod = GetAggregationPeriod();
#def RSM;
def bnum;
#if period >= currentPeriod {
# bnum = RSM_();
#} else {
bnum = Double.NaN;
#}
plot UpDnClr = 0;
UpDnClr.AssignValueColor(if UpTrend == 1 then Color.GREEN else if DownTrend == 1 then Color.Red else Color.White);
input ShowLabel = yes;
#AddLabel(ShowLabel ,"RSM10m" + (if bnumUp > 0 then UpTrendBarCount else DownTrendBarCount), UpDnClr.takeValueColor());
AddLabel(ShowLabel,"RSM" + (if Time_Frame == AggregationPeriod.MONTH then "M"
else if Time_Frame == AggregationPeriod.WEEK then "W"
else if Time_Frame == AggregationPeriod.FOUR_DAYS then "4D"
else if Time_Frame == AggregationPeriod.THREE_DAYS then "3D"
else if Time_Frame == AggregationPeriod.TWO_DAYS then "2D"
else if Time_Frame == AggregationPeriod.DAY then "D"
else if Time_Frame == AggregationPeriod.FOUR_HOURS then "4H"
else if Time_Frame == AggregationPeriod.TWO_HOURS then "2H"
else if Time_Frame == AggregationPeriod.HOUR then "1h"
else if Time_Frame == AggregationPeriod.THIRTY_MIN then "30m"
else if Time_Frame == AggregationPeriod.TWENTY_MIN then "20m"
else if Time_Frame == AggregationPeriod.TEN_MIN then "10m"
else if Time_Frame == AggregationPeriod.FIVE_MIN then "5m"
else if Time_Frame == AggregationPeriod.FOUR_MIN then "4m"
else if Time_Frame == AggregationPeriod.THREE_MIN then "3m"
else if Time_Frame == AggregationPeriod.TWO_MIN then "2m"
else if Time_Frame == AggregationPeriod.MIN then "1m"
else "" ) + (if bnumUp > 0 then UpTrendBarCount else DownTrendBarCount), UpDnClr.takeValueColor());
#
#---------- END
The above code seems to work. Although I am not to crazy about the efficiency of parsing the time frame with concat so settled with pre-defined method when OnDemand is so laggy.
Anyway testing it now with 10m 30m and 1h. I did this to minimize my flipping about time frames to see bar count. If the 1h chart is 2 bars into
an RSM its more risky to hold for up and may wish to consider for down. Nice to know trigger timing 1st bar seems to be best with 1h or no trigger may consider waiting or watching for lower time frame triggers to make a decision or rely on other means.
Looks good so far. Gives me a really good way to know what is going on with higher time frames without having higher time frame charts open and still watch lower. Thanks to the RSM team members here for sure.