list:df=self.dflast_buy_in_date=Nonelast_buy_in_price=0last_sell_out_date=Nonelast_sell_out_price=0buy_sell_dict={}buy_sell_list=["/>
#A股api交易接口止损策略模块defstrategy_stop_lose->bool:df=self.dfif>:returnTrueelse:returnFalse#A股api交易接口设置买卖止损值defset_stop_lose_num->int:df=self.dfreturndf["阻力线"][i]-df["中界线"][i]#买卖框架主函数,[{"buy_date":buy_date,"buy_price":buy_price,"sell_date":sell_date,"sell_price":sell_price},{}...]defstock_strategy_main->list:df=self.dflast_buy_in_date=Nonelast_buy_in_price=0last_sell_out_date=Nonelast_sell_out_price=0buy_sell_dict={}buy_sell_list=[]foriindf.index[20:]:ifself.flag_buy_in:#有没有条件买入做空,默认为没有买入条件Falseifself.strategy_buy_in:#最高价大于BOLL上端线了,买买买,空空空,不要怂,就是干last_buy_in_date=i#买入日期记录一下last_buy_in_price=df["Close"][i]#买入价格记录一下,后边好算盈亏self.stop_lose_num=self.set_stop_lose_num#设好止损,以防踩坑上不来self.flag_buy_in=False#买入后,停止买入判断,以防买太多,死的惨self.need_sell_out=True#开启卖出状态continueifself.need_sell_out:#是否需要卖出,买入了就需要卖出#能不能正常卖出,能的话,就准备继续买入,扩大战果ifself.strategy_stop_win:#是否需要获利了结last_sell_out_date=i#记录卖出日期last_sell_out_price=df["Close"][i]#记录卖出价格buy_sell_dict={"buy_date":last_buy_in_date,"buy_price":last_buy_in_price,"sell_date":last_sell_out_date,"sell_price":last_sell_out_price}buy_sell_list.appendbuy_sell_dict={}self.need_sell_out=False#卖光啦,不需要再卖出啦self.flag_buy_in=True#空仓啦,可以准备再买点,发财,发财continue#需要止损了,忍痛割爱,冷静一下,暂时不具备买入条件elifself.strategy_stop_lose:last_sell_out_date=i#记录卖出日期last_sell_out_price=df["Close"][i]#记录卖出价格buy_sell_dict={"buy_date":last_buy_in_date,"buy_price":last_buy_in_price,"sell_date":last_sell_out_date,"sell_price":last_sell_out_price}buy_sell_list.appendbuy_sell_dict={}self.need_sell_out=False#卖了,不需要再卖出啦continue#没有需要卖出的商品,那就看看能不能准备买入,做点小买卖ifself.need_sell_outisFalse:ifself.strategy_open:#空头还可以嘛,再上去我就做空self.flag_buy_in=True#开启买入做空模式continuereturnbuy_sell_list
文章为作者独立观点,不代表股票交易接口观点