finlab-python / finlab_crypto

Documentation
https://finlab-python.github.io/finlab_crypto/index.html
GNU General Public License v3.0
267 stars 98 forks source link

candles color inverted #18

Closed AmandaRossimandi closed 2 years ago

AmandaRossimandi commented 2 years ago

the colors red and green of the candlesticks render seems inverted. In uptrend are red, downtrend green I think should be the opposite.

For example like the pictures here: https://www.mt5traders.com/trend-candlesticks-metatrader-4-forex-indicator/

penguinwang96825 commented 2 years ago

@AmandaRossimandi There is no wrong with the implementation. In Taiwan's stock market, the green symbol indicates that a stock's price has decreased over the previous day's price, while the red symbol indicates that it has increased. Hope this helps.

AmandaRossimandi commented 2 years ago

@AmandaRossimandi There is no wrong with the implementation. In Taiwan's stock market, the green symbol indicates that a stock's price has decreased over the previous day's price, while the red symbol indicates that it has increased. Hope this helps.

tnx, I would like to change it to make it compliant to european standard. Can you suggest where to flip the color in the code or add an arg parameter, like for example the string country='EU', and set it automatically ?

finlab-python commented 2 years ago

Update this issue on finlab_crypto==0.2.19 version. use k_colors arg to control klines color

k_colors: A string value(world or taiwan) of kline color for diff area. Or use dict format like {'increasing_line':'#c12828', 'decreasing_line':'#83a3db'}, default value is world.

code example:

import finlab_crypto
finlab_crypto.setup()

ohlcv = finlab_crypto.crawler.get_all_binance('BTCUSDT', '4h')

def sma_strategy(ohlcv):
  close = ohlcv.close
  sma20 = close.rolling(20).mean()
  sma60 = close.rolling(60).mean()

  entries = (sma20 > sma60) & (sma20.shift() < sma60.shift())
  exits = (sma20 < sma60) & (sma20.shift() > sma60.shift())
  return entries, exits

from finlab_crypto import Strategy
import numpy as np

@Strategy(sma1=20, sma2=60)
def sma_strategy(ohlcv):
  close = ohlcv.close
  sma20 = close.rolling(sma_strategy.sma1).mean()
  sma60 = close.rolling(sma_strategy.sma2).mean()

  entries = (sma20 > sma60) & (sma20.shift() < sma60.shift())
  exits = (sma20 < sma60) & (sma20.shift() > sma60.shift())

  figures = {
      'overlaps': {
          'sma20': sma20,
          'sma60': sma60
      }
  }
  return entries, exits, figures

portfolio = sma_strategy.backtest(ohlcv, freq='4h', plot=True,k_colors='world') 
portfolio = sma_strategy.backtest(ohlcv, freq='4h', plot=True,k_colors='taiwan')
portfolio = sma_strategy.backtest(ohlcv, freq='4h', plot=True,k_colors={'increasing_line':'#c12828', 'decreasing_line':'#83a3db'})