0

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

frien_dd
  • 154
  • 2
  • 12

1 Answers1

0

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

AnyDozer
  • 2,236
  • 2
  • 5
  • 22
  • Thank you @AnyDozer Is there a better way of calculating the AVG PA from 1500 to 1700? – frien_dd Jan 23 '21 at 12:55
  • In my head it would not be a true average (probably wrong) if the was a quick big spike. I think because I have seen the "avg(volume, 100)" didn't know if there is a way to change the lookback 100 to the baseline range period? @AnyDozer thank you for messaging back. – frien_dd Jan 23 '21 at 13:15
  • How does a quick large spike affect the calculation of the average value? High and low values are important for calculating the average value. High and low spike values will also be used. If you want to find the average value taking into account the volumes, then this is a completely different question. – AnyDozer Jan 23 '21 at 13:54
  • thank you. I am content with high/low midpoint as I am only using at as a baseline (I have lots to learn, just curious). [link](https://stackoverflow.com/questions/65858641/how-to-apply-formula-to-several-securities) Have you any advice for my next question. – frien_dd Jan 23 '21 at 15:43
  • If you have received an answer to your question, use the recommendations of the [article](https://stackoverflow.com/help/someone-answers). – AnyDozer Jan 23 '21 at 15:47