Do your own quantitative trading software (28) Xiaobai quantitative actual combat 2-turn red, buy, turn green, sell

Do your own quantitative trading software (28) Xiaobai Quantitative Practice 2-Turn Red, Buy, Turn Green, Sell
Investors in the stock market are divided into three categories: those who are foresight, those who know later, and those who don’t know.
The foresight is generally the main force in the market, the hindsight is generally a savvy technical analyst, and the unknowing is the loser who provides profit for the first two.
Many people claim that their analytical techniques or tools can predict the rise and fall of the market. This is not the same as a cash cow. Are there any cash cows in the world? Does the money maker need to sell for money?
Hepu always said that he was only an afterthought. Hepu indicators cannot determine how the main market forces will operate the stocks tomorrow, but they can analyze what the main players want to do now.
Hepu's Pixiu index simplifies securities operations, and fools who "turn red to hold stocks and turn green to hold currency" can learn. No matter how complex the index is, it will not be much higher than the success rate and accuracy of the Pixiu index. Because the indicators come from market data, they can only analyze the present moment and the past, what the main force wants to do, and cannot direct the main force how to operate tomorrow, so the indicator cannot be 100% accurate, and it will not be a cash cow. An indicator is an analytical tool, a ruler for comparing the quality of different stocks.
The analysis of technical indicators is based on historical repetition, so analyzing the past and predicting the future is for reference only.
For example, the main input and output indicators of Pixiu can analyze the current moment and history, the main market force (a collection of most investors), and the main statistics of buying or selling this stock.
Stocks that have been abandoned by market investors for a long time, even if they are bought in large quantities in one or two days, cannot change the fate of short-term declines.
Insert picture description here
The picture above is a stock analysis chart in 2003. Let’s take a look at the analysis in 2020.
Insert picture description here
The moving average system in the picture above is so perfect. However, this perfect trap cannot escape the analysis of Pai Yao’s main entry and exit indicators. The main force has always been to throw chips.
Insert picture description here
From a graphical point of view, it seems that the adjusted platform has broken through upwards, and most indicators such as OBV are improving. The mid-line indicator shows an air refueling trend and is ready to surge upward. In fact, a trap carefully designed by the main force. But it cannot escape the analysis of Pai Yao's main entry and exit indicators. The indicators clearly indicate signs of the main force fleeing. Since then, there have been 10 consecutive drop limits.
The main entry and exit indicator of Paixiu is an indicator of Paixiu's indicator set (https://mp.weixin.qq.com/s/c9J-d30haP5nonU3bjiwSg). I bought the book "Reading Cheats" and asked the author to use C++ to develop a set of indicators for Paixiu. This set of indicators supports software such as analysts, big wisdom, and flying fox traders.
With the creation of the new Hepo indicator, the old Hepo indicator will be gradually decrypted for everyone. This article introduces the implementation source code of the core indicator "Pixiu Trader Line", which is the core indicator of the Pixiu Trader King. This code was originally made in C++, and now it has been restored to the code of great wisdom. We are porting to Tongdaxin Software, and finally implemented this code in Python.
"Pixiu trading line" is a mid-line trend indicator, and the trend is not obvious or the market fluctuates within a narrow range, which will cause frequent trading and loss of handling fees. The operation of this indicator is very simple, "turn red to buy, turn green to sell" or "red line to hold shares, green line to hold currency".
Insert picture description here
From the graphical point of view of the Great Wisdom Software, the red line of the "Pixiu trading line" is much smaller than the time period of the green line. Therefore, only the stocks rise and turn red, and they turn green if they do not rise or fall. Therefore, the mid-line operation can make the rational use of funds, the stocks fall into green short positions, and you can get some interest.
The great wisdom source code of "Pixiu Trader Line" indicator is as follows:

S0:=(CLOSE+OPEN+LOW+HIGH)/4;
S1:=EMA(SLOPE(S0,5),60);
S2:=EMA(S1,10);
红线持股:s1,COLORRED;
绿线持币:s1,COLORGREEN;
PARTLINE(s1,s1>=s2 and s1>0 ,RGB(255,0,0),s1<s2,RGB(0,255,0),1,RGB(0,255,0)),linethick2;
0,COLORYELLOW;

Insert picture description here
The picture above shows the formula editor for the Big Wisdom Index.

The source code of the “Pixiu Trader Line” indicator is as follows:

S0:=(CLOSE+OPEN+LOW+HIGH)/4;
S1:=EMA(SLOPE(S0,5),60);
S2:=EMA(S1,10);
S3:=IF(S1>=0,S1,DRAWNULL);
S4:=IF(S1>S2 ,S3,DRAWNULL);
趋势:=S2,COLORYELLOW;
绿线持币:S1,COLORGREEN,LINETHICK3;
红线持股:S4,COLORRED,LINETHICK3;
0,COLORYELLOW;

Insert picture description here
The above picture shows the Tongdaxin Software Index Formula Editor. In Tongdaxin software, "Pixiu Trader Line" indicator display graph is as follows.
Insert picture description here
Finally we give the display source code in Python. The premise is also that you have to have the second generation module of Xiaobai Quantitative.

# -*- coding: utf-8 -*-
# 小白量化显示自编指标
'''
独狼荷蒲qq:2886002
通通小白python量化群:524949939
tkinter,pyqt,gui,Python交流2:517029284
微信公众号:独狼股票分析
'''
import
import  tkinter  as  tk   #导入Tkinter
import  tkinter.ttk  as  ttk   #导入Tkinter.ttk
import  tkinter.tix  as  tix   #导入Tkinter.tix
import  HP_tk  as  htk   #导入htk
from PIL import Image, ImageTk, ImageDraw, ImageFont
from matplotlib import ticker as mticker
import matplotlib.ticker as ticker# 先设定一个日期转换方法
import time
import HP_tdx as htdx
import  HP_view as hpv
import matplotlib.pyplot as plt
from HP_formula import *    #使用HP_formula公式基本函数库

#建立主窗口
root=htk.MainWindow(title='自定义公式演示',x=100,y=200,w=800, h=600)
#root.iconbitmap('ico/py.ico')   #设置应用程序图标

root.SetCenter()                         #移动到屏幕中央
#把window划分为左右2个子容器,左为v1,右为v2
v1=tk.Frame(root,width = 200,bg='blue')
v1.pack(side=tk.LEFT,fill=tk.Y)
v2=tk.Frame(root,bg='yellow')
v2.pack(side=tk.RIGHT, fill=tk.BOTH, expand=1)

#《零基础搭建量化投资系统—以Python为基础》树中示例 8-23
tree=ttk.Treeview(v1)
myid=tree.insert("",0,"指标",text="指标",values=("1"),open=True)
myidx1=tree.insert(myid,0,"技术指标",text="技术指标",values=("2"))
myidx2=tree.insert(myid,1,"交易系统",text="交易系统",values=("3"))
myidx3=tree.insert(myid,2,"条件选股",text="条件选股",values=("4"))
myidx4=tree.insert(myid,3,"五彩 K 线",text="五彩 K 线",values=("5"))
myidy=tree.insert("",1,"工具",text="工具",values=("6"),open=True)
myidy1=tree.insert(myidy,0,"系统设置",text="系统设置",values=("7"))
myidy1=tree.insert(myidy,0,"指标排序",text="指标排序",values=("8"))
tree.pack(side=tk.TOP,fill=tk.BOTH, expand=1)
tree.selection_set("指标")

ds='2020-01-16'  #行情开始日期
de=time.strftime('%Y-%m-%d',time.localtime(time.time()))  #行情结束日期
###---------------------------------------------------------------------------
#首先要对数据预处理
#获取数据
htdx.TdxInit(ip='183.60.224.178',port=7709)
code='603222'
df2a = htdx. get_security_bars(nCategory=4,nMarket = 0,code=code)


#六均线3指标图,K线算一个指标
ax,ax2=hpv.axview3x2(v2,df2a,code+' 六均线K线演示',6)  

#在ax区绘制荷蒲操盘线HPCPX
def ax_HPCPX(ax1,mydf):
    mydf['date']=[x[0:10] for x in mydf.date.astype(str)]
    date_tickers=mydf.date.values
    CLOSE=mydf['close']
    LOW=mydf['low']
    HIGH=mydf['high']
    OPEN=mydf['open']
    VOL=mydf['volume']
    df=mydf.copy()

    def HPCPX():
        S0=(CLOSE+OPEN+LOW+HIGH)/4
        S1=EMA(SLOPE(S0,5),60)
        S2=EMA(S1,20)
        S3=IF(S1>=0,S1,DRAWNULL())
        S4=IF(S1>S2 ,S3,DRAWNULL())
        return S1,S2,S4
    #使用HPCPX指标,返回x,y,x序列。
    x,y,z=HPCPX()
    
    df = df.join(pd.Series( x,name='CPX'))
    df = df.join(pd.Series( y,name='Y'))
    df = df.join(pd.Series( z,name='Z'))
    df['Y0']=0
    
    
    #开始绘图
    def format_date(x,pos=None): 
        if x<0 or x>len(date_tickers)-1: 
            return '' 
        return date_tickers[int(x)]
    ax1.plot(df.date.values,df.CPX.values, color= 'green', lw=2)
    ax1.plot(df.date.values, df.Z.values, color= 'red', lw=2)
    ax1.plot(df.date.values, df.Y0.values, color= 'yellow', lw=2)
    text = ax1.text(0.05, 0.05, '红线持股!绿线持币!', fontdict={
    
    'size': 20},color='yellow')
    plt.ylabel('HPCPX', color='white')
    plt.legend() # 显示图中右上角的提示信息。
    ax1.xaxis.set_major_locator(mticker.MaxNLocator(8))  #x轴分成几等分     
    ax1.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))      
    ax1.yaxis.set_major_locator(mticker.MaxNLocator(nbins=3, prune='upper'))
    ax1.grid(True, color='r')
    ax1.tick_params(axis='x', colors='white')
    ax1.tick_params(axis='y', colors='white')
    plt.subplots_adjust(left=.075, bottom=.08, right=.96, top=.96, wspace=.15, hspace=0.1)
    return ax1

#调用自定义公式
ax3=ax_HPCPX(ax2,df2a)  
plt.close() # 关窗口
root.mainloop()  	#进入Tkinter消息循环

The results of the program are as follows:
Insert picture description here
This article introduces the design techniques of technical indicators, including the discoloration and widening of the indicator line, and the program displayed in the window.
By reading my blog, you have learned how to write Tongdaxin indicators and how to write quantitative programs for Python imitation Tongdaxin indicators. Is it easy to make a Python version of Tongdaxin software?
You say it is not like Tongdaxin software, because there is no marking arrow and text prompt for buying and selling points. But don't worry, this is my next article to teach you how to implement the marking arrow and buying and selling text in the index formula on Tongdaxin software, and to achieve the same function on Python.
If you want to know the implementation technology in advance, please buy the author's book <Building a Quantitative Investment System with Zero Base-Using Python as a Tool> to purchase the website
https://item.jd.com/61567375505.html.

Please continue to pay attention to my blog, my progress is your progress!

Guess you like

Origin blog.csdn.net/hepu8/article/details/111996255