簡體   English   中英

隨機松腳本策略

[英]Stochastic pine script stratygy

大家好,希望你們做得好,

我正在嘗試編寫一個策略,當 k 處於超買區域並越過 d 時做多,而做空則相反

但我是新手,如果交叉發生在超買區域,我現在不知道如何寫多頭入場。

謝謝大家,

我編寫了以下代碼,以獲得當 k 處於超買區域並越過 d 時做多的策略結果,反之則做空。 在代碼注釋中添加了更多詳細信息。

//@version=5
strategy("Stochastic Strategy", overlay=true)
//Stochastic Inputs
length = input.int(14, minval=1)
OverBought = input(80)
OverSold = input(20)
smoothK = 3
smoothD = 3
k = ta.sma(ta.stoch(close, high, low, length), smoothK)
d = ta.sma(k, smoothD)
//Rule to define crossover /crossunder
co = ta.crossover(k,d)
cu = ta.crossunder(k,d)

if (not na(k) and not na(d))
    //code to define if k is in overbought zone and k crossover d and enter a long trade
    if (co and k < OverSold)
        strategy.entry("StochLE", strategy.long, comment="StochLE")
    //code to define if k is in oversold zone and k crossunder d and enters a short trade
    if (cu and k > OverBought)
        strategy.entry("StochSE", strategy.short, comment="StochSE")

暫無
暫無

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

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