BCParticipant
Master
Hi PRT Master
How to apply an indicator on day session only?
Let say a MA 50 within 9:30-16:30, calculation only base on this time frame.
Thanks
Try this. Not tested as demo platform down via IG at the moment.
p = 50
starttime = 093000
endtime = 163000
if barindex >= p then
total = 0
count = 0
for j = 0 to barindex
if count < p then
if opentime[j] >= starttime and time[j] <= endtime then
total = total + close[j]
count = count + 1
endif
else
break
endif
next
ave = total/p
endif
return ave as "Session Average"
Thanks Roberto – I knew something must have been created in the past but I could not find it with a search.
BCParticipant
Master
Thanks all, but really a lot of work if apply to others indicator like MACD, RSI etc.
It is not a huge amount of work. but perhaps you should post a suggestion that PRT add a built in platform indicator that does what you are requesting.
Here is an adapted version of my code. Simply change myIndicator to whatever indicator or price value you want a session average of. You can just CALL this indicator from your strategy or add it to any separate indicator.
p = 50
starttime = 093000
endtime = 163000
myindicator = rsi[14]
if barindex >= p then
total = 0
count = 0
for j = 0 to barindex
if count < p then
if opentime[j] >= starttime and time[j] <= endtime then
total = total + myindicator[j]
count = count + 1
endif
else
break
endif
next
ave = total/p
endif
return ave as "Session Average"
BCParticipant
Master
Thanks Vonasi, why p set to 50?
p is the period of the average. MA50 is p=50