Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

pine script - Capture PA for a set time then use this as a baseline for analysis

Afternoon all,

I am not sure if what I have in my head is possible.

Is it possible to capture Price Action over a set time to then use it as a baseline for future analysis.

So for example capture Price Action between 1200 to 1700, get the average of that information, then use this as a baseline to monitor the percentage change against it after 1700.

I have just trialed the below, which kinda works. But rather than have the mid point of high and low of a specific time, how would I average the PA over that time.

//@version=4
study("Baseline", overlay=false)

baselinetime = input("1500-1700", "Baseline", input.session) //set baseline range
blt = time(timeframe.period, baselinetime)


analysisrange = input("1700-2100", "Analysis Range", input.session) //set analysis range
ar = time(timeframe.period, analysisrange)

var highe_01 = 0.0
var lowe_01  = 10e10
if blt
    if not blt[1]
        highe_01 := high
        lowe_01  := low
    else
        highe_01 := max(high, highe_01)
        lowe_01  := min(low, lowe_01)

midpoint = (highe_01+lowe_01)/2
inc = (close - midpoint)//change(close, length)
p = (inc/close)*100

plot(ar ? p : na, title="Percentage Change", color=color.blue, linewidth=2, style=plot.style_linebr)

I hope that makes sense.

##Also what in the code above is stopping it from plotting over the weekend period?## Update 22/01/2021 @ 20:29 Update the below lines to the below to capture weekend PA

baselinetime = input('1500-1700:1234567', title="Baseline")
analysisrange = input('1700-2100:1234567', title="analysisrange")

Any guidance on the averaging of PA for the 1500 to 1700 would be amazing.

Daniel

question from:https://stackoverflow.com/questions/65847047/capture-pa-for-a-set-time-then-use-this-as-a-baseline-for-analysis

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want to monitor the percentage change from midpoint, then you need to change the calculation of p to the following

p = (inc/midpoint)*100


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...