TP/SL订单在Pine脚本中未执行

huangapple go评论48阅读模式
英文:

TP/SL Order does not execute in Pine Script

问题

  1. 使用以下代码下订单,而且它执行没有任何问题:
//下订单
strategy.entry(
    currentOrder.orderEntryId,
    direction = 如果满足 long 条件则 strategy.long 否则 strategy.short, 
    qty = currentOrder.quantity,
    stop = currentOrder.entryPrice,
    limit = currentOrder.limitPrice)
  1. 我想为同一个订单设置止损和止盈,但是当我使用以下代码下单时它不被执行:
//为当前下的订单设置止损和止盈
strategy.exit(
    id = currentOrder.orderExitId, 
    from_entry = currentOrder.orderEntryId,
    qty = currentOrder.quantity,
    qty_percent = 100,
    limit = currentOrder.takeProfit,
    stop = currentOrder.stopLoss)

我查看了分配给所有参数的值,它们都是正确的。附上调试输出的屏幕截图:
如您所见,价格超过了止盈线(绿线),但策略退出没有执行

英文:
  1. I place the order using the following code and it gets executed without any problem:
   //place order        
`    strategy.entry(
     currentOrder.orderEntryId,
     direction              = longCondition ? strategy.long: strategy.short, 
     qty                    = currentOrder.quantity,
     stop                   = currentOrder.entryPrice,
     limit                  = currentOrder.limitPrice)`

  1. I want to set-up a SL and TP entry for the same order, but when I place it with the following code it does not get executed:
    `
 //setup SL and TP for the currently placed order
    strategy.exit(
         id                 = currentOrder.orderExitId, 
         from_entry         = currentOrder.orderEntryId,
         qty                = currentOrder.quantity,
         qty_percent        = 100,
         limit              = currentOrder.takeProfit,
         stop               = currentOrder.stopLoss)`


I looked into the values assigned to all parameters and they are all OK. Attaching a screen capture of the debug output:
As you can see Price passed the TP line (green) but the strategy.exit did not execute

答案1

得分: 1

已解决 - 如果代码取消订单,止损/止盈订单也将被取消。对于已经输入的订单取消也是如此。

英文:

Resolved it - if the code cancels the order , SL/TP orders are also cancelled. This is also true for cancelling the order that that has already been entered.

huangapple
  • 本文由 发表于 2023年3月12日 07:06:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75710124.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定