gpt4 book ai didi

trading - 我在 pine 编辑器中购买但不出售的策略有问题

转载 作者:行者123 更新时间:2023-12-04 13:40:35 26 4
gpt4 key购买 nike

我正在使用松树编辑器制定一个策略,当 D 线(即绿线)穿过 17.5 时买入,然后在 D 线穿过 78 时卖出。正如您从我发布的图表中看到的,它应该买入和卖出几次,但只买一次,什么都不做。我似乎无法弄清楚我错过了什么。代码的底部是我在策略中告诉它通过和出售的地方。谢谢

strategy("stochastic")
length = input(21, minval=1, title="length")
rsilength = input(21, minval=1, title="rsi length")
smoothk = input(4, minval=1, title="smoothk")
smoothd = input(10, minval=1, title="smoothd")
rsi = rsi(close, rsilength)

sto = stoch(close,highest(length),lowest(length), length)
K = sma(sto,smoothk)
D = sma(K,smoothd)

//plot(rsi, title="rsi", color=color.black)
plot(D, title="%D",color=color.green)
plot(K, title="%K",color=color.red)

hline(78,title="upper limit", color=color.red)
hline(17, title="lower limit",color=color.blue)
//plot(sto, title = "sto",color=color.black)


// === INPUT BACKTEST RANGE ===
FromMonth = input(defval = 8, title = "From Month", minval = 1, maxval = 12)
FromDay = input(defval = 5, title = "From Day", minval = 1, maxval = 31)
FromYear = input(defval = 2019, title = "From Year", minval = 2017)
ToMonth = input(defval = 9, title = "To Month", minval = 1, maxval = 12)
ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToYear = input(defval = 9999, title = "To Year", minval = 2017)

// === FUNCTION EXAMPLE ===
start = timestamp(FromYear, FromMonth, FromDay, 00, 00) // backtest start window
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59) // backtest finish window
window() => time >= start and time <= finish ? true : false // create function "within window of time"

// === EXECUTION ===
shares = 10000/close
buy = crossunder(D,17.5)
sell = crossover(D,78)

strategy.entry("buy", shares, when = window() and buy) // buy long when "within window of time" AND crossover
strategy.close("sell", when = window() and sell) // sell long when "within window of time" AND crossunder

如图中突出显示的那样,这应该买卖几次。
https://ibb.co/37L0wSK那是链接,抱歉我没有足够的代表来发布图片。

最佳答案

您的 strategy.close()调用未使用与 strategy.entry() 相同的订单 ID称呼。我在最后 3 行中添加了标记(您可以通过输入将它们关闭)以显示满足条件的位置。

Note: make sure you include the first line in the script when you transport Pine scripts. It's the compiler directive that specifies which version of Pine the code is using, so it's important.


//@version=4
strategy("stochastic")
length = input(21, minval=1, title="length")
rsilength = input(21, minval=1, title="rsi length")
smoothk = input(4, minval=1, title="smoothk")
smoothd = input(10, minval=1, title="smoothd")
showMarkers = input(true, "Show Markers")

rsi = rsi(close, rsilength)

sto = stoch(close,highest(length),lowest(length), length)
K = sma(sto,smoothk)
D = sma(K,smoothd)

//plot(rsi, title="rsi", color=color.black)
plot(D, title="%D",color=color.green)
plot(K, title="%K",color=color.red)

hline(78,title="upper limit", color=color.red)
hline(17, title="lower limit",color=color.blue)
//plot(sto, title = "sto",color=color.black)


// === INPUT BACKTEST RANGE ===
FromMonth = input(defval = 8, title = "From Month", minval = 1, maxval = 12)
FromDay = input(defval = 5, title = "From Day", minval = 1, maxval = 31)
FromYear = input(defval = 2019, title = "From Year", minval = 2017)
ToMonth = input(defval = 9, title = "To Month", minval = 1, maxval = 12)
ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToYear = input(defval = 9999, title = "To Year", minval = 2017)

// === FUNCTION EXAMPLE ===
start = timestamp(FromYear, FromMonth, FromDay, 00, 00) // backtest start window
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59) // backtest finish window
window() => time >= start and time <= finish ? true : false // create function "within window of time"

// === EXECUTION ===
shares = 10000/close
buy = crossunder(D,17.5)
sell = crossover(D,78)

strategy.entry("buy", shares, when = window() and buy) // buy long when "within window of time" AND crossover
strategy.close("buy", when = window() and sell) // sell long when "within window of time" AND crossunder

plotshape(showMarkers and buy, "buy", shape.triangleup, location.bottom, color.green, 0, text = "buy", size = size.tiny)
plotshape(showMarkers and sell, "sell", shape.triangledown, location.top, color.maroon, 0, text = "sell", size = size.tiny)
bgcolor(showMarkers ? window() ? color.green : color.maroon : na)

enter image description here

关于trading - 我在 pine 编辑器中购买但不出售的策略有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57763677/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com