joeldg / bowhead

PHP trading bot framework
Apache License 2.0
801 stars 288 forks source link

Incorrect use of MACD / SMA / EMA ... in Indicators? #114

Open sixcom opened 6 years ago

sixcom commented 6 years ago

I am curious about the usage of results of something like trader_macd() / trader_sma() ?

  1. $this->getRecentData() gets the data in descending order e.g. <?php return [ '2018-01-03' => 5, '2018-01-02' => 15, '2018-01-01' => 20, ];

  2. trader_sma($recnetData, 2) will get <?php return [ 10, 20]

  3. In the code, pretty much everywhere uses array_pop() which returns the last element of array (in this case 20 is returned, but actually 10 is the latest SMA)

Is this correct? The default data size is 168, if the interval is one day then SMA result is average of some price data 100+ days ago, should it use the first element from the result array?

nasyrov commented 6 years ago

@sixcom just use array_reverse before you pass your data to indicators

joeldg commented 6 years ago

see: https://github.com/joeldg/bowhead/blob/master/app/Traits/OHLC.php#L33

nasyrov commented 6 years ago

@joeldg fair enough