簡體   English   中英

如何在 tradingview 的多頭策略中包含空頭信號?

[英]How to include short signals in a Long only strategy on tradingview?

如何在 tradingview 的多頭策略中包含空頭信號?

我有一個 Tradingview 策略,它根據匹配條件只給出多頭/買入信號。 我還需要它在條件合適時生成短信號。 我該怎么做?

strategy("Varun scalp", shorttitle="Varun scalp", overlay=true)
timeframe = input('3')
box = input('Traditional')
boxsize = input(5, type=float)
reversal = input(1)
pnf = pointfigure(tickerid, 'close', box, boxsize, reversal)
pnf_open= security(pnf, timeframe , open)
pnf_close= security(pnf, timeframe , close)
p1 = plot(pnf_open, title="pnf_open", color=green)
p2 = plot(pnf_close,  title="pnf_close",color=maroon)
base = pnf_close> pnf_open? pnf_close: pnf_open
p0 = plot(base, title="base", color=gray)
fill(p0, p2, color=green, transp=70)
fill(p0, p1, color=maroon, transp=70)
entry() => (base > pnf_close)
exit() => (base > pnf_open)
alertcondition(entry(), title='buy', message='buy!')
alertcondition(exit(), title='sell', message='sell!')
strategy.risk.allow_entry_in(strategy.direction.long)
strategy.entry("Long", long=true, when=entry())
strategy.entry("close", false, when=exit())

strategy.entry()long參數設置為false

long (bool) 必需的參數。 行情position方向:'true'或'strategy.long'為多頭,'false'或'strategy.short'為空頭。

要詳細說明 Vitruvius 的答案,除了您已經擁有的內容之外,您還想包括這些內容。 所以你的代碼的結尾看起來像這樣 - 應該注意的是它會來回反轉多頭和空頭或關閉多頭或空頭策略,哪個先發生。

首先在策略聲明之外定義您的進入和退出條件。

entry=(whatever your entry logic is)
exit=(whatever your exit logic is)
shortentry=(whatever your entry logic is)
shortexit=(short exit logic)
strategy.entry("Long", long=true, when=entry)
strategy.entry("Short", long=false, when=shortentry)
strategy.close("close long", when=exit)
strategy.entry("close short", when=shortexit)

暫無
暫無

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

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