Search code examples
pine-scriptpine-script-v5

I would like plot EMA weekly only on TF Daily, how do i do this?


EmaW = request.security(syminfo.tickerid, "1W", ma1, barmerge.gaps_on, barmerge.lookahead_off)

5W = barstate.islast ? EmaW5  
plot(timeframe.isdaily and show_ema_WEEKLY ? print_5:na,"Ema 5 WEEKLY", linewidth=6, color=color.new(color.gray,50))

I would like see on Tf Daily Ema weekly


Solution

  • I'm not sure about the purpose of the print_5 variable in your code, nor what 5W means, but you can replace print_5 with the value you get from the security function to plot the weekly EMA on the daily chart only:

    //@version=5
    indicator("", overlay = true)
    ema5 = ta.ema(close, 5)
    ema5Weekly = request.security(syminfo.tickerid, "1W", ema5, barmerge.gaps_on, barmerge.lookahead_off)
    show_ema_WEEKLY = true
    plot(timeframe.isdaily and show_ema_WEEKLY ? ema5Weekly : na,"Ema 5 WEEKLY", linewidth=6, color=color.new(color.gray,50))
    

    Ema 5 Weekly example