How to apply an indicator on day session only?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #110775 quote
    BC
    Participant
    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

    #110776 quote
    Vonasi
    Moderator
    Master

    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"
    
    #110783 quote
    robertogozzi
    Moderator
    Master
    #110787 quote
    Vonasi
    Moderator
    Master

    Thanks Roberto – I knew something must have been created in the past but I could not find it with a search.

    #110817 quote
    BC
    Participant
    Master

    Thanks all, but really a lot of work if apply to others indicator like MACD, RSI etc.

    #110820 quote
    Vonasi
    Moderator
    Master

    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"
    #110842 quote
    BC
    Participant
    Master

    Thanks Vonasi, why p set to 50?

    #110843 quote
    Vonasi
    Moderator
    Master

    p is the period of the average. MA50 is p=50

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

How to apply an indicator on day session only?


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
BC @robin_chan Participant
Summary

This topic contains 7 replies,
has 3 voices, and was last updated by Vonasi
6 years, 3 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 10/22/2019
Status: Active
Attachments: No files
Logo Logo
Loading...