elprl
elprl

Reputation: 1960

Calculations on other time periods in pine

I'd like to be able to plot the Ichimoku Cloud of the 45m period over the 1m period chart and signal alerts for certain 45m conditions. The reason for using the 1m period is to apply custom logic for trailing stops to generate alerts as close to the tick as possible.

I know the logic for creating the cloud:

//Ichimoku input Logic
conversionPeriods = input(9, minval=1, title="Conversion Line Periods"),
basePeriods = input(26, minval=1, title="Base Line Periods")
laggingSpan2Periods = input(52, minval=1, title="Lagging Span 2 Periods"),
displacement = input(26, minval=1, title="Displacement")

//Ichimoku function Logic
donchian(len) => avg(lowest(len), highest(len))

//Ichimoku line Logic
tenkanLine = donchian(conversionPeriods)
kijunLine = donchian(basePeriods)
leadLine1 = avg(tenkanLine, kijunLine)
leadLine2 = donchian(laggingSpan2Periods)

How can I achieve this logic on the 1m period but using the 45m period data for the cloud? I imagine a possible solution has something to do with using the security(tickerId, 45, close) but I'm not sure how.

Upvotes: 0

Views: 788

Answers (1)

ahfx
ahfx

Reputation: 377

You're almost there. You can now request a different period through the security function:

plot(security(tickerid, '45', tenkanLine))
plot(security(tickerid, '45', kijunLine))
plot(security(tickerid, '45', leadLine1))
plot(security(tickerid, '45', leadLine2))

Here's a simple example with a sma plot.

sma_expr = sma(close, 14)
sma_45_period = security(tickerid, '45', sma_expr)

plot(sma_45_period)

Upvotes: 3

Related Questions