改为文华8公式 [文华财经]
-
咨询内容:
def init(context): context.n = 20 context.symbol = 'CE.i2012'nbsp; context.ratio = 0.8 subscribe(symbols=context.symbol, frequency=ླྀ' count=2) time = context.now.strftime('H:%M:%S' if ཅ00:00'< time < ཋ00:00'or ད00:00'< time < ན00:00' algo(context) schedule(schedule_func=algo, date_rule=Ƈ' time_rule=ཅ00:00' schedule(schedule_func=algo, date_rule=Ƈ' time_rule=ད00:00'def algo(context): if context.mode == 2: data = history_n(symbol=context.symbol, frequency=Ƈ' count=context.n+1, end_time=context.now, fields='lose,high,low,bob' df=True) # 计算ATR tr_list = [] for i in range(0, len(data)-1): tr = max((data['igh'.iloc[i] - data['ow'.iloc[i]), data['lose'.shift(-1).iloc[i] - data['igh'.iloc[i], data['lose'.shift(-1).iloc[i] - data['ow'.iloc[i]) tr_list.append(tr) context.atr = int(np.floor(np.mean(tr_list))) context.atr_half = int(np.floor(0.5 * context.atr))
context.don_open = np.max(data['igh'.values[-context.n:]) context.don_close = np.min(data['ow'.values[-context.n:]) if context.mode == 1: data = history_n(symbol=context.symbol, frequency=Ƈ' count=context.n, end_time=context.now, fields='lose,high,low' df=True) current_data = current(symbols=context.symbol) tr_list = [] for i in range(1, len(data)): tr = max((data['igh'.iloc[i] - data['ow'.iloc[i]), data['lose'.shift(-1).iloc[i] - data['igh'.iloc[i], data['lose'.shift(-1).iloc[i] - data['ow'.iloc[i]) tr_list.append(tr) tr_new = max((current_data[0]['igh' - current_data[0]['ow'), data['lose'.iloc[-1] - current_data[0]['igh', data['lose'.iloc[-1] - current_data[0]['ow') tr_list.append(tr_new) context.atr = int(np.floor(np.mean(tr_list))) context.atr_half = int(np.floor(0.5 * context.atr)) context.don_open = np.max(data['igh'.values[-context.n:]) context.don_close = np.min(data['ow'.values[-context.n:]) context.long_add_point = context.don_open + context.atr_half context.long_stop_loss = context.don_open - context.atr_half context.short_add_point = context.don_close - context.atr_half context.short_stop_loss = context.don_close + context.atr_halfdef on_bar(context, bars): symbol = bars[0]['ymbol' recent_data = context.data(symbol=context.symbol, frequency=ླྀ' count=2, fields='lose,high,low' close = recent_data['lose'.values[-1] position_long = context.account().position(symbol=symbol, side=PositionSide_Long) position_short = context.account().position(symbol=symbol, side=PositionSide_Short) if not position_long and not position_short: if close > context.don_open: order_volume(symbol=symbol, side=OrderSide_Buy, volume=context.atr, order_type=OrderType_Market, position_effect=PositionEffect_Open) print('多仓atr' if close < context.don_close: order_volume(symbol=symbol, side=OrderSide_Sell, volume=context.atr, order_type=OrderType_Market, position_effect=PositionEffect_Open) print('空仓atr' if position_long: if close > context.long_add_point: order_volume(symbol=symbol, volume=context.atr_half, side=OrderSide_Buy, order_type=OrderType_Market,position_effect=PositionEffect_Open) print('续加仓0.5atr' context.long_add_point += context.atr_half context.long_stop_loss += context.atr_half if close < context.long_stop_loss: volume_hold = position_long['olume' if volume_hold >= context.atr_half: order_volume(symbol=symbol, volume=context.atr_half, side=OrderSide_Sell, order_type=OrderType_Market, position_effect=PositionEffect_Close) else: order_volume(symbol=symbol, volume=volume_hold, side=OrderSide_Sell, order_type=OrderType_Market,position_effect=PositionEffect_Close) print('多仓0.5atr' context.long_add_point -= context.atr_half context.long_stop_loss -= context.atr_half if position_short: if close < context.short_add_point: order_volume(symbol = symbol, volume=context.atr_half, side=OrderSide_Sell, order_type=OrderType_Market, position_effect=PositionEffect_Open) print('续加仓0.5atr' context.short_add_point -= context.atr_half context.short_stop_loss -= context.atr_half if close > context.short_stop_loss: volume_hold = position_short['olume' if volume_hold >= context.atr_half: order_volume(symbol=symbol, volume=context.atr_half, side=OrderSide_Buy, order_type=OrderType_Market, position_effect=PositionEffect_Close) else: order_volume(symbol=symbol, volume=volume_hold, side=OrderSide_Buy, order_type=OrderType_Market,position_effect=PositionEffect_Close) print('空仓0.5atr' context.short_add_point += context.atr_half context.short_stop_loss += context.atr_half来源:程序化99
- 文华技术人员: 来源:程序化99
-
文华技术人员:这是PYTHON源码,需要联系专门开发同事,预计需要两周以上时间。有结果给您跟帖回复。
来源: WWW.CXH99.COM
-
文华客服:
好的
-
网友回复:
参考;
TR:=MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));//真实波幅 ATR:=MA(TR,26); //求26个周期内真实波幅的简单移动平均 TC..INTPART((MONEYTOT*0.8/(UNIT*ATR)));//根据权益的80%计算下单手数 HH:=HV(H,20); LL:=LV(L,20); CROSSUP(C,HH)&&ISLASTBK=0&&ISLASTSK=0&&BARPOS>=26,BK(TC);//最新价超过20周期的最高值,首次买入开仓,手数为TC手 CROSSDOWN(C,LL)&&ISLASTBK=0&&ISLASTSK=0&&BARPOS>=26,SK(TC); //最新价跌破20周期的最低值,首次卖出开仓,手数为TC手 C>=IF(ISLASTSP,REFSIG_PRICE(SP,1),BKPRICE)+0.5*ATR&&(ISLASTBK||ISLASTSP)&&BKVOL>0,BK(TC);//价格在上次开平仓的基础上上涨0.5倍ATR,买入加仓TC手 C<=IF(ISLASTBP,REFSIG_PRICE(BP,1),SKPRICE)-0.5*ATR&&(ISLASTSK||ISLASTBP)&&SKVOL>0,SK(TC);//价格在上次开平仓的基础上下跌0.5倍AT,卖出加仓TC手 C<=(IF(ISLASTSP,REFSIG_PRICE(SP,1),BKPRICE)-0.5*ATR)&&BKVOL>0,SP(MIN(TC,BKVOL));//最新价小于开平仓价减去0.5倍的ATR,止损平仓 C>=(IF(ISLASTBP,REFSIG_PRICE(BP,1),SKPRICE)+0.5*ATR)&&SKVOL>0,BP(MIN(TC,SKVOL)); //最新价大于开平仓价加上0.5倍的ATR,止损平仓 TRADE_AGAIN(10);
有思路,想编写各种指标公式,交易模型,选股公式,还原公式的朋友
可联系技术人员 QQ: 262069696 或微信号:cxh99cxh99 进行 有偿收费 编写!
(注:由于人数限制,QQ或微信请选择方便的一个联系我们就行,加好友时请简单备注下您的需求,否则无法通过。谢谢您!)
相关文章
-
没有相关内容