0

I'm trying to calculate the RSI using the Poloniex API and PHP Trader EXtension. Here is what i have so far.

date_default_timezone_set( 'UTC' );

$api = new poloniex( 'xxxxxxx', 'xxxxx' );

$data = $api->getChartValues( 'BTC_LTC', strtotime( "-21 hours" ), time(), 300 );
print_r( $data);

$rsi = array();
foreach ( $data as $a )
{
    $rsi[] = $a['close'];
}
$rsi = trader_rsi(  array_reverse($rsi) , 14 );

The getChartValues calls the returnChartData API Function from Poloniex API. After running the script, the output RSI is completely different than the valid one.

What i'm doing wrong?

user3393046
  • 163
  • 1
  • 7
  • 15

2 Answers2

2

maybe there is no need to reverse, here is my code that works fine

$rsi = array();
foreach ( $data as $a )
{
    $rsi[] = $a['close'];
}
$rsi = trader_rsi( $rsi , 14 );
print_r( $rsi );
0

According to the RSI definition:

The relative strength index is calculated using the following formula: RSI = 100 - 100 / (1 + RS) Where RS = Average gain of up periods during the specified time frame / Average loss of down periods during the specified time frame/ [...]

The default time frame for comparing up periods to down periods is 14, as in 14 trading days.

Are you sure that the RS parameter in your computation is exactly the same than in "the valid one" ? And according to you what is "the valid one" source ?

A. STEFANI
  • 6,707
  • 1
  • 23
  • 48