我对这段代码有疑问:
strategy.entry("LONG", strategy.long, alert_message='{"action":"order","side":"buy","price":"'+tostring(close)+'"}')
strategy.exit("STOP", "LONG", stop=close * (1 - stop), alert_message='{"action":"close","side":"sell"}')
strategy.exit("PRFT", "LONG", limit=close * (1 + prft), alert_message='{"action":"profit","side":"sell"}')
* 亏损/利润具有相同的止损/限制问题。
只有第一个出口有效,在这种情况下,只有“ STOP”。我需要将这两个分开发送到 webhook 。
我尝试使用 strategy.order()进行“ PRFT”创建,但是回测的结果却大不相同。
我不能使用 alertcondition(),因为它仅在蜡烛关闭后才触发。
有人可以帮我吗?
答案 0 :(得分:0)
也许这就是您找到的:
// @version=4
strategy("strategy")
stop = 0.05
prft = 0.05
strategy.entry("LONG", strategy.long, alert_message='{"action":"order","side":"buy","price":"'+tostring(close)+'"}')
if strategy.position_size != 0
strategy.order("STOP", false, qty = strategy.position_size, oca_name = "exit long", oca_type = strategy.oca.reduce, stop=strategy.position_avg_price * (1 - stop), alert_message='{"action":"close","side":"sell"}')
strategy.order("PRFT", false, qty = strategy.position_size, oca_name = "exit long", oca_type = strategy.oca.reduce, limit=strategy.position_avg_price * (1 + prft), alert_message='{"action":"profit","side":"sell"}')
else
strategy.cancel("STOP")
strategy.cancel("PRFT")