作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用松树编辑器制定一个策略,当 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
最佳答案
您的 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)
关于trading - 我在 pine 编辑器中购买但不出售的策略有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57763677/
我在 Elastic Beanstalk 上托管的匿名自动售货机遇到问题。情况是我正在使用 AWS 为 iOS 提供的代码,但是为 KeyWrapper 生成的加密生成的 uid/ key 获得了 5
即使在本地主机中,我也无法在 Firefox 中正确显示 Font Awesome 。我收到以下跨域错误: Timestamp: 08/08/2012 02:49:37 PM Error: downl
我是一名优秀的程序员,十分优秀!