最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JSON message for Pine Script strategy execution - Stack Overflow

programmeradmin4浏览0评论

I an trying to write a JSON message for executing Pine Script strategy at TradingView.

// === /STRATEGY ===


// Close the current position fully and reverse to the opposite position
if (xlong)
    if (strategy.position_size < 0)  // If there's an open short position
        strategy.close_all()        // Fully close all short positions
    strategy.entry("long", strategy.long)  // Open a long position

if (xshort)
    if (strategy.position_size > 0)  // If there's an open long position
        strategy.close_all()        // Fully close all long positions
    strategy.entry("short", strategy.short)  // Open a short position

So it's basically trying to determine the previous position. Close it to 0. And open a new one in the opposite direction.

{
  "ticker": "{{ticker}}", 
  "prev_position": "{{strategy.prev_market_position}}", 
  "close_all": true, 
  "action": "{{strategy.order.action}}", 
  "quantity": "{{strategy.order.contracts}}", 
  "pointer": "Insert your ponter here"
}

The problem is that orders interact with each other and previous order don't close completely. It closes it with the same amount the order was opened loosong all Pnl.

I tried many combinations of lines and commands. didn't help. This idea should simply reverse position with the same amount so close to the current position and open the same size in opposite side with market order.

Thank you

发布评论

评论列表(0)

  1. 暂无评论