简体   繁体   中英

trading view / Pine scripting Average of High and Low in

I am trying to get the average high / Low of 10 day or 20 days (Number of Days =input). For this i am using for loop and the security(syminfo.tickerid, 'D', high). But i cannt use the security in for loop. So how can achieve adding all the highs and dividing by number of days. Where number of days is dynamic.

A for loop is unnecessary and inefficient to achieve this in Pine. Prefer the non-repainting version and see this publication for an explanation: How to avoid repainting when using security() - PineCoders FAQ .

//@version=4
study("", "", true)
hlMa = sma(hl2, input(10))

repainting = security(syminfo.tickerid, 'D', hlMa)
plot(repainting)

// More reliable.
noRepainting = security(syminfo.tickerid, 'D', hlMa[1], lookahead = barmerge.lookahead_on)
plot(noRepainting, "", color.orange, 6, transp = 70)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM