Home > Mobile >  Not able to send tradingview webhook messages to discord using alerts
Not able to send tradingview webhook messages to discord using alerts

Time:09-30

I have a tradingview script like this

ma200 = sma(close, 200)
ma50 = sma(close, 50)
if crossover(ma50, ma200) or crossover(ma200,ma50)
    alert('{"content":"{{ticker}}, {{interval}}, Market structure change"}', alert.freq_once_per_bar)

But for some reason the placeholders don't work when sending the message to discord. In discord it appears like this,

enter image description here

But the same code if I use alertcondition() like this,

ma200 = sma(close, 200)
ma50 = sma(close, 50)
alertcondition(crossover(ma50, ma200) or crossover(ma200,ma50),title="market structure change",message='{"content":"{{ticker}}, {{interval}}, Market structure change"}')

it works perfectly and sends alerts to discord with proper placeholder names.

Why does this happen and how can I rectify it?

CodePudding user response:

the {{ }} placeholders will only have functionality in alertcondition(). We need to build our own when using alert().

Try this out as an alternative. These built-ins return a string for the same variables mentioned in the placeholders. Notice how we must add punctuation between built-ins. eg ','

        alert('{"content":"'   syminfo.ticker   ','   timeframe.period   ', Market structure change"}', alert.freq_once_per_bar)

Cheers and best of luck with your trading and coding

  • Related