问题
I'm trying to create a plot to the chart based on the following conditions:
- It's the second consecutive green bar to open above the 9 day MA line
- It's oversold on the RSI
I'm having issue is what order to write the condition, and knowing how many brackets I need?
strategy(title="Swing Strat", pyramiding=1, overlay=true, default_qty_value=2, default_qty_type=strategy.fixed, initial_capital=100, currency=currency.GBP)
//plotting MA lines
MAPeriod9 = input(9, title="9 MA Period")
MA9 = sma(close, MAPeriod9)
MAPeriod180 = input(180, title="180 MA Period")
MA180 = sma(close, MAPeriod180)
plot(MA9, color=color.blue, linewidth=1)
plot(MA180, color=color.red, linewidth=1)
// creating the RSI
rsiSource = input(title="RSI Source", type=input.source, defval=close)
rsiLength = input(title="RSI Length", type=input.integer, defval=14)
rsiOverbought = input(title="RSI Overbought Level", type=input.integer, defval=70)
rsiOversold = input(title="RSI Oversold Level", type=input.integer, defval=30)
//get RSI value
rsiValue = rsi(rsiSource, rsiLength)
isOverbought = rsiValue >= rsiOverbought
isOversold = rsiValue <= rsiOversold
//checking to see if the bars close over 9 day MA line
MAcrossover = crossover(close, MA9)
entrypoint = barssince(MAcrossover)
//marking the second green bar to open above the SMA line
tradingsignal = ((entrypoint==1 and MA9<open and open<close and open[1]<close[1]) and isOversold)
plotshape(tradingsignal, title="Entry Trigger", location=location.abovebar, color=color.red, transp=0, style=label.style_xcross, text="Entry Point")
回答1:
You have no errors in the condition. In your case, you can remove all the brackets.
Correct the style parameter in the last line to the following style=shape.xcross
.
If you don't see any labels with Entry Point
on the chart, increase value the oversold parameter.
来源:https://stackoverflow.com/questions/65869780/pinescript-conditional-statement-plotting