This is a great study. https://usethinkscript.com/threads/rsm-indicator-for-thinkorswim.5407/
I find that the chop on the 1minute time frame is too excessive, so I was trying to modify the script to use a 5min aggregation period on a 1min chart.
I pared down the script to what appears to be the essentials for just painting the plot (I replaced PriceColor for the candles with a line plot that would appear above them, but aside from the painting strategy being different, the signals should be identical).
However, I cannot get anything in this code to run when attempting to use a 5min aggregation period. I think it's because the referenced studies such as Stochastic Slow are not correct when I've tried to reproduce the full code (replacing the shortcut "Reference [Study Name]" for the purpose of setting the aggregation period for each fundamental of high, low, close etc. to 5min).
This is what I've got. The chart labels that should show the values for the variables used aren't showing at all, so the script isn't loading at all:
I realize this is a mess. If anyone else likes scalping with a 1min chart or time frame lower than 5 minutes, but is also finding that the signals are too choppy with a period under 5 minutes, I'm hoping someone may be interested in helping to get this working.
I find that the chop on the 1minute time frame is too excessive, so I was trying to modify the script to use a 5min aggregation period on a 1min chart.
I pared down the script to what appears to be the essentials for just painting the plot (I replaced PriceColor for the candles with a line plot that would appear above them, but aside from the painting strategy being different, the signals should be identical).
However, I cannot get anything in this code to run when attempting to use a 5min aggregation period. I think it's because the referenced studies such as Stochastic Slow are not correct when I've tried to reproduce the full code (replacing the shortcut "Reference [Study Name]" for the purpose of setting the aggregation period for each fundamental of high, low, close etc. to 5min).
This is what I've got. The chart labels that should show the values for the variables used aren't showing at all, so the script isn't loading at all:
Code:
declare upper;
################################################################
########## Variables #########
################################################################
def agg = AggregationPeriod.FIVE_MIN;
input rangeType = { default "ADR", "ATR" };
################################################################
########## ATR/ADR Calc #########
################################################################
input ATRlength = 14;
input ATRaverageType = AverageType.WILDERS;
def Range;
if rangeType == rangeType.ATR {
Range = MovingAverage(ATRaverageType, TrueRange(high(period = "agg"), close(period = "agg"), low(period = "agg")), ATRlength);
} else {
Range = Average(high(period = "agg") - low(period = "agg"), 7);
}
################################################################
########## ADX Indicator Reference #########
################################################################
input lengthADX = 21;
input averageType = AverageType.WILDERS;
def hiDiff = high(period = "agg") - high(period = "agg")[1];
def loDiff = low(period = "agg")[1] - low(period = "agg");
def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
def ATR = MovingAverage(averageType, TrueRange(high(period = "agg"), close(period = "agg"), low(period = "agg")), lengthADX);
plot "DI+" = 100 * MovingAverage(averageType, plusDM, lengthADX) / ATR;
plot "DI-" = 100 * MovingAverage(averageType, minusDM, lengthADX) / ATR;
def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
def ADX = MovingAverage(averageType, DX, lengthADX);
def ADXR = (ADX + ADX[lengthADX - 1]) / 2;
################################################################
########## RSI #########
################################################################
input lengthRSI = 7;
def price = close(period = "agg");
input averageTypeRSI = AverageType.EXPONENTIAL;
def NetChgAvg = MovingAverage(averageTypeRSI, close(period = "agg") - close(period = "agg")[1], lengthRSI);
def TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(close(period = "agg") - close(period = "agg")[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
################################################################
########## Stochastic Slow #########
################################################################
def SFagg = AggregationPeriod.FIVE_MIN;
def SFover_bought = 80;
def SFover_sold = 20;
def SFKPeriod = 14;
def SFDPeriod = 3;
def SFpriceH = high(period = "SFagg");
def SFpriceL = low(period = "SFagg");
def SFpriceC = close(period = "SFagg");
def SFslowing_period = 3;
def SFaverageType = AverageType.WILDERS;
def SFlowest_k = Lowest(SFpriceL, SFKPeriod);
def SFc1 = SFpriceC - SFlowest_k;
def SFc2 = Highest(SFpriceH, SFKPeriod) - SFlowest_k;
def SFFastK = if SFc2 != 0 then SFc1 / SFc2 * 100 else 0;
def SlowK = MovingAverage(SFaverageType, SFFastK, SFslowing_period);
def SlowD = MovingAverage(SFaverageType, SlowK, SFDPeriod);
################################################################
########## MACD #########
################################################################
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.WEIGHTED;
def Value = MovingAverage(averageTypeMACD, close(period = "agg"), fastLength) - MovingAverage(averageTypeMACD, close(period = "agg"), slowLength);
def Avg = MovingAverage(averageTypeMACD, Value, MACDLength);
def Diff = Value - Avg;
################################################################
########## Assign Price Color #########
################################################################
# instead of paint bars:
plot paintbarsline = Average(high(period = "agg"), 5);
paintbarsline.SetPaintingStrategy(PaintingStrategy.LINE);
paintbarsline.SetLineWeight(3);
paintbarsline.AssignValueColor(if RSI > 50 and SlowK > 50 and Value > Avg then Color.GREEN else if RSI < 50 and SlowK < 50 and Value < Avg then Color.RED else Color.DARK_GRAY);
AddLabel(yes, RSI, Color.WHITE);
AddLabel(yes, SlowK, Color.WHITE);
AddLabel(yes, Value, Color.WHITE);
AddLabel(yes, Avg, Color.WHITE);
I realize this is a mess. If anyone else likes scalping with a 1min chart or time frame lower than 5 minutes, but is also finding that the signals are too choppy with a period under 5 minutes, I'm hoping someone may be interested in helping to get this working.
Last edited by a moderator: