The below consist of the pinescript which I have written.
I am new to pinescript and would like to seek help regarding the pinescript that I have been working on. Basically, the issue is in the "EntryCondition" where the "bullishEC" and "MA Conditions" do not work concurrently. However, they work individually if I remove either the BullishEC condition or the MA Conditions. Please advise, any input/help would be greatly appreciated!
// 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')
I can tell you 2 reasons.
#1
TradingView is not supporting hedge trade backtesting. Which means you cannot LONG and SHORT together.
#2
strategy.entry
allows you to entry a single entry, unless you set pyramiding option.
USE strategy.order
instead. It allows you to make multiple orders.
I also suggest you to check how many position you have. Because It will keep ordering limitlessly.
strategy.opentrades
gives you number of position.
example)
if strategy.opentrades < 5
strategy.order(conditions)
Even if you use [strategy.order], you cannnot hedge BTW.
Is it helpful? I wish you luck!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.