def entry(context, data, s, lot=LOT):
def order_to(n):
sod = context.stop_order.pop(s, None)
# cancel_order(sod.id)
if sod:
o = get_order(sod)
if o.is_open:
o.cancel()
n *= 2
order(s, n)
# cancel former stop_order
dc = data.history(s, fields="close", length=MA_SLOW_LEN).values
ma_fast = context.ma_fast[s]
ma_slow = context.ma_slow[s]
ma_fast[0] = ma_fast[1]
ma_slow[0] = ma_slow[1]
try:
ma_fast[1] = ta.MA(dc, MA_FAST_LEN)[-1]
ma_slow[1] = ta.MA(dc, MA_SLOW_LEN)[-1]
except:
return
if ma_fast[0] <= ma_slow[0] and ma_fast[1] > ma_slow[1]:
order_to(lot)
elif ma_fast[0] >= ma_slow[0] and ma_fast[1] < ma_slow[1]:
order_to(-lot)
评论列表
文章目录