hlc3 is a predefined series float in Pine Script for the timeframe of the current chart. How do I get the a hlc3 series float of lower timeframe within the current chart?

Say am on a daily chart, my pinescript (V5) code will give me the series float for predefined variable hlc3. I want to to get the hourly series hlc3

//(high + low + close)/3 Low1HLC1 = request.security_lower_tf(syminfo.tickerid, timeframe = "1", expression = (high + low + close) / 3) esa1 = ta.ema(Low1HLC1, n1) 

I get the error: Error at 119:15 Cannot call 'ta.ema' with argument 'source'='Low1HLC1'. An argument of 'float[]' type was used but a 'series float' is expected.

I want to get a series float of lower timeframe hlc3

1 Answer

With the lower time frame data you have to do some extra steps to be able to use it. You'll need to put the data into a new float array and then you can access it. Here's an example on a 5 minute chart requesting the data from a 1 minute chart

indicator("My script") hlc = request.security_lower_tf(syminfo.tickerid, '1', hlc3) float[] newArray = array.new<float>(5) if hlc.size() > 0 for i = 0 to hlc.size() - 1 newArray.shift() newArray.push(hlc.get(i)) if barstate.islast label.new(bar_index,high,str.tostring(newArray.get(0), format.mintick) + ' ' + str.tostring(hlc.get(0), format.mintick)) ma = newArray.avg() plot(ma) 

So here I have the same data in both arrays. I left the debug label on so you can see. Then just quickly turned that into a moving average, which looks like what you are trying to do.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.