G’day,
I am looking for a way to retrieve the highs and lows that occur between a period of time. There are few theories that I would like to test using this data.
My broker offers only PRT 10.2 – I’ve read through the documentation and am unable find a way that would allow me to
- Cycle through a time period, say 9 to 5 and on 5 minute chart and retrieve the OHLC value just for this period
- Optionally return a pivot line of some sort with the midpoint calculated using data in #1
- Calculate standard deviations, moving averages etc only using data from this period.
In essence, I would like to be able to segregate price movements that occur over different time periods and apply standard indicators to test strategies.
Any help or nudge in the right direction would be much appreciated. Thank you!
WingParticipant
Veteran
You can do this I think. If not by changing your chart time settings, by code.
- To cycle through only a set time period on the intraday chart, to find the day’s current high for example, after 9 am before 5 pm.
once DailyHigh=0
if time=090000 then
dailyhigh=high
endif
if time>=090000 and time<=170000 and high>dailyhigh then
dailyhigh=high
endif
return high
- Midpoint would just be average, between high point as explained above and low point retrieved through same method.
- To calculate moving averages etc., you are in a more tricky situation. You will need to write code that alters the return of the standard indicators. A serious problem with PRT is that you cannot make your own arrays, you can only use built in arrays. However, you can make this work. I took your question as a challenge and made a simple moving average that takes into account what happened only upto 170000 yesterday when showing the morning’s moving average. From 170000 to 090000 it just shows normal moving average, not using custom time. Try it out:
myperiod=20
once dailybardiff=1
period=myperiod
once currperiod=1
once lastrealbar=0
once startbar=0
final=average[myperiod]
if currperiod<=period and currperiod>=0 then
mm=summation[dailybardiff](close)
mm2=summation[dailybardiff+(period-currperiod-1)](close)
endif
if time=090000 then
startbar=intradaybarindex
dailybardiff=barindex-lastrealbar
endif
if time>=090000 and time<=1700000 then
currperiod=intradaybarindex-startbar
if currperiod>period then
currperiod=period
endif
if currperiod<period and currperiod>0 then
firstadd=summation[currperiod](close)
final=(mm2-mm+firstadd)/(period)
endif
endif
if time=170000 then
lastrealbar=barindex
endif
return final
Note that this was done in a hurry, but I hope it answers your questions.
Hello, Wing!
Thank you for the initial bit of code to delimit times within a day. B/c of that, I was able to quickly replicate it 6 times to mark session highs and lows for NYC, London, and Tokyo. The user will have to set his own colors/line styles to differentiate them, but this was the fastest (15 mins) I’ve ever conceptualized and finished an indicator! 😀
I have two observations/questions:
I had to kludge the Tokyo session with two separate IF statements for each of high and low, where NYC and London only need one for high and one for low, to account for daily rollover at my local midnight. You can see the commented-out prior attempt with an OR condition to account for the daily rollover (didn’t work). Other users will have to enter in their local times for the three market sessions, and adjust accordingly. Is there a more elegant way to do this?
This indicator freaks out and does not display correctly when I switch to tick charts. I had a similar problem for a previous indicator. Is there a way to account for the difference in ??? timestamp data, duration of bars, I don’t know what, etc.?
The indicator works well enough for any minute/hour chart, so I am putting this open question out for the sake of learning better scripting/coding.
once NYCHi=0
once TOKHi=0
once LONHi=0
once NYClo=0
once TOKlo=0
once LONlo=0
if time=070000 then
NYChi=high
NYClo=low
endif
if time>=070000 and time<=160000 and high>NYChi then
NYChi=high
endif
if time>=070000 and time<=160000 and low<NYClo then
NYClo=low
endif
if time=010000 then
LONhi=high
LONlo=low
endif
if time>=010000 and time<=070000 and high>LONhi then
LONhi=high
endif
if time>=010000 and time<=070000 and low<LONlo then
LONlo=low
endif
if time=180000 then
TOKhi=high
TOKlo=low
endif
if time>=180000 and time <=235959 and high>TOKhi then
//if time>=180000 or time <=010000 and high>TOKhi then
TOKhi=high
endif
if time>=000000 and time <=010000 and high>TOKhi then
//if time>=180000 or time <=010000 and high>TOKhi then
TOKhi=high
endif
if time>=180000 and time <=235959 and low<TOKlo then
//if time>=180000 or time <=010000 and low<TOKlo then
TOKlo=low
endif
if time>=000000 and time <=010000 and low<TOKlo then
//if time>=180000 or time <=010000 and low<TOKlo then
TOKlo=low
endif
return NYChi as "NYC high", LONhi as "LON high", TOKhi as "TOK high", NYClo as "NYC low", LONlo as "LON low", TOKlo as "TOK low"