0

Could someone help me to correct the problem I am having with pinescript when updating the version as it tells me that the "when" will soon be obsolete and I have to replace it with "if", but the problem is that I do not want to lose the notifications or alerts.

Thanks


// Estrategia long 
longEntry() =>
    ta.rsi(close, 2) <= 20 and close >= ta.sma(close, 200) and ta.ema(close, 20)
longExit() =>
    ta.ema(close, 80) and ta.rsi(close, 2) >= 80


strategy.entry(id='Compra', direction=strategy.long, when=longEntry())
strategy.close(id='Compra', when=longExit())
strategy.exit('Cerrar Venta', from_entry='Venda', profit=useTakeProfit, loss=useStopLoss, trail_points=useTrailStop, trail_offset=useTrailOffset)


// Estrategia short
shortEntry() =>
    ta.rsi(close, 2) >= 80 and close <= ta.sma(close, 200) and ta.ema(close, 80)
shortExit() =>
    low <= ta.ema(close, 20) and ta.rsi(close, 2) <= 10


strategy.entry(id='Venda', direction=strategy.short, when=shortEntry())
strategy.close(id='Venda', when=shortExit())
strategy.exit('Cerrar Compra', from_entry='Compra', profit=useTakeProfit, loss=useStopLoss, trail_points=useTrailStop, trail_offset=useTrailOffset)

I have tried a thousand things, but this is my first time programming in pinescript and I get confused with the strategy.close and .exit.

yeerliin
  • 3
  • 1

1 Answers1

0

It's juast a warning message which tells you that when will be obsolete in the near future.

So, instead of:

strategy.entry(id='Compra', direction=strategy.long, when=longEntry())

You can do:

if (longEntry())
    strategy.entry(id='Compra', direction=strategy.long)

And both work the same way.

vitruvius
  • 15,740
  • 3
  • 16
  • 26