Search code examples
pine-scripttradingview-api

How do I know which hourly candle a signal on the daily candle corresponds to?


there,

I have an indicator that displays a signal on a daily candle when the EMA 20 and EMA 50 cross.

Is there any way to find out which hourly candle the EMA 20 and EMA 50 crossing on the daily candle corresponds to?


Solution

  • You can make use of the timeframe argument in the indicator declaration statement. If you set your chart resolution to 1 hour and the timeframe argument to 1 day, you will be able to see on which hourly candle the cross occurs.

    //@version=5
    indicator('Crossover', 'C', true, timeframe = '')
    
    bool BarC = if ta.crossunder(ta.sma(close, 20), ta.sma(close, 50))
        true
    bool BarR = if ta.crossover(ta.sma(close, 20), ta.sma(close, 50))
        true
    plotshape(BarC, size = size.huge, color = color.red)
    plotshape(BarR, size = size.huge, color = color.green)