Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to use security function without delay in pinescript?

I’m using security function like below:

indicator("My script" , overlay = true)

mystate = close[0] >= open[0] and close[1] >= open[1] and close[2] >= open[2] and close[3] >= open[3] and close[4] >= open[4]

transtate = request.security(syminfo.tickerid, "30", mystate)

plotshape(transtate,  
          size=size.small,  
          style= shape.triangledown, 
          color=color.red,  
          text = 'this', 
          textcolor=color.red)

it means plot the candle when 5 green candle Continuous.

so it plot 1:30 in time frame 30

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

and when switch time frame to 15 the plots are on 1:45 and 2:00

and in time frame 5 the plots are on 1:55 , 2:00 , 2:05 , 2:10 , 2:15 , 2:20

how can I get plots immediately in right time( in example above in 1:30) in all time frame ?

picture below is in time frame 5 minute
enter image description here

picture below is in time frame 30 minute
enter image description here

I tried to plot candles on time frame 30 with security function and see the plot shape on lower time frames.

>Solution :

Use the barmerge.lookahead_on parameter of the security() function to match the start of the higher timeframe bar with the first one in the same period on lower tf

transtate = request.security(syminfo.tickerid, "30", mystate, lookahead = barmerge.lookahead_on)

Note that the security with lookahead leaks future data on historical bars.

If you would like to plot only on the first lower tf bar, replace the condition in plotshape to:

plotshape(transtate and not nz(transtate[1]), ...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading