简体   繁体   中英

How to get high and low for a specific time period

I am trying to write a strategy in Pinescript for trading view and I have to get the high and low values during a certain time period. Like 10:00 to 10:30 AM. In the documentation I can see the time range but not sure how to get high and low for that particular time period.

Good afternoon Vignesh,

I am interested in your question and if you get an answer I would be grateful if you could share.

I am not sure if the below might assist you. It captures the high and low of the first 60 mins after UTC 00:00.

    //Session Rules
    bartimeSess = time('D')
    newbarSess = bartimeSess != bartimeSess[1]


    high_range = valuewhen(newbarSess,high,0)
    low_range = valuewhen(newbarSess,low,0)

//Calcul For Opening Range
locHigh = security(syminfo.tickerid, "60", high_range)
locLow = security(syminfo.tickerid, "60", low_range)
range = locHigh - locLow

//Plot Statements For Initial Balance
plot(time(timeframe.period) > 0 ? locHigh : na,title="IB High", color=color.blue, transp=20, linewidth=2)
plot(time(timeframe.period) > 0 ? locLow : na,title="IB Low", color=color.blue, transp=20, linewidth=2)


//Plot Statements For Medium of IB range
plot(locLow + range/2,title="IB Medium", color=color.green, transp=20, linewidth=2)

This code is modified from this PineCoders FAQ entry . Note that the hi/lo develops as the monitored period of time elapses:

//@version=4
study("Session hi/lo", "", true)
noPlotOutside = input(true, "Don't plot outside of hours")
showHi = input(true, "Show highs")
showLo = input(true, "Show lows")
srcHi = input(high, "Source for Highs")
srcLo = input(low, "Source for Lows")
timeAllowed = input("1000-1030", "Allowed hours", input.session)

// Check to see if we are in allowed hours using session info on all 7 days of the week.
timeIsAllowed = time(timeframe.period, timeAllowed + ":1234567")
var hi = 10e-10
var lo = 10e10
if timeIsAllowed
    // We are entering allowed hours; reset hi/lo.
    if not timeIsAllowed[1]
        hi := srcHi
        lo := srcLo
    else
        // We are in allowed hours; track hi/lo.
        hi := max(srcHi, hi)
        lo := min(srcLo, lo)

plot(showHi and not(noPlotOutside and not timeIsAllowed)? hi : na, "Highs", color.blue, 3, plot.style_circles)
plot(showLo and not(noPlotOutside and not timeIsAllowed)? lo : na, "Lows", color.fuchsia, 3, plot.style_circles)

在此处输入图像描述

Disclosure: the link in this answer points to a PineCoders FAQ entry. I am a member of the PineCoders community and I most probably wrote that FAQ entry. PineCoders is a TradingView-supported group of volunteer Pine coders and PineCoders' website is strictly educational. Neither TradingView nor PineCoders benefits financially from sending traffic to pinecoders.com, and the site contains no affiliate/referral links.

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