唐奇安通道
唐奇安通道刻画
通道上界=过去20日内的最高价
通道下界=过去20日内的最低价
中轨道计算公式:
中 轨 道 = 通 道 上 界 + 通 道 下 界 2 中轨道=\frac{通道上界+通道下界}{2} 中 轨 道 = 2 通 道 上 界 + 通 道 下 界
import pandas as pd
import numpy as np
import matplotlib. pyplot as plt
ChinaUnicom= pd. read_csv( 'ChinaUnicom.csv' )
ChinaUnicom. index= ChinaUnicom. iloc[ : , 1 ]
ChinaUnicom. index= pd. to_datetime( ChinaUnicom. index, format = '%Y-%m-%d' )
ChinaUnicom= ChinaUnicom. iloc[ : , 2 : ]
Close= ChinaUnicom. Close
High= ChinaUnicom. High
Low= ChinaUnicom. Low
upboundDC= pd. Series( 0.0 , index= Close. index)
downboundDC= pd. Series( 0.0 , index= Close. index)
midboundDC= pd. Series( 0.0 , index= Close. index)
for i in range ( 20 , len ( Close) ) :
upboundDC[ i] = max ( High[ ( i- 20 ) : i] )
downboundDC[ i] = min ( Low[ ( i- 20 ) : i] )
midboundDC[ i] = 0.5 * ( upboundDC[ i] + downboundDC[ i] )
upboundDC= upboundDC[ 20 : ]
downboundDC= downboundDC[ 20 : ]
midboundDC= midboundDC[ 20 : ]
plt. rcParams[ 'figure.figsize' ] = ( 20.0 , 10.0 )
plt. rcParams[ 'font.sans-serif' ] = [ 'SimHei' ]
plt. plot( Close[ '2013' ] , label= "Close" , color= 'k' )
plt. plot( upboundDC[ '2013' ] , label= "upboundDC" , color= 'b' , linestyle= 'dashed' )
plt. plot( midboundDC[ '2013' ] , label= "midboundDC" , color= 'r' , linestyle= '-.' )
plt. plot( downboundDC[ '2013' ] , label= "downboundDC" , color= 'b' , linestyle= 'dashed' )
plt. title( "2013年中国联通股价唐奇安通道" )
plt. ylim( 2.9 , 3.9 )
plt. legend( )
<matplotlib.legend.Legend at 0x11737cef0>
plt. rcParams[ 'figure.figsize' ] = ( 20.0 , 10.0 )
upDownDC= pd. DataFrame( {
'upboundDC' : upboundDC, \
'downboundDC' : downboundDC} )
ChinaUnicom13= ChinaUnicom[ '2013-01-01' : '2013-06-28' ]
upDownDC13= upDownDC[ '2013-01-01' : '2013-06-28' ]
import candle
candle. candleLinePlots( candleData= ChinaUnicom13, \
splitFigures= False , \
candleTitle= '中国联通2013年上半年K线图及唐奇安通道' , \
Data= upDownDC13)
python捕捉唐奇安通道突破
当价格先走强而突破前n期的最高价时做多,当价格先向下运动,价格低于前n期的最低价时做空。
def upbreak ( tsLine, tsRefLine) :
n= min ( len ( tsLine) , len ( tsRefLine) )
tsLine= tsLine[ - n: ]
tsRefLine= tsRefLine[ - n: ]
signal= pd. Series( 0 , index= tsLine. index)
for i in range ( 1 , len ( tsLine) ) :
if