簡體   English   中英

Pine 腳本 - 當多個條件為真時輸入位置

[英]Pine script - Enter position when multiple conditions are true

幾天來我一直試圖弄清楚這一點,我知道答案將非常簡單......

我想在多個條件為真時進入一個位置。 編譯腳本時不會產生任何錯誤,但圖表上不會出現應有的買賣(也許代碼中還有其他錯誤??)。 我嘗試了很多東西,但這是我最近的嘗試。

//@version=3
strategy("Easy BTC Trading", overlay=true,pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)

Multiple = input(2, minval=0,step=0.01)
ATR1 = atr(21)*Multiple
volumeavg = (volume[2]+volume[3]+volume[4])/3

highest = highest(high,5)
lowest = lowest(low,5)


long1 = high > highest
long2 = volume[1] >= volumeavg*2

go_long = high > highest and volume[1] > volumeavg*2
exit_long = low < lowest

strategy.entry("Long",strategy.long, when = go_long)
strategy.exit("Exit long","Long", profit = 5, stop = strategy.position_avg_price - ATR1, when = exit_long)

我讓你的腳本工作,我復制/粘貼了下面的代碼,並附有注釋來解釋:

//@version=3
strategy("Easy BTC Trading", overlay=true,pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)

Multiple = input(2, minval=0,step=0.01)
ATR1 = atr(21)*Multiple
volumeavg = (volume[2]+volume[3]+volume[4])/3
//I guess that you want to know the highest value for the last 5 bars
//if yes, in the highest & lowest functions, you need to use close[1]
//which is the previous close before the actual one
//if you just use close, your actual close can be the highest one
//so your long order would never trigger as your close would never
//be higher than the highest
highest = highest(close[1],5)
lowest = lowest(close[1],5)

long1 = close > highest
long2 = volume[1] >= (volumeavg*2)


//go_long = high > highest and volume[1] > volumeavg*2
//there was a problem with that condition above, so I wrote it a clearer way,
// with an if and it works better
go_long = 0
if (close > highest and volume[1] > volumeavg)
    go_long := 1
exit_long = close < lowest

strategy.entry("Long",strategy.long, when = go_long)
strategy.exit("Exit long","Long", profit = 5, stop = strategy.position_avg_price - ATR1, when = exit_long)

Vsoler 是對的。 高永遠不會高於最高。 當新高達到最高等於最高時,因此您需要將當前蠟燭從最高檢查中取出。

改變這個:
highest = highest(high,5)
對此:
highest = highest(high[1],5)

通過這種方式,您將傳遞給 'highest()' 不包括當前蠟燭的最后 5 根蠟燭。

你認為“高”可以大於“最高”嗎? Perhahs 它可以大於最高 [1]

問候維森特·索勒

暫無
暫無

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

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