ashfordtrader
New member
Can you please post the full script? I am interested to see how it works. Thank you.Thank you so much!
Can you please post the full script? I am interested to see how it works. Thank you.Thank you so much!
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
@ashfordtrader We don't have all of that prepared in one script for you. But this thread will help you get started https://usethinkscript.com/threads/display-rsi-label-on-thinkorswim.798/
#Show/hide aggregation periods
input show1m = yes;#Hint show1m:1 minute
input show2m = yes;#Hint show2m:2 minutes
input show3m = yes;#Hint show3m:3 minutes
input show4m = yes;#Hint show4m:4 minutes
input show5m = yes;#Hint show5m:5 minutes
input show10m = yes;#Hint show10m:10 minutes
input show15m = yes;#Hint show15m:15 minutes
input show20m = yes;#Hint show20m:20 minutes
input show30m = yes;#Hint show30m:30 minutes
input show60m = yes;#Hint show60m:1 hour
input show2hr = yes;#Hint show2hr:2 hours
input show4hr = yes;#Hint show4hr:4 hours
input show1d = yes;#Hint show1d:1 day
### 1m timeframe ###
def tf1m = AggregationPeriod.MIN;
def rsi = reference RSI("over bought" = 95, "over sold" = 5, price = close(period = AggregationPeriod.MIN));
AddLabel(yes,"RSI1m ", if rsi >= 50 or rsi <= 50 then Color.RED else Color.GREEN);
### 5m timeframe ###
def tf5m = AggregationPeriod.five_MIN;
def rsi5 = reference RSI("over bought" = 95, "over sold" = 5, price = close(period = AggregationPeriod.FIVE_MIN));
AddLabel(yes, "RSI5m", if rsi >= 50 or rsi <= 50 then Color.RED else Color.GREEN);
Thank you so much Ben. Here is the script I started. But, the 1min and 5 min RSI ended up with the same value. They should be different. What am I doing wrong? Thank you.
Code:#Show/hide aggregation periods input show1m = yes;#Hint show1m:1 minute input show2m = yes;#Hint show2m:2 minutes input show3m = yes;#Hint show3m:3 minutes input show4m = yes;#Hint show4m:4 minutes input show5m = yes;#Hint show5m:5 minutes input show10m = yes;#Hint show10m:10 minutes input show15m = yes;#Hint show15m:15 minutes input show20m = yes;#Hint show20m:20 minutes input show30m = yes;#Hint show30m:30 minutes input show60m = yes;#Hint show60m:1 hour input show2hr = yes;#Hint show2hr:2 hours input show4hr = yes;#Hint show4hr:4 hours input show1d = yes;#Hint show1d:1 day ### 1m timeframe ### def tf1m = AggregationPeriod.MIN; def rsi = reference RSI("over bought" = 95, "over sold" = 5, price = close(period = AggregationPeriod.MIN)); AddLabel(yes,"RSI1m ", if rsi >= 50 or rsi <= 50 then Color.RED else Color.GREEN); ### 5m timeframe ### def tf5m = AggregationPeriod.five_MIN; def rsi5 = reference RSI("over bought" = 95, "over sold" = 5, price = close(period = AggregationPeriod.FIVE_MIN)); AddLabel(yes, "RSI5m", if rsi >= 50 or rsi <= 50 then Color.RED else Color.GREEN);
input timeframe_label1 = "5-min";
input timeframe_label2 = "15-min";
### 1st timeframe ###
def tf1 = AggregationPeriod.FIVE_MIN;
def rsi1 = reference RSI(price = close(period =tf1));
AddLabel(yes, "RSI " +timeframe_label1 +" : " +round(rsi1,1), color.orange);
### 2nd timeframe ###
def tf2 = AggregationPeriod.FIFTEEN_MIN;
def rsi2 = reference RSI(price = close(period = tf2));
AddLabel(yes, "RSI " +timeframe_label2 +" : " +round(rsi2,1), color.orange);
# This is a conversion of the NinjaTrader VPA indicator. ToS does not support directional
# triangles and diamonds, so there are some differences. The triangles are left as is, just
# not pointing a specific direction. The diamonds have been replaced with circles.
# Red Square - UpThrust bar.
# Blue Diamond - Reversal possible, yesterday was high volume wide spread up bar, but
# today we reached 10 days high with low close wide spread down bar.
# Red Triangle Down - UpThrust confirmation.
# Lime Square - Strength bar (either strength is showing in down trend or a supply
# test in up trend).
# Yellow Triangle Up - An Upbar closing near High after a Test confirms strength.
# Lime Diamond - Stopping volume. Normally indicates end of bearishness is nearing
# /OR/ No supply.
# Lime Triangle Up - The previous bar saw strength coming back, This upbar confirms strength.
# Blue Square - Psuedo UpThrust, A Sign of Weakness /OR/ A High Volume Up Bar closing
# down in a uptrend shows Distribution /OR/ No Demand.
# Blue Triangle Down - A Down Bar closing down after a Pseudo Upthrust confirms weakness.
# Yellow Triangle Down - High volume Downbar after an upmove on high volume indicates weakness.
# Aqua Triangle Up - High volume upbar closing on the high indicates strength (in short
# term down trend).
# Deep Pink Square - Test for supply.
# Turquoise Diamond - Effort to Rise. Bullish sign.
# Yellow Diamond - Effort to Fall. Bearish sign.
# The NT version used a LinRegSlopeSFX indicator for determining trends. Those have been
# replaced in this ToS version with a call to the built in LinearRegressionSlope indicator.
#######
# Arguments
input volumeEMALength = 30;
input narrowSpreadFactor = 0.7;
input wideSpreadFactor = 1.5;
input aboveAvgVolfactor = 1.5;
input ultraHighVolfactor = 2;
input highCloseFactor = 0.70;
input lowCloseFactor = 0.25;
input colorBars = {default false, true};
input trendText = {false, default true};
input volumeDefinitions = { false, default true };
input alerts = { default false, true };
#######
# Calculations
rec spread = high - low;
def median = (high + low ) / 2;
rec avgVolume = CompoundValue(volumeEMALength, ExpAverage(volume, volumeEMALength), Double.NaN);
# Calculate Volume moving average and it's standard deviation
rec sAvgVolume = CompoundValue(volumeEMALength, Average(volume, volumeEMALength), Double.NaN);
def sAvgVolumeSTD = StDev(sAvgVolume, volumeEMALength);
# check if the vloume has been decreasing in the past two days.
def isTwoDaysLowVol = (volume < volume[1] && volume[0] < volume[2]);
# Calculate Range information
def avgSpread = WildersAverage(spread, volumeEMALength)[0];
rec isWideSpreadBar = (spread > (wideSpreadFactor * avgSpread));
rec isNarrowSpreadBar = (spread < (narrowSpreadFactor * avgSpread));
# Price information
rec isUpBar = close > close[1];
rec isDownBar = close < close[1];
# Check if the close is in the Highs/Lows/Middle of the bar.
def x1 = if (close == low) then avgSpread else (spread / (close - low));
def isUpCloseBar = (x1 < 2);
def isDownCloseBar = (x1 > 2);
def isMidCloseBar = (x1 < 2.2 && x1 > 1.8);
def isVeryHighCloseBar = (x1 < 1.35);
# Trend Definitions
rec fiveDaysSma = CompoundValue(5, Average(close, 5)[0], Double.NaN);
def LongTermTrendSlope = LinearRegressionSlope(price = fiveDaysSma, length = 40)[0];
def MiddleTermTrendSlope = LinearRegressionSlope(price = fiveDaysSma, length = 15)[0];
def ShortTermTrendSlope = LinearRegressionSlope(price = fiveDaysSma, length = 5)[0];
######################################################################
# VSA Definitions
# utbar
rec isUpThrustBar = isWideSpreadBar && isDownCloseBar && ShortTermTrendSlope > 0;
# utcond1
def upThrustConditionOne = (isUpThrustBar[1] && isDownBar);
# utcond2
def upThrustConditionTwo = (isUpThrustBar[1] && isDownBar[0] && volume > volume[1]);
# utcond3
def upThrustConditionThree = (isUpThrustBar[0] && volume > 2 * sAvgVolume[0]);
# scond1
rec isConfirmedUpThrustBar = (upThrustConditionOne or upThrustConditionTwo or upThrustConditionThree);
# scond
rec isNewConfirmedUpThrustBar = (isConfirmedUpThrustBar[0] && !isConfirmedUpThrustBar[1]);
# trbar
def reversalLikelyBar = (volume[1] > sAvgVolume[0] && isUpBar[1] && isWideSpreadBar[1] && isDownBar[0] && isDownCloseBar && isWideSpreadBar[0] && LongTermTrendSlope > 0 && high == Highest(high, 10)[0]);
# hutbar
rec isPseudoUpThrustBar = (isUpBar[1] && (volume[1] > aboveAvgVolfactor * sAvgVolume[0]) && isDownBar[0] && isDownCloseBar && !isWideSpreadBar[0] && !isUpThrustBar[0]);
# hutcond
def pseudoUpThrustConfirmation = (isPseudoUpThrustBar[1] && isDownBar[0] && isDownCloseBar && !isUpThrustBar[0]);
# tcbar
def weaknessBar = (isUpBar[1] && high[0] == Highest(high, 5)[0] && isDownBar[0] && (isDownCloseBar or isMidCloseBar) && volume[0] > sAvgVolume[0] && !isWideSpreadBar[0] && !isPseudoUpThrustBar[0]);
# stdn, stdn0, stdn1, stdn2
def strengthInDownTrend = (volume[0] > volume[1] && isDownBar[1] && isUpBar[0] && (isUpCloseBar or isMidCloseBar) && ShortTermTrendSlope < 0 && MiddleTermTrendSlope < 0);
def strengthInDownTrend0 = (volume[0] > volume[1] && isDownBar[1] && isUpBar[0] && (isUpCloseBar or isMidCloseBar) && ShortTermTrendSlope < 0 && MiddleTermTrendSlope < 0 && LongTermTrendSlope < 0);
def strengthInDownTrend1 = (volume[0] > (sAvgVolume[0] * aboveAvgVolfactor) && isDownBar[1] && isUpBar[0] && (isUpCloseBar or isMidCloseBar) && ShortTermTrendSlope < 0 && MiddleTermTrendSlope < 0 && LongTermTrendSlope < 0);
def strengthInDownTrend2 = (volume[1] < sAvgVolume[0] && isUpBar[0] && isVeryHighCloseBar && volume[0] > sAvgVolume[0] && ShortTermTrendSlope < 0);
rec bycond1 = (strengthInDownTrend or strengthInDownTrend1);
# bycond
def isStrengthConfirmationBar = (isUpBar[0] && bycond1[1]);
# stvol
def stopVolBar = low[0] == Lowest(low, 5)[0] && (isUpCloseBar or isMidCloseBar) && volume[0] > aboveAvgVolfactor * sAvgVolume[0] && LongTermTrendSlope < 0;
# ndbar, nsbar
def noDemandBar = (isUpBar[0] && isNarrowSpreadBar[0] && isTwoDaysLowVol && isDownCloseBar);
def noSupplyBar = (isDownBar[0] && isNarrowSpreadBar[0] && isTwoDaysLowVol && isDownCloseBar);
# lvtbar, lvtbar1, lvtbar2
rec supplyTestBar = (isTwoDaysLowVol && low[0] < low[1] && isUpCloseBar);
def supplyTestInUpTrendBar = (volume[0] < sAvgVolume[0] && low[0] < low[1] && isUpCloseBar && LongTermTrendSlope > 0 && MiddleTermTrendSlope > 0 && isWideSpreadBar[0]);
def successfulSupplyTestBar = (supplyTestBar[1] && isUpBar[0] && isUpCloseBar);
# dbar
def distributionBar = (volume[0] > ultraHighVolfactor * sAvgVolume[0] && isDownCloseBar && isUpBar[0] && ShortTermTrendSlope > 0 && MiddleTermTrendSlope > 0 && !isConfirmedUpThrustBar[0] && !isUpThrustBar[0]);
# eftup, eftupfl, eftdn
def effortToMoveUpBar = (high[0] > high[1] && low[0] > low[1] && close[0] > close[1] && close[0] >= ((high[0] - low[0]) * highCloseFactor + low[0]) && spread[0] > avgSpread && volume[0] > volume[1]);
def failedEffortUpMove = (effortToMoveUpBar[1] && (isUpThrustBar[0] or upThrustConditionOne or upThrustConditionTwo or upThrustConditionThree));
def effortToMoveDownBar = (high[0] < high[1] && low[0] < low[1] && close[0] < close[1] && close[0] <= ((high[0] - low[0]) * lowCloseFactor + low[0]) && spread[0] > avgSpread && volume[0] > volume[1]);
######################################################################
# set the shapes on the graph
# upthurst and NOT confirmed - red square on top
plot upThrustBarPlot = if isUpThrustBar[0] and !isNewConfirmedUpThrustBar[0] then (high + 2 * TickSize()) else Double.NaN;
upThrustBarPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
upThrustBarPlot.SetStyle(Curve.POINTS);
upThrustBarPlot.SetDefaultColor(Color.RED);
upThrustBarPlot.HideBubble();
upThrustBarPlot.HideTitle();
# reversal likely - blue diamond on top
plot reversalLikelyBarPlot = if reversalLikelyBar then (high + 2 * TickSize()) else Double.NaN;
reversalLikelyBarPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
reversalLikelyBarPlot.SetDefaultColor(Color.BLUE);
reversalLikelyBarPlot.HideBubble();
reversalLikelyBarPlot.HideTitle();
# new confirmed upthrust bar - red triangle (down) on top
plot isNewConfirmedUpThrustBarPlot = if isNewConfirmedUpThrustBar then (high + 2 * TickSize()) else Double.NaN;
isNewConfirmedUpThrustBarPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
isNewConfirmedUpThrustBarPlot.SetDefaultColor(Color.RED);
isNewConfirmedUpThrustBarPlot.HideBubble();
isNewConfirmedUpThrustBarPlot.HideTitle();
# strength in down trend - lime square on bottom
plot strengthInDownTrendPlot = if strengthInDownTrend then (low - 4 * TickSize()) else Double.NaN;
strengthInDownTrendPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
strengthInDownTrendPlot.SetDefaultColor(Color.GREEN);
strengthInDownTrendPlot.HideBubble();
strengthInDownTrendPlot.HideTitle();
# strength in down trend - lime square on bottom
plot strengthInDownTrend1Plot = if strengthInDownTrend1 then (low - 4 * TickSize()) else Double.NaN;
strengthInDownTrend1Plot.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
strengthInDownTrend1Plot.SetDefaultColor(Color.GREEN);
strengthInDownTrend1Plot.HideBubble();
strengthInDownTrend1Plot.HideTitle();
# supply test in up trend - lime square on bottom of the bar
plot supplyTestInUpTrendBarPlot = if supplyTestInUpTrendBar then (low - 4 * TickSize()) else Double.NaN;
supplyTestInUpTrendBarPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
supplyTestInUpTrendBarPlot.SetDefaultColor(Color.GREEN);
supplyTestInUpTrendBarPlot.HideBubble();
supplyTestInUpTrendBarPlot.HideTitle();
# successful test for supply - yellow triangle up on bottom of the bar
plot successfulSupplyTestBarPlot = if successfulSupplyTestBar then (low - 2 * TickSize()) else Double.NaN;
successfulSupplyTestBarPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
successfulSupplyTestBarPlot.SetDefaultColor(Color.YELLOW);
successfulSupplyTestBarPlot.HideBubble();
successfulSupplyTestBarPlot.HideTitle();
# stopping volume green (diamond) circle at bottom of bar
plot stopVolBarPlot = if stopVolBar then (low - 2 * TickSize()) else Double.NaN;
stopVolBarPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
stopVolBarPlot.SetDefaultColor(Color.GREEN);
stopVolBarPlot.HideBubble();
stopVolBarPlot.HideTitle();
# green triangle up at bottom of the bar
plot isStrengthConfirmationBarPlot = if isStrengthConfirmationBar then (low - 7 * TickSize()) else Double.NaN;
isStrengthConfirmationBarPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
isStrengthConfirmationBarPlot.SetDefaultColor(Color.GREEN);
isStrengthConfirmationBarPlot.HideBubble();
isStrengthConfirmationBarPlot.HideTitle();
# blue square at top of bar
plot isPseudoUpThrustBarPlot = if isPseudoUpThrustBar then (high + 2 * TickSize()) else Double.NaN;
isPseudoUpThrustBarPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
isPseudoUpThrustBarPlot.SetDefaultColor(Color.BLUE);
isPseudoUpThrustBarPlot.HideBubble();
isPseudoUpThrustBarPlot.HideTitle();
# blue triangle (down) at top of bar
plot pseudoUpThrustConfirmationPlot = if pseudoUpThrustConfirmation then (high + 2 * TickSize()) else Double.NaN;
pseudoUpThrustConfirmationPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
pseudoUpThrustConfirmationPlot.SetDefaultColor(Color.BLUE);
pseudoUpThrustConfirmationPlot.HideBubble();
pseudoUpThrustConfirmationPlot.HideTitle();
# yellow triangle (down) at top of bar
plot weaknessBarPlot = if weaknessBar then (high + 2 * TickSize()) else Double.NaN;
weaknessBarPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
weaknessBarPlot.SetDefaultColor(Color.YELLOW);
weaknessBarPlot.HideBubble();
weaknessBarPlot.HideTitle();
# aqua triangle up at bottom of bar
plot strengthInDownTrend2Plot = if strengthInDownTrend2 then (low - 2 * TickSize()) else Double.NaN;
strengthInDownTrend2Plot.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
strengthInDownTrend2Plot.SetDefaultColor(Color.CYAN); # ????
strengthInDownTrend2Plot.HideBubble();
strengthInDownTrend2Plot.HideTitle();
# distribution at end of uptrend - blue square on top
plot distributionBarPlot = if distributionBar then (high + 2 * TickSize()) else Double.NaN;
distributionBarPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
distributionBarPlot.SetDefaultColor(Color.BLUE);
distributionBarPlot.HideBubble();
distributionBarPlot.HideTitle();
# supply test bar - pink square on bottom
plot supplyTestBarPlot = if supplyTestBar then (low - 2 * TickSize()) else Double.NaN;
supplyTestBarPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
supplyTestBarPlot.SetDefaultColor(Color.MAGENTA);
supplyTestBarPlot.HideBubble();
supplyTestBarPlot.HideTitle();
# no demand bar - blue squre on top
plot noDemandBarPlot = if noDemandBar then (high + 2 * TickSize()) else Double.NaN;
noDemandBarPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
noDemandBarPlot.SetDefaultColor(Color.BLUE);
noDemandBarPlot.HideBubble();
noDemandBarPlot.HideTitle();
# no supply bar - lime diamond on bottom
plot noSupplyBarPlot = if noSupplyBar then (low - 2 * TickSize()) else Double.NaN;
noSupplyBarPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
noSupplyBarPlot.SetDefaultColor(Color.GREEN);
noSupplyBarPlot.HideBubble();
noSupplyBarPlot.HideTitle();
# effort to move up - turquoise diamond in the median of the bar
plot effortToMoveUpBarPlot = if effortToMoveUpBar then (median) else Double.NaN;
effortToMoveUpBarPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
effortToMoveUpBarPlot.SetDefaultColor(CreateColor(64, 224, 208));
effortToMoveUpBarPlot.HideBubble();
effortToMoveUpBarPlot.HideTitle();
# effort to move down - yellow diamond in the median of the bar
plot effortToMoveDownBarPlot = if effortToMoveDownBar then (median) else Double.NaN;
effortToMoveDownBarPlot.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
effortToMoveDownBarPlot.SetDefaultColor(Color.YELLOW);
effortToMoveDownBarPlot.HideBubble();
effortToMoveDownBarPlot.HideTitle();
#######
# Trend Text Definitions
AddLabel(trendText, Concat("Vol: ", if volume > sAvgVolume[0] + 2.0 * sAvgVolumeSTD then "Very High"
else if volume[0] > (sAvgVolume[0] + 1.0 * sAvgVolumeSTD) then "High"
else if (volume[0] > sAvgVolume[0]) then "Above Average"
else if (volume[0] < sAvgVolume[0] && volume[0] > (sAvgVolume[0] - 1.0 * sAvgVolumeSTD)) then "Less Than Average"
else if (volume[0] < (sAvgVolume[0] - 1.0 * sAvgVolumeSTD)) then "Low"
else ""), Color.gray);
AddLabel(trendText, Concat("Spread: ", if (spread > (avgSpread * 2.0)) then "Wide"
else if (spread > avgSpread) then "Above Average"
else "Narrow"), Color.gray);
AddLabel(trendText, Concat("Close: ", if (isVeryHighCloseBar) then "Very High"
else if (isUpCloseBar) then "High"
else if (isMidCloseBar) then "Mid"
else if (isDownCloseBar) then "Down"
else "Very Low"), Color.gray);
AddLabel(trendText, Concat("Trend: ", Concat("Short Term ", if (ShortTermTrendSlope > 0) then "Up"
else "Down")), Color.gray);
AddLabel(trendText, Concat("Mid Term ", if (MiddleTermTrendSlope > 0) then "Up" else "Down"), Color.gray);
AddLabel(trendText, Concat("Long Term ", if (LongTermTrendSlope > 0) then "Up" else "Down"), Color.gray);
######
# Volume Bar Definitions
AddLabel(volumeDefinitions, if isUpThrustBar[0] then "An Upthrust Bar. A sign of weakness."
else if upThrustConditionOne then "A downbar after an Upthrust. Confirm weakness."
else if upThrustConditionTwo && !upThrustConditionOne then "A High Volume downbar after an Upthrust. Confirm weakness."
else if upThrustConditionThree then "This upthrust at very High Volume, Confirms weakness"
else if strengthInDownTrend1 then "Strength seen returning after a down trend. High volume adds to strength. "
else if strengthInDownTrend0 && !strengthInDownTrend then "Strength seen returning after a down trend."
else if strengthInDownTrend && !strengthInDownTrend1 then "Strength seen returning after a long down trend."
else if supplyTestBar[0] then "Test for supply."
else if successfulSupplyTestBar[0] then "An Upbar closing near High after a Test confirms strength."
else if isStrengthConfirmationBar then "An Upbar closing near High. Confirms return of Strength."
else if distributionBar then "A High Volume Up Bar closing down in a uptrend shows Distribution."
else if isPseudoUpThrustBar[0] then "Psuedo UpThrust. A Sign of Weakness."
else if pseudoUpThrustConfirmation then "A Down Bar closing down after a Pseudo Upthrust confirms weakness."
else if supplyTestInUpTrendBar then "Test for supply in a uptrend. Sign of Strength."
else if strengthInDownTrend2 then "High volume upbar closing on the high indicates strength."
else if weaknessBar then "High volume Downbar after an upmove on high volume indicates weakness."
else if noDemandBar then "No Demand. A sign of Weakness."
else if noSupplyBar then "No Supply. A sign of Strength."
else if effortToMoveUpBar[0] then "Effort to Rise. Bullish sign."
else if effortToMoveDownBar then "Effort to Fall. Bearish sign."
else if failedEffortUpMove then "Effort to Move up has failed. Bearish sign."
else if stopVolBar then "Stopping volume. Normally indicates end of bearishness is nearing."
else "",
if isUpThrustBar[0] then Color.RED
else if upThrustConditionOne then Color.GREEN
else if upThrustConditionTwo && !upThrustConditionOne then Color.GREEN
else if upThrustConditionThree then Color.BLUE
else if strengthInDownTrend1 then Color.YELLOW
else if strengthInDownTrend0 && !strengthInDownTrend then Color.GREEN
else if strengthInDownTrend && !strengthInDownTrend1 then Color.GREEN
else if supplyTestBar[0] then Color.CYAN
else if successfulSupplyTestBar[0] then Color.CYAN
else if isStrengthConfirmationBar then Color.GREEN
else if distributionBar then Color.YELLOW
else if isPseudoUpThrustBar[0] then Color.GREEN
else if pseudoUpThrustConfirmation then Color.BLUE
else if supplyTestInUpTrendBar then Color.BLUE
else if strengthInDownTrend2 then Color.YELLOW
else if weaknessBar then Color.BLUE
else if noDemandBar then Color.YELLOW
else if noSupplyBar then Color.GREEN
else if effortToMoveUpBar[0] then CreateColor(127, 255, 212)
else if effortToMoveDownBar then Color.BLUE
else if failedEffortUpMove then Color.BLUE
else if stopVolBar then Color.CYAN
else Color.BLACK);
########
# Alerts
Alert(if alerts and (isUpThrustBar[0]
or upThrustConditionOne
or (upThrustConditionTwo && !upThrustConditionOne)
or upThrustConditionThree
or strengthInDownTrend1
or (strengthInDownTrend0 && !strengthInDownTrend)
or (strengthInDownTrend && !strengthInDownTrend1)
or supplyTestBar[0]
or successfulSupplyTestBar[0]
or isStrengthConfirmationBar
or distributionBar
or isPseudoUpThrustBar[0]
or pseudoUpThrustConfirmation
or supplyTestInUpTrendBar
or strengthInDownTrend2
or weaknessBar
or noDemandBar
or noSupplyBar
or effortToMoveUpBar[0]
or effortToMoveDownBar
or failedEffortUpMove
or stopVolBar) then 1 else 0, if isUpThrustBar[0] then "An Upthrust Bar. A sign of weakness."
else if upThrustConditionOne then "A downbar after an Upthrust. Confirm weakness."
else if upThrustConditionTwo && !upThrustConditionOne then "A High Volume downbar after an Upthrust. Confirm weakness."
else if upThrustConditionThree then "This upthrust at very High Volume, Confirms weakness."
else if strengthInDownTrend1 then "Strength seen returning after a down trend. High volume adds to strength. "
else if strengthInDownTrend0 && !strengthInDownTrend then "Strength seen returning after a down trend."
else if strengthInDownTrend && !strengthInDownTrend1 then "Strength seen returning after a long down trend."
else if supplyTestBar[0] then "Test for supply."
else if successfulSupplyTestBar[0] then "An Upbar closing near High after a Test confirms strength."
else if isStrengthConfirmationBar then "An Upbar closing near High. Confirms return of Strength."
else if distributionBar then "A High Volume Up Bar closing down in a uptrend shows Distribution."
else if isPseudoUpThrustBar[0] then "Psuedo UpThrust. A Sign of Weakness."
else if pseudoUpThrustConfirmation then "A Down Bar closing down after a Pseudo Upthrust confirms weakness."
else if supplyTestInUpTrendBar then "Test for supply in a uptrend. Sign of Strength."
else if strengthInDownTrend2 then "High volume upbar closing on the high indicates strength."
else if weaknessBar then "High volume Downbar after an upmove on high volume indicates weakness."
else if noDemandBar then "No Demand. A sign of Weakness."
else if noSupplyBar then "No Supply. A sign of Strength."
else if effortToMoveUpBar[0] then "Effort to Rise. Bullish sign."
else if effortToMoveDownBar then "Effort to Fall. Bearish sign."
else if failedEffortUpMove then "Effort to Move up has failed. Bearish sign."
else if stopVolBar then "Stopping volume. Normally indicates end of bearishness is nearing."
else "", Alert.BAR, Sound.Ding);
Can you please post the full script? I am interested to see how it works. Thank you.
#MTF RSI Three standard ToS RSI studies with a choice of time frame for second and third RSI. Cloud between chart and second RSI.
# RSI with agg periods by Horserider. 5/12/2019
declare lower;
#RSI
input length = 14;
input over_Bought = 80;
input over_Sold = 20;
input price = close;
input averageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
plot RSI = 50 * (ChgRatio + 1);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot lline = 50;
RSI.DefineColor("Positive and Up", Color.GREEN);
RSI.DefineColor("Positive and Down", Color.DARK_GREEN);
RSI.DefineColor("Negative and Down", Color.RED);
RSI.DefineColor("Negative and Up", Color.DARK_RED);
RSI.AssignValueColor(if RSI >= 50 then if RSI > RSI[1] then RSI.Color("Positive and Up") else RSI.Color("Positive and Down") else if RSI < RSI[1] then RSI.Color("Negative and Down") else RSI.Color("Negative and Up"));
OverSold.SetDefaultColor(GetColor(7));
OverBought.SetDefaultColor(GetColor(7));
# RSI 2
input length2 = 14;
input price2 = close;
input averageType2 = AverageType.WILDERS;
input agg = AggregationPeriod.DAY;
def c = close(period = agg);
def NetChgAvg2 = MovingAverage(averageType2, c - c[1], length2);
def TotChgAvg2 = MovingAverage(averageType2, AbsValue(c - c[1] ),length2);
def ChgRatio2 = if TotChgAvg2 != 0 then NetChgAvg2 / TotChgAvg2 else 0;
plot RSI2 = 50 * (ChgRatio2 + 1);
RSI2.DefineColor("Positive and Up", Color.GREEN);
RSI2.DefineColor("Positive and Down", Color.DARK_GREEN);
RSI2.DefineColor("Negative and Down", Color.RED);
RSI2.DefineColor("Negative and Up", Color.DARK_RED);
RSI2.AssignValueColor(if RSI2 >= 50 then if RSI2 > RSI2[1] then RSI2.Color("Positive and Up") else RSI2.Color("Positive and Down") else if RSI2 < RSI2[1] then RSI2.Color("Negative and Down") else RSI2.Color("Negative and Up"));
RSI2.setLineWeight(3);
#Moving Averages
input MALength = 8;
input AverageType1 = AverageType.SIMPLE;
# plot the Moving Averages
def MA = MovingAverage(AverageType1, RSI2, MALength);
plot pMA = MA;
# RSI 3
input length3 = 14;
input price3 = close;
input averageType3 = AverageType.WILDERS;
input agg3 = AggregationPeriod.WEEK;
def c3 = close(period = agg3);
def NetChgAvg3 = MovingAverage(averageType3, c3 - c3[1], length3);
def TotChgAvg3 = MovingAverage(averageType3, AbsValue(c3 - c3[1]),length3);
def ChgRatio3 = if TotChgAvg3 != 0 then NetChgAvg3 / TotChgAvg3 else 0;
plot RSI3 = 50 * (ChgRatio3 + 1);
RSI3.DefineColor("Positive and Up", Color.GREEN);
RSI3.DefineColor("Positive and Down", Color.DARK_GREEN);
RSI3.DefineColor("Negative and Down", Color.RED);
RSI3.DefineColor("Negative and Up", Color.DARK_RED);
RSI3.AssignValueColor(if RSI3 >= 50 then if RSI3 > RSI3[1] then RSI3.Color("Positive and Up") else RSI3.Color("Positive and Down") else if RSI3 < RSI3[1] then RSI3.Color("Negative and Down") else RSI3.Color("Negative and Up"));
RSI3.setLineWeight(5);
#addCloud(RSI, RSI2, color.green, color.red);
# End Code
Not really... Your 1 min chart is the culprit... You can do higher on lower but not lower on higher as far as aggregation...Thank you so much Ben. When I am on 1 min chart, I see both 1min and 5 min labels, which is great. But when I go to 5min chart, both labels disappear. I was hoping to only see 5min RSI label. Is there any way to fix that?
Not really... Your 1 min chart is the culprit... You can do higher on lower but not lower on higher as far as aggregation...
See if 1 & 5 and 3 & 5 work for you...
I would like to know how to put weekly and daily RSI in a hourly chart so that we can have three RSI in the hourly chart. When three RSI indicators overlap above 70, the market will be overbought for a longer term. When three RSI indicators overlap below 30, the market will be oversold for a longer term.
# rsi3x_agg_00
# plot 3 rsi lines, 2 of diff agg times
# https://usethinkscript.com/threads/i-would-like-to-know-how-to-put-weekly-and-daily-rsi-in-hourly-chart.10835/
declare lower;
def na = double.nan;
#------------------------------------
input oooooo__1__oooooo = 0;
# rsi #1 - chart time
input show_rsi_1 = yes;
input length1 = 14;
input over_Bought1 = 70;
input over_Sold1 = 30;
input price1 = close;
input averageType1 = AverageType.WILDERS;
#input showBreakoutSignals1 = no;
def rsi1 = rsi(length1, over_Bought1, over_Sold1, price1, averageType1 );
input color1 = 1;
plot z1 = if show_rsi_1 then rsi1 else na;
z1.setdefaultcolor(getcolor(color1));
addlabel(show_rsi_1, "Chart time", getcolor(color1));
#-------------------------------------
input oooooo__2__oooooo = 0;
# rsi #2 - diff agg time
input show_rsi_2 = yes;
input agg2 = AggregationPeriod.day;
input length2 = 14;
input over_Bought2 = 70;
input over_Sold2 = 30;
def price2 = close(period = agg2);
input averageType2 = AverageType.WILDERS;
#input showBreakoutSignals2 = no;
def rsi2 = rsi(length2, over_Bought2, over_Sold2, price2, averageType2 );
input color2 = 8;
plot z2 = if show_rsi_2 then rsi2 else na;
z2.setdefaultcolor(getcolor(color2));
addlabel(show_rsi_2, "Day", getcolor(color2));
#-------------------------------------
input oooooo__3__oooooo = 0;
# rsi #3 - diff agg time
input show_rsi_3 = yes;
input agg3 = AggregationPeriod.week;
input length3 = 14;
input over_Bought3 = 70;
input over_Sold3 = 30;
def price3 = close(period = agg3);
input averageType3 = AverageType.WILDERS;
#input showBreakoutSignals = no;
def rsi3 = rsi(length3, over_Bought3, over_Sold3, price3, averageType3 );
input color3 = 6;
plot z3 = if show_rsi_3 then rsi3 else na;
z3.setdefaultcolor(getcolor(color3));
addlabel(show_rsi_3, "Week", getcolor(color3));
# -----------------------------------
# check if all 3 rsi's are above the 3 over boughts, or below the 3 over solds.
# are the 3 RSI's > their own over bought , ( default 70)
def ob1x = (rsi1 >= over_Bought1);
def ob2x = (rsi2 >= over_Bought2);
def ob3x = (rsi3 >= over_Bought3);
def ob_3hi = (ob1x and ob2x and ob3x);
# are the 3 RSI's < their own over sold , ( default 30)
def os1x = (rsi1 <= over_Sold1);
def os2x = (rsi2 <= over_Sold2);
def os3x = (rsi3 <= over_Sold3);
def os_3lo = (os1x and os2x and os3x);
# draw a cloud in the middle
def cldtop = 60;
def cldbot = 40;
input show_cloud = yes;
addcloud( (if ob_3hi and show_cloud then cldtop else na), cldbot, color.green, color.gray);
addcloud( (if os_3lo and show_cloud then cldtop else na), cldbot , color.red, color.gray);
#plot obs1 = if show_cloud then cldtop else na;
#plot obs2 = if show_cloud then cldbot else na;
#obs1.setdefaultcolor(color.dark_gray);
#obs2.setdefaultcolor(color.dark_gray);
# --------------------------------
plot z50 = 50;
z50.setdefaultcolor(color.gray);
input show_bought_sold_level_lines = yes;
plot ob1 = if show_bought_sold_level_lines then over_Bought1 else na;
ob1.setdefaultcolor(getcolor(color1));
plot os1 = if show_bought_sold_level_lines then over_sold1 else na;
os1.setdefaultcolor(getcolor(color1));
plot ob2 = if show_bought_sold_level_lines then over_Bought2 else na;
ob2.setdefaultcolor(getcolor(color2));
plot os2 = if show_bought_sold_level_lines then over_sold2 else na;
os2.setdefaultcolor(getcolor(color2));
plot ob3 = if show_bought_sold_level_lines then over_Bought3 else na;
ob3.setdefaultcolor(getcolor(color3));
plot os3 = if show_bought_sold_level_lines then over_sold3 else na;
os3.setdefaultcolor(getcolor(color3));
#
welcomehalcyonguy, Thank you very much for this very useful indicator. I will test it from now on. I would like to know whether we can have a scan setup based on this indicator.
Yes, you can load this indicator 4 times as lower charts. Set the aggregation to what you want. In settings, unplot the additional aggregations.Thanks for the Multiple Time Frame (MTF) RSI.
How to display Multiple Time Frame (MTF) RSI separately in the lower part?
For example,
Upper part:
5-minute price chart
Lower part (these RSI below are in separated graphes, not combined into one graph):
5-minute RSI
15-minite RSI
hourly RSI
daily RSI
Does anyone know if there is a RSI label that allows you to configure it to show different time frames? For example, if watching the 5 min chart, I'd like to display on the upper left the Weekly, Daily, 4H, 1H, 30M, and 15M RSI levels.
Reasoning - it's good to know when the RSI reading for multiple timeframes reach extremes. It would be better to know this all on one chart without switching time frames.
Thank you for any help/direction in my search for this.
Code:#RSI_MTF_Labels declare upper; script R { input agg = AggregationPeriod.DAY; input length = 14; input over_Bought = 70; input over_Sold = 30; def price = close(period = agg); input averageType = AverageType.WILDERS; input showBreakoutSignals = no; def NetChgAvg = MovingAverage(averageType, price - price[1], length); def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length); def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0; plot RSI = 50 * (ChgRatio + 1); } input over_sold = 30; input over_bought = 70; def RW = R(agg = "WEEK"); def RD = R(agg = "DAY"); def R4 = R(agg = "FOUR_HOURS"); def RH = R(agg = "HOUR"); def R30 = R(agg = "THIRTY_MIN"); def R15 = R(agg = "FIFTEEN_MIN"); def R5 = R(agg = "FIVE_MIN"); AddLabel(yes, "W: " + Round(RW), if RW >= over_bought then Color.RED else if RW <= over_sold then Color.GREEN else Color.WHITE); AddLabel(yes, "D: " + Round(RD), if RD >= over_bought then Color.RED else if RD <= over_sold then Color.GREEN else Color.WHITE); AddLabel(yes, "4H: " + Round(R4), if R4 >= over_bought then Color.RED else if R4 <= over_sold then Color.GREEN else Color.WHITE); AddLabel(yes, "H: " + Round(RH), if RH >= over_bought then Color.RED else if RH <= over_sold then Color.GREEN else Color.WHITE); AddLabel(yes, "30m: " + Round(R30), if R30 >= over_bought then Color.RED else if R30 <= over_sold then Color.GREEN else Color.WHITE); AddLabel(yes, "15m: " + Round(R15), if R15 >= over_bought then Color.RED else if R15 <= over_sold then Color.GREEN else Color.WHITE); AddLabel(yes, "5m: " + Round(R5), if R5 >= over_bought then Color.RED else if R5 <= over_sold then Color.GREEN else Color.WHITE);
Start a new thread and receive assistance from our community.
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.
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.