![](/img/trans.png)
[英]How to Keep two long and short opposed positions open in tradingview pinescript?
[英]How to force the TradingView strategy-tester to open/exit Long positions only ? (Remove short) + set TP/SL not giving any result
我一直在嘗試獲取只做多頭策略的回測結果,但沒有成功。 此外,出於某種原因,我似乎無法設置“獲利”/止損。 我正在交易基於秒的間隔,所以我想要 0.01% 的止盈並使用:
strategy.exit("Exit Long", from_entry="Long", stop=close * 1.00001)"
(我也試過使用 limit=close 而不是“stop”)但是上下調整該值似乎對 .net 利潤結果沒有任何影響。 由於某些原因,它確實在 1500 萬支蠟燭中起作用。 無論我嘗試什么,我似乎都無法設置止損。
如果您知道我可以直接在指標設置中更改的良好“輸入”樣式 TP 和 SL,而不必在 Pine 編輯器中手動輸入,那也很棒。
這是我的代碼。 請耐心等待,因為我在任何類型的編程中都是初學者。 我嘗試刪除所有可能提及 short 的內容,添加我在文檔中找到的“strategy.direction.long”行。 帶 // 的部分是我試過但沒有解決任何問題的部分,但保留以備后用。
// Only trade from the long side
strategy.risk.allow_entry_in(strategy.direction.long)
// Submit orders
//if buySignal
//strategy.entry(id="EL", long=true)
//if sellSignal
//strategy.entry(id="ES", long=false)
strategy.entry('Long', strategy.long, 1, when=buySignal)
strategy.close('Long', when=sellSignal)
strategy.cancel('Short', when=sellSignal)
//strategy.exit("exit", "long", profit = 50, loss = 20)
strategy.exit("Exit Long", from_entry="Long", stop=close * 1.000015)
//strategy.exit("Exit Long", from_entry="Long", stop=low * 1.007)
strategy.risk.allow_entry_in(strategy.direction.long)
如果 Pine V5 有任何過時的內容,請告知。
如果您每次都無條件地調用此行,您的舊退出訂單將被刪除並使用新的關閉值創建一個新訂單。
strategy.exit("Exit Long", from_entry="Long", stop=close * 1.000015)
這肯定是您的止損未在 1 秒時間范圍內執行的原因。
你應該在你的 strategy.entry 之后只執行一次這一行。
嘗試:
if strategy.opentrades == 0 // No open order
strategy.entry('Long', strategy.long, 1, when=buySignal)
strategy.exit("Exit Long", from_entry="Long", stop=close * 1.000015)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.