-
Notifications
You must be signed in to change notification settings - Fork 54
蜡烛图形态
ChannelCMT edited this page Jun 4, 2019
·
1 revision
用TA_Lib寻找蜡烛图特征
-
蜡烛图是什么?
-
蜡烛图的两大用途是什么?
-
常见蜡烛图是怎么计算的?
-
蜡烛图如何用图表显示,并用TA_Lib寻找蜡烛图?
蜡烛图又称为K线图,主要包含四个数据,即开盘价、最高价、最低价、收盘价,所有的蜡烛图都是围绕这四个数据展开,反映大势的状况和价格信息。如果把每日的K线图放在一张图中,就能得到日K线图,同样也可画出周K线图、月K线图。
- 判断反转信号
- 判断持续信号
Close/Open>1.05
High/Low < Close/Open+0.018
Open/Close > 1.05
High/Low < Open/Close+0.018
(Min(Close,Open)-Low)/(High-Low)>0.667
(High-Max(Close,Open))/(High-Low)>0.667
Close-Open<Abs(0.001)
High-Low>0.001
open[-1]-close[-2]>0.01
import warnings
warnings.filterwarnings('ignore')
from jaqs_fxdayu.data.dataservice import LocalDataService
ds = LocalDataService()
from time import time
## 加freq参数
start = time()
path = r'../min_data/VnTrader_1Min_Db'
props = {'fields': 'open,high,low,close,volume','symbol': 'BTCUSDT:binance', 'freq': '8H',
'start_date':20180801000000}
Time_dict = ds.bar_reader(path,props)
print(time()-start)
5.192053318023682
data1H = Time_dict.set_index('datetime')
from jaqs_fxdayu.data.hf_dataview import HFDataView
dv1H = HFDataView()
dv1H.create_init_dv(Time_dict.set_index(["trade_date","symbol"]))
Initialize dataview success.
def location(df):
Location = (df.close-df.low.rolling(50).min())/(df.high.rolling(50).max()-df.low.rolling(50).min())*100
return Location
Location = location(data1H)
# Location
观察蜡烛图和成交量的关系,找到信号。
import matplotlib.pyplot as plt
import mpl_finance as mpf
def draw_candle(candle, scatterX, scatterY):
fig, (ax, ax1) = plt.subplots(2,1,sharex=True, figsize=(18,10))
ax.grid(True)
mpf.candlestick_ohlc(ax, candle, width=0.3, colorup='r', colordown='g',alpha=1.0)
ax.scatter(scatterX, scatterY, color='b', s=100, marker='^')
ax.xaxis_date ()
ax1.bar(data1H.index, data1H.volume)
plt.show()
Big_Up = dv1H.add_formula('Big_Up','If((close/open>1.02) && (high/low<(close/open+0.02)), 100, 0)', add_data=True)
Big_Up[Big_Up['BTCUSDT:binance']==100]
symbol | BTCUSDT:binance |
---|---|
trade_date | |
20180813080000 | 100.0 |
20180815000000 | 100.0 |
20180815080000 | 100.0 |
20180817080000 | 100.0 |
20180821080000 | 100.0 |
20180825000000 | 100.0 |
20180828000000 | 100.0 |
20180909160000 | 100.0 |
20180921080000 | 100.0 |
dataBigUp = dv1H.get_ts('Big_Up', date_type='datetime')
dataBigUp[dataBigUp['BTCUSDT:binance']==100].index
DatetimeIndex(['2018-08-13 08:00:00', '2018-08-15 00:00:00',
'2018-08-15 08:00:00', '2018-08-17 08:00:00',
'2018-08-21 08:00:00', '2018-08-25 00:00:00',
'2018-08-28 00:00:00', '2018-09-09 16:00:00',
'2018-09-21 08:00:00'],
dtype='datetime64[ns]', name='trade_date', freq=None)
scatterBigUpX = dataBigUp[dataBigUp['BTCUSDT:binance']==100].index
scatterBigUpY = data1H.loc[scatterBigUpX].low-100
设置candle
from matplotlib.pylab import date2num
data1H['candleTime'] = list(map(date2num, data1H.index))
candle = data1H.reindex_axis(["candleTime", "open", "high", "low", "close"], 1).values
draw_candle(candle, scatterBigUpX, scatterBigUpY)
# dataBigUp[dataBigUp['BTCUSDT:binance']==100]
(Min(Close,Open)-Low)/(High-Low)>0.667
观察蜡烛图和成交量的关系,找到信号
import pandas as pd
pd.Series(list(map(lambda a,b : min(a,b), data1H['close'],data1H['open'])),index=data1H.index).tail()
datetime
2018-09-20 08:00:00 6392.00
2018-09-20 16:00:00 6411.00
2018-09-21 00:00:00 6417.77
2018-09-21 08:00:00 6492.00
2018-09-21 16:00:00 6647.91
dtype: float64
lowerShadow = dv1H.add_formula('lowerShadow','If((((Min(close,open)-low)/(high-low))>0.7),100,0)', add_data=True)
datalowerShadow = dv1H.get_ts('lowerShadow', date_type='datetime')
# datalowerShadow
scatterlowerShadowX = datalowerShadow[datalowerShadow['BTCUSDT:binance']==100].index
scatterlowerShadowX
DatetimeIndex(['2018-08-02 00:00:00', '2018-08-06 16:00:00',
'2018-08-07 00:00:00', '2018-08-12 16:00:00',
'2018-09-11 00:00:00'],
dtype='datetime64[ns]', name='trade_date', freq=None)
scatterlowerShadowY = data1H.loc[scatterlowerShadowX].low-100
draw_candle(candle, scatterlowerShadowX, scatterlowerShadowY)
- Three-line strike, bearish: 84% ta.CDL3LINESTRIKE
- Three white soldiers: 82% ta.CDL3WHITESOLDIERS
- Engulfing, bearish: 79% ta.CDLENGULFING
- Morning star: 78% ta.CDLMORNINGSTAR
- Morning doji star: 76% ta.CDLMORNINGDOJISTAR
engulfing = dv1H.add_formula('engulfing', "If((Ta('CDLENGULFING', 0, open, high, low, close, volume)==100),100,0)", add_data=True)
engulfingVolume = dv1H.get_ts('engulfing', date_type='datetime')
engulfingVolume[engulfingVolume['BTCUSDT:binance']==100]
symbol | BTCUSDT:binance |
---|---|
trade_date | |
2018-08-19 16:00:00 | 100.0 |
2018-08-31 00:00:00 | 100.0 |
2018-09-01 00:00:00 | 100.0 |
2018-09-04 08:00:00 | 100.0 |
engulfingVolumeX = engulfingVolume[engulfingVolume['BTCUSDT:binance']==100].index
engulfingVolumeY = data1H.loc[engulfingVolumeX].low-100
draw_candle(candle, engulfingVolumeX, engulfingVolumeY)
-
python基础
-
python进阶
-
数据格式处理
-
数据计算与展示
-
因子横截面排序分析
-
信号时间序列分析
-
CTA策略类型
-
附录:因子算法