Reference the previous low’s RSI


Category:
0
0

Hi Pete, I appreciate all the great work you do here.  I was wondering if there is a way to reference a previous low’s RSI.  For instance within the last 30 bars a lowest low was achieved.  I would like to reference the RSI when that low occurred.  Please see the pic as reference.

I am able to do it with price, I believe, with the following code.  Is there a way to reference the RSI for that low?

input period = 30;

def lo = low;
def lowprice = Lowest(lo[1], period);

I tried using the following to reference the RSI. The problem, it seems, is that it catches the previous bars RSI if that bars low is lower than the current bar.  So I get false signals.

def lo = RSI();

def lowrsi = Lowest(lo[1], period);

Any help is appreciated.  Please let me know if I need to word the question differently to understand what I mean to accomplish.

Attachments:
Marked as spam
Posted by (Questions: 5, Answers: 2)
Asked on July 30, 2019 6:25 pm
165 views
0
Private answer

When providing a screenshot with your post it is imperative that you include the entire chart view. We need to be able to see the ticker symbol you have loaded on your chart as well as the time frame selected. Otherwise, how are we supposed to replicate your exact scenario when developing the solution?

Despite this, I am able to come up with my own example. The code is two lines. Please examine this code compare it to yours. The code you provided makes use of extra steps which are not required. The only time you want to add extra steps to your code is when you need to make it easier to read. And I can assure you that this does not make it easier to read:

def lo = RSI();
def lowrsi = Lowest(lo[1], period);

To answer your implied question, placing the '[1]' after the variable name as shown above has the affect of excluding the current bar from the test for Lowest in x bars.

In order to quickly acheive your stated goals in the fewest lines we have only to incorporate two functions provided in the Thinkorswim language:

GetMinValueOffset(): http://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/GetMinValueOffset.html

GetValue(): http://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others/GetValue.html

Here is the code, along with a screenshot below to show the result.

declare lower;
def targetBars = GetMinValueOffset(low, 30);
plot rsiAtLow = GetValue(RSI(), targetBars);

This makes for code that is easiest to read. However we could compact this further and do all the work in a single line:

plot rsiAtLow = GetValue(RSI(), GetMinValueOffset(low, 30));

This is nice and tidy, however if you need to debug your code at some point in the future it may be difficult to unravel.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on July 31, 2019 10:20 am