【发布时间】:2022-07-20 15:22:11
【问题描述】:
以下是我写的 pinescript。
我是 pinescript 的新手,想就我一直在研究的 pinescript 寻求帮助。基本上,问题出在“EntryCondition”中,其中“bullishEC”和“MA 条件”不能同时起作用。但是,如果我删除 BullishEC 条件或 MA 条件,它们会单独工作。请告知,任何输入/帮助将不胜感激!
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © thrilledBook49599
//@version=5
strategy('RSI2 Strategy', overlay=true)
// Get price of SPX500USD,1H,CLOSE
spx500usd_price = request.security('spx500usd', '60', close)
// Creating EMA Indicator
spx500usd_ema10 = ta.ema(spx500usd_price, 10)
spx500usd_ema200 = ta.ema(spx500usd_price, 200)
//Create an RSI Indicator
r = ta.rsi(close, 2)
//Create Engulfing Candle
BullishEC = open[1] > close[1] and close > open and close >= open[1] and close[1] >= open and close - open > open[1] - close[1]
BearishEC = close[1] > open[1] and open > close and open >= close[1] and open[1] >= close and open - close > close[1] - open[1]
//Create Entry Conditions Variable
longCondition = (close > spx500usd_ema200 and close < spx500usd_ema10) and r<10 and BullishEC
closelongCondition = r > 90
shortCondition = (close > spx500usd_ema200 and close < spx500usd_ema10) and r<10 and BullishEC
closeshortCondition = r < 10
strategy.entry('long', strategy.long, when=longCondition)
strategy.close('long', when=closelongCondition)
strategy.entry('short', strategy.short, when=shortCondition)
strategy.close('short', when=closeshortCondition)
plot(spx500usd_ema10)
plot(spx500usd_ema200)
plotshape(BearishEC, title='Bearish Engulfing', color= color.red, style=shape.arrowdown, text='Bearish\nEngulfing')
plotshape(BullishEC, title='Bullish Engulfing', location=location.belowbar, color=color.green, style=shape.arrowup, text='Bullish\nEngulfling')
【问题讨论】: