Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update函数,更新持仓状态,没有新的开仓event,也会更新 last_event #139

Open
PingFeng233 opened this issue Apr 7, 2023 · 1 comment

Comments

@PingFeng233
Copy link

czsc/objects.py

 # 当有新的开仓 event 发生,更新 last_event
  if op in [Operate.LO, Operate.SO]:
      self.last_event = {'dt': dt, 'bid': bid, 'price': price, 'op': op, 'op_desc': op_desc}

这段代码是否应该判断一下有无持仓,只要开仓之后last_event会一直更新,会导致下面判断止损的代码price 和 self.last_event['price']的值是一样的

# 多头止损
  if price / self.last_event['price'] - 1 < -self.stop_loss / 10000:
      self.pos = 0
      self.operates.append(__create_operate(Operate.LE, f"平多@{self.stop_loss}BP止损"))
@zengbin93
Copy link
Member

这里的止损不是以开仓价来计算的,而是以最后一次开仓事件的触发价格来计算。所以只要有新的开仓动作,就要更新 last_event。也就是会出现你下面说的那种情况,这是正常的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants