0

The usual delay methods don't have the effect I want. The delay I'm looking for should follow the red line of her level. But the usual delay just moves forward by one bar.enter image description here

Offset, Changing the timeframe didn't help either. The desired result in practice in the figure. As a result, the white line means where the green line should move exactly at the same level as shown in the figure.enter image description here

//@version=2 
study("MTF", overlay=true)
tim=input('5')
tim1=input('5')
out1 = security(tickerid, tim, open)
out2 = security(tickerid, tim1, out1)
plot(out1,color=red,linewidth = 4, transp = 0)
plot(out2,color=green, linewidth = 4, transp = 0)

//@version=5
indicator('MTF', overlay=true)
tim = input('5')
tim1 = input('5')
out1 = request.security(syminfo.tickerid, tim, open)
out2 = request.security(syminfo.tickerid, tim1, out1)
plot(out1, color=color.new(color.red, 0), linewidth=4)
plot(out2, color=color.new(color.green, 0), linewidth=4)
Poulo
  • 11
  • 2
  • it is not reliable with MTF. First [convert your code to v5](https://www.tradingview.com/pine-script-docs/en/v5/migration_guides/index.html) – Gu5tavo71 Feb 03 '23 at 18:53
  • But that won't help. Using two types of barmerge.lookahead will also not give the desired result – Poulo Feb 03 '23 at 18:58

1 Answers1

0

offset depends on the value selected in HTF
you can use a switch

Something like that:

//@version=5
indicator('MTF', overlay=true)
tim = input('5')
tim1 = input('5')
out1 = request.security(syminfo.tickerid, tim, open[1], lookahead = barmerge.lookahead_on)  //No repaint
out2 = request.security(syminfo.tickerid, tim1, out1)

htfOffset   = switch tim
    '5'     => -5
    '15'    => -15
    '30'    => -30
    '45'    => -45
    '60'    => -60

plot(out1, color=color.new(color.red, 0), linewidth=4, offset = htfOffset)
plot(out2, color=color.new(color.green, 0), linewidth=4)
Gu5tavo71
  • 706
  • 1
  • 4
  • 11