Help me write a trend script with RSI and DMI

crawford5002

Member
VIP
looking for someone to help me with a script that includes Relative strength index and the directional movement indicator, I'm new to this so bare with me, what I'm looking for is a trend trade indicator that is color coded, with the relative strength index that includes the 15min, 30min, and 1hr at or above the RSI 60 , also including the directional movement indicator at or above 25 to show a bullish move.

Thanks in Advance
 

BenTen

Administrative
Staff member
Staff
VIP
A few questions:

1. You want an MTF (multi timeframe) version of the RSI indicator?
2. You want to combine the RSI and DMI indicator together?
 

BenTen

Administrative
Staff member
Staff
VIP
Here is an example scanner. You can get started by clicking on the Scan tab in your ThinkorSwim and add the same conditions below.

acqaTE9.png
 

crawford5002

Member
VIP
Here is an example scanner. You can get started by clicking on the Scan tab in your ThinkorSwim and add the same conditions below.

acqaTE9.png
the DMI greater than or equal to 25 on the same timeframes 15 30 1hr to start off, then I will make adjustment if need be, thanks again I just started using thinkorswim so I'm trying to figure this out
 

BenTen

Administrative
Staff member
Staff
VIP
Shouldn't be a problem but the issue with multi timeframe indicator is that you always have to wait for the candle from the highest timeframe to close in order to confirm the trend direction otherwise you may see fluctuation between signals. I am not sure if you guys are well aware of that.
 

crawford5002

Member
VIP
Shouldn't be a problem but the issue with multi timeframe indicator is that you always have to wait for the candle from the highest timeframe to close in order to confirm the trend direction otherwise you may see fluctuation between signals. I am not sure if you guys are well aware of that.
ok understand, how about just the the Trend indicator with the RSI at or above 60 and the DMI at or above 25 for just the time frame you have your chart on, if anything I can watch all 3 time frames
 

Rojo Grande

Member
VIP
Hello,
Is it possible to get the down arrows on top of trend line, and the up arrows below the trend line?
n3ROBoW.png


Here is the code I have

Code:
declare lower;

input length = 7;
input over_Bought = 60;
input over_Sold = 40;
input mid_line = 50;
input price = close;
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);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot MidLine = mid_line;
plot UpSignal = if RSI crosses above RSI[1] then OverSold else Double.NaN;
plot DownSignal = if RSI crosses below RSI[1] then OverBought else Double.NaN;


UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", GetColor(1));
RSI.AssignValueColor(if RSI > RSI[1] then color.GREEN else if RSI < RSI[1] then color.RED else color.gray);
OverSold.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(8));
MidLine.SetDefaultColor(Color.MAGENTA);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 

horserider

Well-known member
VIP
@crawford5002 Just playing around , take a look.
Code:
declare lower;

input length = 14;
input over_Bought = 60;
input over_Sold = 25;
input mid_line = 50;
input price = close;
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);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot MidLine = mid_line;



RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", GetColor(1));
RSI.AssignValueColor(if RSI > RSI[5] then color.GREEN else if RSI < RSI[5] then color.RED else color.gray);

##################################################################
input lengthdmi = 14;
input averageTypedmi = AverageType.WILDERS;

def hiDiff = high - high[1];
def loDiff = low[1] - low;

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(averageTypedmi, TrueRange(high, close, low), lengthdmi);
plot "DI+" = 100 * MovingAverage(averageTypedmi, plusDM, lengthdmi) / ATR;


"DI+".AssignValueColor(if "DI+" > 25 then color.LIME else if "DI+" < 25 then color.PINK else color.gray);


plot UpSignal = if RSI >= 60 and "DI+" crosses above 25 then OverSold else Double.NaN;
UpSignal.SetHiding(!showBreakoutSignals);
OverSold.SetDefaultColor(Color.WHITE);
OverBought.SetDefaultColor(Color.WHITE);
MidLine.SetDefaultColor(Color.GRAY);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
 

crawford5002

Member
VIP
@crawford5002 Just playing around , take a look.
Code:
declare lower;

input length = 14;
input over_Bought = 60;
input over_Sold = 25;
input mid_line = 50;
input price = close;
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);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot MidLine = mid_line;



RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", GetColor(1));
RSI.AssignValueColor(if RSI > RSI[5] then color.GREEN else if RSI < RSI[5] then color.RED else color.gray);

##################################################################
input lengthdmi = 14;
input averageTypedmi = AverageType.WILDERS;

def hiDiff = high - high[1];
def loDiff = low[1] - low;

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(averageTypedmi, TrueRange(high, close, low), lengthdmi);
plot "DI+" = 100 * MovingAverage(averageTypedmi, plusDM, lengthdmi) / ATR;


"DI+".AssignValueColor(if "DI+" > 25 then color.LIME else if "DI+" < 25 then color.PINK else color.gray);


plot UpSignal = if RSI >= 60 and "DI+" crosses above 25 then OverSold else Double.NaN;
UpSignal.SetHiding(!showBreakoutSignals);
OverSold.SetDefaultColor(Color.WHITE);
OverBought.SetDefaultColor(Color.WHITE);
MidLine.SetDefaultColor(Color.GRAY);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Perfect Thank you
 

crawford5002

Member
VIP
Shouldn't be a problem but the issue with multi timeframe indicator is that you always have to wait for the candle from the highest timeframe to close in order to confirm the trend direction otherwise you may see fluctuation between signals. I am not sure if you guys are well aware of that.
can help me with labels on the chart showing the 1min RSI 5minRSI and the 15min RSI labels turning green if =60 or greater , yellow if= 50-59, red under 50
 

BenTen

Administrative
Staff member
Staff
VIP
@crawford5002 You need to adjust the timeframe within the code to 15m. Plus, you can only display data from a higher timeframe onto a lower timeframe.

Example: you can add a label to show 15min RSI on the 5m chart but not the other way around.
 

Similar threads

Top