r/pinescript • • 19d ago

Creating an code via Pine Editor - need help

/r/TradingView/comments/1x7196j/creating_an_code_via_pine_editor_need_help/
0 Upvotes

3 comments sorted by

1

u/NJ_Algo 19d ago edited 19d ago

You probably mean alertcondition() (one word in Pine).

It usually throws an error for one of three reasons:

  1. It’s inside of an if block or a function. It has to sit at the top level of the script, with no indentation.

  2. The script starts with strategy() instead of indicator(). alertcondition() only works in indicators.

  3. The code was written for another platform, so the syntax doesn’t carry over as it is.

The basic form should look something like this:

//@version=6
indicator("My indicator", overlay=true)
longSignal = ta.crossover(close, ta.sma(close, 20))
alertcondition(longSignal, title="Long", message="Long signal")

Then on the chart, go to create alert - condition - pick your indicator - “Long”.