Reputation: 11
This is my code that I've written but when I run it I get this error: Compilation error. Line 24: Could not find function or function reference 'crossover'
// © KabeerMehdi
//@version=5
//MACD auto-trading strategy
strategy("MACD", overlay=true)
// Define variables
longLength = 26
shortLength = 12
signalLength = 9
// Calculate MACD and signal line on different time frames
macd1 = ta.ema(close, shortLength) - ta.ema(close, longLength)
signal1 = ta.ema(macd1, signalLength)
macd2 = ta.ema(close, shortLength) - ta.ema(close, longLength)
signal2 = ta.ema(macd2, signalLength)
macd3 = ta.ema(close, shortLength) - ta.ema(close, longLength)
signal3 = ta.ema(macd3, signalLength)
// Define entry and exit conditions
longCondition = macd1 > signal1 and macd2 > signal2 and macd3 > signal3
shortCondition = macd1 < signal1 and macd2 < signal2 and macd3 < signal3
exitCondition = crossover(macd1, signal1) or crossover(macd1, signal1) or crossover(macd2, signal2) or crossover(macd2, signal2) or crossover(macd3, signal3) or crossover(macd3, signal3)
// Enter long position
if longCondition
strategy.entry("Long", strategy.long)
// Enter short position
if shortCondition
strategy.entry("Short", strategy.short)
// Exit position
if exitCondition
strategy.close()
I tried to google and see if i got the function name wrong but I didn't ANd plus I'm using v5 so this should work.
Upvotes: 1
Views: 262
Reputation: 3058
In version 5 you should replace :
crossover(x, y)
by :
ta.crossover(x, y)
Upvotes: 1