Sell Relative Strength Index TASC Code Conversion

The TASC March 2019 issue includes "Sell Relative Strength Index" by Howard Wang. The EasyLanguage code follows and I'd like to know how to convert it.

TradeStation EasyLanguage (ELS) for SRSI
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) ;

I have done two versions with and without looping. My straight up conversion follows and does not yield anything near what the article displays.

/*	Fromulas\\Custom\\S&C\\Rel Str\\Sell Relative Strength Index Alt_1.afl
	TASC Feb 2019 by Howard Wang
	Use as: Indicator
	
	TradeStation EsayLanguage	*/

//	Inputs
Len = Param( "Length", 20, 1, 100, 1 );
//	Vars
srsi = srsin = k = 0 ;

// for( k = 0; k < BarCount; k++ )
for( k = 0; k < Len - 1; k++ )
{
	// BEGIN body of the loop
	Value1 = abs( Close[ k ] - Open[ k ] ) ;
	Value2 = abs( High[ k ] - Low[ k ] ) ;
  
	if( Value2 == 0 ) 
		Value3 = 0 ;
	else
	{
		Value3 = Value1 / Value2 ;
	}
	
	srsin = srsin + Value3 ;
}
	// END
	
srsi = srsin / Len ;

// Color = IIf( srsi > 0, colorGreen, IIf( srsi < 0, colorRed, srsi >= -0.05 AND srsi <= 0.05, colorYellow )) ;
Color = colorBrightGreen ;

Plot( 0.38,  "",     colorDarkRed ,  styleLine );	// Plot 1
Plot( srsi,  "srsi", Color, 	     styleLine ) ;	// Plot 2
Plot( -0.38, "",     colorDarkGreen, styleLine );	// Plot 3
Plot( 0.00,  "",     colorYellow,    styleLine ) ;	// Plot 4

Thank you for your time and consideration, John

@Coltrane153,

It is pretty simple... that EA loop code is nothing more and nothing less other than calculating simple moving average -> so using MA() function in AB. BTW, absvalue makes no sense to me since the code uses negative levels (-> see-0.38, -0.05). If you use abs then it will never go negative (and H-L will be >=0 anyway). So I have commented abs function.

/// TASC Feb 2019 Sell Relative Strength Index by Howard Wang
/// @link https://forum.amibroker.com/t/sell-relative-strength-index-tasc-code-conversion/11884/2
/// AFL version by fxshrat
GraphXSpace = 10;
length = 20;

Value1 = /*abs*/(close - open);
Value2 = /*abs*/(high - low);
Value3 = value1 / (value2+1e-9);
srsi = MA(Value3, length);

srsi_color = IIf(srsi > 0.05, colorGreen, 
			 IIf(srsi < -0.05, colorRed, 
			 IIf(srsi >= -0.05 AND srsi <= 0.05, colorYellow, colorDefault)));

PlotGrid( 0.38, colorDarkRed, pattern = 8, width = 2, label = true);// Plot 1
Plot( srsi, "", srsi_color, styleLine  );// Plot 2
PlotGrid( -0.38, colorDarkGreen, pattern, width, label );// Plot 3
PlotGrid( 0.00,  colorYellow, pattern, width, label ) ;	// Plot 4

_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} - {{DATE}} %s SRSI: %g",
                       EncodeColor( SelectedValue( srsi_color ) ), SelectedValue( srsi ) ) );

30

7 Likes

Fxshrat,

Thank you. Fantastic solution for removing the looping code. -- John

1 Like