掘金社区
大家好,请教一个编写的问题,
def on_bar(context, bars): #数据推送时间 bob开始时间 eob是结束时间
print(bars[0].bob)
recent_data = context.data(symbol=context.symbol, frequency='900s', count=56, fields='close,high,low') # 获取数据
if close[-1] > ema10[-1] and close[-2] < ema10[-2]: # K线上穿均线,
order_target_percent(context.symbol, percent=0.5, position_side=1, order_type=OrderType_Market) # 买入半仓
order = order_target_percent(context.symbol, percent=0.3, position_side=1, order_type=OrderType_Market)
print(order[0]['filled_vwap']) # 返回成交的均价。
dealprice = order[0]['filled_vwap']
if ????:
print(context.symbol, '达到3%的涨幅,平仓')
if ????:
print(context.symbol, '达到-1%的涨幅,止损平仓')
如果涨幅(从成交的均价开始算)达到了3%,则全平仓止盈。
如果跌幅(从成交的均价开始算)达到了-1%,则全平仓止损
请大家帮忙写一下了,谢谢,谢谢,谢谢!
评论: 2
-
计算涨跌幅
ration = (bars[0]['close']/position.vwap) - 1
if ration > 0.03:
order()
if ration < -0.01:
order() -
@evergreen 谢谢