#### netarchitech

##### Well-known member

**VIP**

**Warehouse**

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

Here is my attempt at converting it to Thinkscript:

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...

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);
```

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();
```

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

Last edited: