Sell Relative Strength Index (sRSI) Indicator for ThinkorSwim

netarchitech

netarchitech

New member
I'm trying to convert a Tradestation ELS into Thinkscript. Here is the Tradestation code:

Rich (BB code):
inputs:
Length(20);

vars:
srsi(0),
srsin(0),
k(0);

srsin = 0;
For k = 0 to Length - 1
Begin
Value1 = absvalue(close[k] - open[k];
Value2 = absvalue(high[k] - low[k];
If value2 = 0 then value3 = 0
Else
Value3 = value1/value2;
srsin = srsin + value3;
End;

srsi = srsin/length;

plot1(0.38);
plot2(srsi);
plot3(-0.38);
plot4(0);
If srsi > 0 then Setplotcolor(2,green);
If srsi < 0 then Setplotcolor(2,red);
If srsi >= -0.05 and srsi <= 0.05 then Setplotcolor(2,yellow);

Setplotcolor(1,darkred);
Setplotcolor(3,darkgreen);
Setplotcolor(4,yellow);
Here is my attempt at converting it to Thinkscript:

Rich (BB code):
declare lower;

input Length = 20;

def srsi = 0;
def srsin = 0;
def k = 0;

plot iteration = fold k = 0 to Length - 1;

def Value1 = absvalue(close[k] - open[k]);
def Value2 = absvalue(high[k] - low[k]);
def Value = if value2 == 0 then value3 == 0 else value3 == value1 / value2;

def srsin = srsin + value3;

def srsi = srsin / Length;

plot line1 = 0.38;
line1.SetDefaultColor(Color.DARK_RED);
line1.HideTitle();
line1.HideBubble();

plot line2 = srsi;
line2.AssignValueColor(if srsi > 0 then Color.GREEN 
else if srsi < 0 then Color.RED 
else if srsi >= -0.05 and srsi <= 0.05 then Color.YELLOW 
else Color.GRAY);
line2.SetLineWeight(2);
line2.HideTitle();

plot line3 = -0.38;
line3.SetDefaultColor(Color.DARK_GREEN);
line3.HideTitle();
line3.HideBubble();

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.ORANGE);
ZeroLine.HideTitle();
ZeroLine.HideBubble();
The Thinkscript compiler says the fold statement is invalid. This is the first time I've attempted to work with a fold statement.



Any assistance would be greatly appreciated. Thanks in advance...

 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
[[2,13],[13]]
 
Last edited:
netarchitech

netarchitech

New member


Success! For those of you whom might be interested in taking the converted code for a test drive:

Rich (BB code):
declare lower;

input len = 7; #changed from the setting of 20 per the instructions of the original author

def srsin;
def value1 = close - open;
def value2 = high - low;
def value3 = if value2 == 0 then 0
else value1 / value2;

srsin = Sum(value3, len);

plot srsi = srsin / len;
srsi.assignValueColor(if srsi > 0.05 then Color.GREEN
else if srsi<-0.05 then color.red
else color.yellow);

plot l1 = 0.38 ; 
l1.SetDefaultColor(Color.DARK_RED);

plot l2 = -0.38; 
l2.SetDefaultColor(Color.DARK_GREEN);

plot zline = 0;
zline.SetDefaultColor(Color.ORANGE);
Good Luck and Good Trading!

 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@netarchitech Glad you got it work &#128515;

 
Last edited:
netarchitech

netarchitech

New member
@BenTen Yeah, me too... It was a good learning experience :)

 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@netarchitech What is this indicator called? I'll help you change the title and move it into the proper category?

 
Last edited:
netarchitech

netarchitech

New member
@BenTen Thanks :) It's called sRSI...

 
Last edited:
J

john3

New member
VIP
What are the upper indicators? Would you please post links for them?

Thank you.

 
Last edited:

Top