簡體   English   中英

Pine Script - 無法用我的邏輯編寫 Strategy.exit

[英]Pine Script - Unable to write a Strategy.exit with my logic

我嘗試在 Pine 編輯器中編寫策略腳本。

  • strategy.entry() 正在按我的預期工作。
  • 但是 strategy.exit() 沒有按照我的邏輯工作。
  • 我的退出計算是前一根蠟燭的高點減去低點。

我是 Pine 的新手。 下面是我的代碼。 有人可以指出什么是錯的嗎?

    Short = ( ( close[1] > open[1] ) and ( high < high[1] ) and ( close < low[1] ) )
    if ( Short )
        Target = high[1] - low[1]
        Loss = high[1] - low[1]
        strategy.entry("Enter Short", strategy.short, 1, when = window() )
        strategy.exit("Enter Short", "Enter Short", stop=Loss, limit=Target, when = window())

根據 pine 腳本手冊: when (bool) 一個可選參數。 訂單條件。 如果條件為“真”,則下單。 如果條件為'false',則什么都不會發生(之前下的相同ID的訂單不會被取消)。 默認值為“真”。 所以我認為你沒有滿足條件window()。 請改用 strategy.close()。

回答

Target = valuewhen(( ( close[1] > open[1] ) and ( high < high[1] ) and ( close < low[1] ) ), high[1] - low[1], 0 ) strategy.exit("Enter Short", "Enter Short", stop=strategy.position_avg_price+Target, limit=strategy.position_avg_price-Target, when = window())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM