Home > database >  Pinescript - Syntax error at input 'long_entry'
Pinescript - Syntax error at input 'long_entry'

Time:01-27

I have an issue with prinescript. I don't get how to fix this, line 23. When I use an if statementwhen, I use the ?: I don't get the error.

//@version=5
indicator("Test 1", overlay = true)

// Define the indicators
ema = ta.ema(close, 200)
atr14 = ta.atr(14)
long_entry = false
short_entry = false

// Define the conditions for consecutive open and close prices
long_condition = (close[2] < open[2] and close[1] < open[1] and close > open[1]) and (close > open)
     or (close[3] < open[3] and close[2] < open[2] and close > open[2]) and (close > open)
     or (close[4] < open[4] and close[3] < open[3] and close > open[3]) and (close > open)
     or (close[5] < open[5] and close[4] < open[4] and close > open[4]) and (close > open)
     or (close[6] < open[6] and close[5] < open[5] and close > open[5]) and (close > open)
short_condition = (close[2] > open[2] and close[1] > open[1] and close < open[1]) and (close > open)
     or (close[3] > open[3] and close[2] > open[2] and close < open[2]) and (close < open)
     or (close[4] > open[4] and close[3] > open[3] and close < open[3]) and (close < open)
     or (close[5] > open[5] and close[4] > open[4] and close < open[4]) and (close < open)
     or (close[6] > open[6] and close[5] > open[5] and close < open[5]) and (close < open)

// Define the conditions for long and short positions
if long_condition and close > ema and barstate.isconfirmed
     long_entry := true

if short_condition and close < ema and barstate.isconfirmed
     short_entry := true
     
// Define the stop loss
long_stop = close - (atr14 * 2)
short_stop = close   (atr14 * 2)

I looked around but couldn't find a solution.

CodePudding user response:

If blocks must be indented by four spaces or a tab. You have five spaces in below if statements:

// Define the conditions for long and short positions
if long_condition and close > ema and barstate.isconfirmed
     long_entry := true

if short_condition and close < ema and barstate.isconfirmed
     short_entry := true

So, change it to:

// Define the conditions for long and short positions
if long_condition and close > ema and barstate.isconfirmed
    long_entry := true

if short_condition and close < ema and barstate.isconfirmed
    short_entry := true

Note: The script must have at least one output function call (e.g. plot, barcolor, etc.).

  • Related