Just recently you might start to see the following warnings in Tradingview :
This is happening when you’re using “when” parameter in any strategy.* functions. For example, following code will produce 2 warnings for every “strategy.entry” call:
//@version=5
strategy("MACD Strategy", overlay=true)
fastLength = input(12)
slowlength = input(26)
MACDLength = input(9)
MACD = ta.ema(close, fastLength) - ta.ema(close, slowlength)
aMACD = ta.ema(MACD, MACDLength)
delta = MACD - aMACD
strategy.entry("MacdLE", strategy.long, when = ta.crossover(delta, 0))
strategy.entry("MacdSE", strategy.short, when = ta.crossunder(delta, 0))
How to Fix?
Solution for this error you can see in the warning itself. You have to replace your when parameter with if or switch operator. You can do this the following way with if statement:
//@version=5
strategy("MACD Strategy", overlay=true)
fastLength = input(12)
slowlength = input(26)
MACDLength = input(9)
MACD = ta.ema(close, fastLength) - ta.ema(close, slowlength)
aMACD = ta.ema(MACD, MACDLength)
delta = MACD - aMACD
if (ta.crossover(delta, 0))
strategy.entry("MacdLE", strategy.long)
if (ta.crossunder(delta, 0))
strategy.entry("MacdSE", strategy.short)
Solution with a switch will be a bit more complicated because we have to create a variable with the type of input first:
//@version=5
strategy("MACD Strategy", overlay=true)
fastLength = input(12)
slowlength = input(26)
MACDLength = input(9)
MACD = ta.ema(close, fastLength) - ta.ema(close, slowlength)
aMACD = ta.ema(MACD, MACDLength)
delta = MACD - aMACD
long = ta.crossover(delta, 0)
short = ta.crossunder(delta, 0)
entry_type = long ? 'long' :
short ? 'short' :
'none'
switch entry_type
'long' => strategy.entry("MacdLE", strategy.long)
'short' => strategy.entry("MacdSE", strategy.short)
As you can see solution for this warning is very simple so try to start using it right away, because in the next version of Pine Script it might be an error.
Follow me on TradingView and YouTube.
I have:
strategy.close(‘Short’, alert_message=’Close Short’)
without a “when”, but I still get this warning.
Yep, I saw it, I believe it’s a TV bug.
Try to add the ‘immediately = false’ parameter, for a weird reason it solves the warning.