Peter Tran
Peter Tran

Reputation: 1

Pine script - Security function not show correct on different timeframe

I'm newbie and try to get ichimoku data on 4 hour timeframe but it not showing the correct value when I shift.

//@version=4

study(title="test1", overlay=true)

conversionPeriods = input(9, minval=1, title="Conversion Line Length")

basePeriods = input(26, minval=1, title="Base Line Length")

laggingSpan2Periods = input(52, minval=1, title="Leading Span B Length")

displacement = input(26, minval=1, title="Displacement")

donchian_M240(len) => avg(security(syminfo.tickerid, 'D' , lowest(len)), security(syminfo.tickerid, 'D', highest(len)))

tenkanSen_M240 = donchian_M240(conversionPeriods)
kijunSen_M240 = donchian_M240(basePeriods)
senkoSpanA_M240 = avg(tenkanSen_M240, kijunSen_M240)

plot(senkoSpanA_M240[25], title="senkoSpanA_M240[25]")

The value senkoSpanA_M240[25] keep changing when I'm in M5, M15, M30, H1, H4 or D1.

Can you help please?

Upvotes: 0

Views: 271

Answers (1)

tommyf1001
tommyf1001

Reputation: 11

the reason it keeps changing when you change time frames is because you are using a historical bar reference [25] on your senkoSpanA_M240.

This means it will look for the senkoSpanA_M240 condition that occurred 25 bars ago.

Depending on which time frame you are selecting, it will look back 25 bars of that time frame and perform the calculation.

What exactly are you trying to achieve by using the [25]?

Upvotes: 1

Related Questions