Search code examples
pine-scriptpine-script-v5tradingview-api

Is fibUp = fibonacci(high,"up") a valid PineScript statement?


// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © r
//@version=5
// This script triggers a trade when RSI is overbought/oversold and there is a convergence with MACD
// It also implements Tom Demark signals and only triggers a trade when all conditions are met
// The trade is only triggered when near a Fibonacci resistance or support line

// Define constants
rsiLength = 14
overbought = 70
oversold = 30
macdLength = 12
signalLength = 26

// Include libraries
study(title="Trade Trigger", overlay=true)

// Get current symbol and time frame
symbol = syminfo.ticker
timeframe = syminfo.timeframe

// Calculate RSI
rsi = rsi(close, rsiLength)

// Calculate MACD and signal line
macd = macd(close, macdLength, signalLength)
signal = macd[1]

// Check if RSI is overbought/oversold and there is a convergence with MACD
if (rsi > overbought and macd > signal) or (rsi < oversold and macd < signal)
    // Calculate Fibonacci levels
        fibUp = fibonacci(high,"up")
            if (close > high) or (close < low)
        fibDown = fibonacci(low, "down")
                // Check if price is near a Fibonacci resistance or support line
            if (close > high) or (close < low)
                            // Trigger trade
                                    trade()
                                        endif
                                        endif

is fibUp = fibonacci(high,"up") a valid statement?

In PineScript I get the compilation error:

mismatched input 'fibUp' expecting 'end of line without line continuation'.

I tried removing indents and spaces without any improvement, but the error still occurs.


Solution

  • in your code you must change :

    if (rsi > overbought and macd > signal) or (rsi < oversold and macd < signal)
        // Calculate Fibonacci levels
            fibUp = fibonacci(high,"up")
                if (close > high) or (close < low)
    

    by this code : the idea is to respect to ´if’ block with 4 spaces after (only 4)

    if (rsi > overbought and macd > signal) or (rsi < oversold and macd < signal)
        // Calculate Fibonacci levels
        fibUp = fibonacci(high,"up")
        if (close > high) or (close < low)
            .. and so on ..