Pinescript conditional statement plotting

那年仲夏 提交于 2021-02-11 12:13:15

问题


I'm trying to create a plot to the chart based on the following conditions:

  1. It's the second consecutive green bar to open above the 9 day MA line
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!