Search code examples
pine-scriptpine-script-v5tradingview-api

Pine Script create alert using Heikin Ashi but alert trigger normal candle as well


this is my entry condition

if buyConditionB and testPeriod
    strategy.entry("Long", strategy.long, qty=buyQty)
    alert('{"CustomId": "456","BuySide": "Long"}',freq=alert.freq_all)

if buyConditionS and testPeriod
    strategy.entry("Short", strategy.short, qty=buyQty)
    alert('{"CustomId": "123","BuySide": "Short"}',freq=alert.freq_all)

but seems it trigger alert from HA and normal candle if have buy or sell signal.

How to ensure i just want to receive HA signal only. (i created alert using HA cannot fix this issue)


Solution

  • You need to make sure you get all your values from the Heikin Ashi chart. To do that, you need to create a new ticker id based on Heikin Ashi candles.

    After that, you need to use the request.security() function to get data from the Heikin Ashi candles.

    ha_ticker = ticker.heikinashi(syminfo.tickerid)
    [buyConditionB_ha, buyConditionS_ha, testPeriod_ha] = request.security(ha_ticker, timeframe.period, [buyConditionB, buyConditionS, testPeriod])