Sulkhan Metreveli
Sulkhan Metreveli

Reputation: 1

Pine Language - Undeclared Identifier Error

What is wrong with this code? I'm getting an undeclared identifier error. Don't see why

// This is a simple moving average cross-over strategy
//@version=3
strategy("Crossover")

// Buy rule
entryLong = crossover(sma(10), sma(20))
if (entryLong)
    strategy.entry("MyLong", strategy.long, qty=1, limit=10, stop=5)

// Sell rule
entryShort = crossunder(sma(10), sma(20))
if entryShort
    strategy.entry("MyShort", strategy.short, qty=1, limit=10, stop=5)

Upvotes: 0

Views: 80

Answers (1)

G.Lebret
G.Lebret

Reputation: 3088

You should use the version 5 of pinescript as version 3 is clearly obsolete and generate errors hard to spot.
Here is your code in the version 5 :

//@version=5
strategy("Crossover")

// Buy rule
entryLong = ta.crossover(ta.sma(close,10), ta.sma(close,20))
if (entryLong)
    strategy.entry("MyLong", strategy.long, qty=1, limit=10, stop=5)

// Sell rule
entryShort = ta.crossunder(ta.sma(close,10), ta.sma(close,20))
if entryShort
    strategy.entry("MyShort", strategy.short, qty=1, limit=10, stop=5)

Upvotes: 0

Related Questions