Welcome to the BEST forum for traders

Did you know we're sharing tons of exclusive content here?
Our community is growing quickly. Take a look around and say "Hello".

why i have this error ???

Jan 25, 2023 - 3:56 AM

Viewed 5334 times

https://best-trading-indicator.com/community/bti/forums/4180/topics/1615314 COPY
  • hi everybody,

    on tradingview , pinescript find an error in my code :

    // Define the MACD function
    macd(src, fast_length, slow_length, signal_length) =>
    fast_ma = sma(src, fast_length)
    slow_ma = sma(src, slow_length)
    macd_line = fast_ma - slow_ma
    signal_line = sma(macd_line, signal_length)
    histogram = macd_line - signal_line
    return[macd_line, signal_line, histogram]

    In the last line the first ' , ' have a red underline ......

    someone can find a solution ?

    thanks

    err.png

    0
  • Hi

    remove the return keyword, it's not a pine keyword

    [macd_line, signal_line, histogram] is enough

    1
  • tks dave dave

    1
  • i also have a wierd error.. - Could not find function or function reference ta.ema

    this is the code

    //@version 5
    strategy(20 EMA & 50 EMA Crossover with Stochastic RSI Filter)

    length = input(title=Length of EMAs, type=integer, defval=20)
    oversold = input(title=Oversold level, type=integer, defval=20)
    overbought = input(title=Overbought level, type=integer, defval=80)

    // calculate the exponential moving averages
    ema20 = ta.ema(close, 20)
    ema50 = ta.ema(close, 50)

    // calculate the stochastic RSI
    rsi = ta.rsi(close, 14)
    k = ta.stoch(rsi, 3)
    d = ta.sma(k, 3)

    // long entry conditions
    long_entry = crossover(ema20, ema50) and crossunder(k, oversold)

    // long exit conditions
    long_exit = crossabove(k, overbought)

    // short entry conditions
    short_entry = crossunder(ema20, ema50) and crossabove(k, overbought)

    // short exit conditions
    short_exit = crossunder(k, oversold)

    // plot the long entry and exit signals
    plot(long_entry ? close : na, title=Long Entry, style=plot.style_circles, color=color.green, linewidth=3)
    plot(long_exit ? close : na, title=Long Exit, style=plot.style_circles, color=color.red, linewidth=3)

    // plot the short entry and exit signals
    plot(short_entry ? close : na, title=Short Entry, style=plot.style_circles, color=color.red, linewidth=3)
    plot(short_exit ? close : na, title=Short Exit, style=plot.style_circles, color=color.green, linewidth=3)

    // create overlay to display on the chart
    overlay(ema20, title=20 EMA, color=color.yellow)
    overlay(ema50, title=50 EMA, color=color.blue)

    0
  • Hello helper,

    I'm getting error Incorrect 'for' statement. Expecting 'to '. for the below pine code. Can anyone please help?

    indicator(My Script, overlay=true)

    // Define the colors for the candles
    yellow = #FFFF00
    white = #FFFFFF
    orange = #FFA500
    silver = #C0C0C0

    // Initialize variables to keep track of the state
    entryLong = false
    exitLong = false
    entryShort = false
    exitShort = false

    // Use the bar_index function to go through each bar on the chart
    for i = 0 to bar_index

    // Check the entry long condition
    if (high[i] > high[i+1]) and (low[i] > low[i+1]) and (close[i] > high[i+1])
    entryLong := true
    exitLong := false
    barcolor(yellow)

    // Check the exit long condition
    if (entryLong) and (high[i] < high[i+1]) and (close[i] < low[i+1])
    entryLong := false
    exitLong := true
    barcolor(white)

    // Color the candles yellow between entry long and exit long candles
    if (entryLong) and not (exitLong)
    barcolor(yellow)

    // Check the entry short condition
    if (high[i] < high[i+1]) and (low[i] < low[i+1]) and (close[i] < low[i+1])
    entryShort := true
    exitShort := false
    barcolor(orange)

    // Check the exit short condition
    if (entryShort) and (low[i] > low[i+1]) and (close[i] > high[i+1])
    entryShort := false
    exitShort := true
    barcolor(silver)

    // Color the candles orange between entry short and exit short candles
    if (entryShort) and not (exitShort)
    barcolor(orange)

    0
  • First !!! You didn't used Pine //@version=5
    You wrote //@version 5 ... for this reason the Pine Editor thought you are creating Code for Pine //@version=1

    The right instruction for unsing PineScript Version 5 --> // @version=5

    Sorry for double Entry's, couldn't find a way how to delete a message.

    This post was edited Jun 28, 2023 11:09AM
    1
  • Hello ,
    There are some issues with your code. I'm not a expert, but maybe this helps you.
    I didn't correct your formula ... only where are some obvious problems with the code.
    IF you use the Errormessages in the Pine-Editor window ( bellow) .. then you will see where the problem is.
    First !!! You didn't used Pine //@version=5
    You wrote //@version 5 ... for this reason the Pine Editor thought you are creating Code for Pine //@version=1

    The right instruction for unsing PineScript Version 5 --> // @version=5

    When you decleare a veriable with a input then you need to say witch variable should be created with this Input ... so right is .. length = input.int (title=Length of EMAs, defval20) ...
    you neet the quotes, this was several times not used in Methods of you.
    There was several other issues with the Namespace where you not said to the system where he should take the funktion ... ta.crossover ... crossover allone not working ... then you used crossabove .. this is not a existing method.

    You will find the full help in the Reference Manual for Pinescript on Tradingview.

    // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
    // © Werner_Stiegler
    //@version=5

    strategy(20 EMA & 50 EMA Crossover with Stochastic RSI Filter)

    length = input.int (title=Length of EMAs, defval=20)
    oversold = input.int (title=Oversold level, defval=20)
    overbought = input.int (title=Overbought level, defval=80)

    // calculate the exponential moving averages
    ema20 = ta.ema(close, 20)
    ema50 = ta.ema(close, 50)

    // calculate the stochastic RSI
    rsi = ta.rsi(close, 14)
    //k = ta.stoch(rsi, 3) -- Stoch benötigt mehr Parameter
    // d = ta.sma(k, 3) --> when K with Stochastic variable is working then this could work when you give the right amound of criterias to the SMA function.

    // long entry conditions
    // long_entry = crossover(ema20, ema50) and crossunder(k, oversold) ... --> // needs the namespace ta.crossover !!! then works with the right criteria

    // long exit conditions
    // long_exit = crossabove(k, overbought) --> corssabove not exists !!! ta.crossunder ??

    // short entry conditions
    // short_entry = crossunder(ema20, ema50) and crossabove(k, overbought) --> Namespace ta.crossunder / ta.crossover

    // short exit conditions
    // short_exit = crossunder(k, oversold) // --> Namespace ta.crossunder

    // plot the long entry and exit signals
    //plot(long_entry ? close : na, title=Long Entry, style=plot.style_circles, color=color.green, linewidth=3)
    // plot(long_exit ? close : na, title=Long Exit, style=plot.style_circles, color=color.red, linewidth=3)

    // plot the short entry and exit signals
    //plot(short_entry ? close : na, title=Short Entry, style=plot.style_circles, color=color.red, linewidth=3)
    //plot(short_exit ? close : na, title=Short Exit, style=plot.style_circles, color=color.green, linewidth=3)

    // create overlay to display on the chart
    plot(ema20, title=20 EMA, color=color.yellow)
    plot(ema50, title=50 EMA, color=color.blue)

    1
  • Jignesh P (@jigneshp):
    The bar_index ist the actual bar ... and 0 is also the actual bar ...
    So
    For I=0 to 0 ...
    maybe you wanted do something else ...

    1
CONTENTS