英文:
TP/SL Order does not execute in Pine Script
问题
- 使用以下代码下订单,而且它执行没有任何问题:
 
//下订单
strategy.entry(
    currentOrder.orderEntryId,
    direction = 如果满足 long 条件则 strategy.long 否则 strategy.short, 
    qty = currentOrder.quantity,
    stop = currentOrder.entryPrice,
    limit = currentOrder.limitPrice)
- 我想为同一个订单设置止损和止盈,但是当我使用以下代码下单时它不被执行:
 
//为当前下的订单设置止损和止盈
strategy.exit(
    id = currentOrder.orderExitId, 
    from_entry = currentOrder.orderEntryId,
    qty = currentOrder.quantity,
    qty_percent = 100,
    limit = currentOrder.takeProfit,
    stop = currentOrder.stopLoss)
我查看了分配给所有参数的值,它们都是正确的。附上调试输出的屏幕截图:
如您所见,价格超过了止盈线(绿线),但策略退出没有执行
英文:
- 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)`
- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论