Referencing the selected timeframe in code

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #181628 quote
    Philstrading
    Participant
    Senior

    I don’t think there is, but is there a way to reference the selected timeframe (default timeframe) so that it can be referred to in hard code?

    this isn’t logical code its to portray the logic.

    Hope that makes sense.. I did submit it to PRT as a suggestion…. Can’t see an obvious reference to it anywhere but still looking… Cheers

    If timeframe (default)=(3 mins) then
    timeframe (3 mins)
    "hard code"
    Timeframe (15 mins)
    "hard code"
    timeframe (hourly)
    "hard code"
    endif
    
    If timeframe (default)=(15 mins)then
    timeframe (15 mins)
    "hard code"
    Timeframe (1 hour)
    "hard code"
    timeframe (4 hours)
    "hard code"
    
    If timeframe (default)=(1 hour) then
    timeframe (1 hour)
    "hard code"
    Timeframe (8 hour)
    "hard code"
    timeframe (daily)
    "hard code"
    endif
    
    timeframe (default)
    return "my selection"
    
    #181629 quote
    Philstrading
    Participant
    Senior

    I’m currently coding variables for gettimeframe with different called indicators as a possible way around it, but haven’t finished that yet,think it may be feasible, just wondering if there is a snippet of code I don’t know about.. I’m optimistic about the called version

    #181767 quote
    Philstrading
    Participant
    Senior

    Ok, it wasn’t particualarly logical how PRT allows that to me but it’s sorted now, easy when you know how… reference the “named fields” in the call lines…

    #199323 quote
    Nick, The Tall Guy
    Participant
    New

    Hi. I’ve got exactly the same problem, but can’t figure out a solution. Any chance you could post a code snippet to show how you solved it. Thanks

    #199326 quote
    robertogozzi
    Moderator
    Master

    This is an indicator to display the current TF on the chart. Its purpose is to show how to detect the current default TF:

    /*           GetTimeFrame
    
       returns the number of seconds in the selected Timeframe:
     
          60       = 1 minute
          300      = 5 minutes
          3600     = 1 hour
          14400    = 4 hours
          86400    = 1 day    (24 hours)
          604800   = 1 week   (7  days)
          2592000  = 1 month  (30 days)
          31536000 = 1 year   (365 days)
                -1 = default TF (or non time-based TF)
    
    
       this indicator returns two values (commented out as it plots text)
    
          TF = 0 seconds
          TF = 1 minutes
          TF = 2 hours
          TF = 3 days
          TF = 4 weeks
          TF = 5 months
          TF = 6 years
    
          N  = number of units
    */
    
    DEFPARAM DrawOnlastBarOnly = true
    ShiftText = 1
    Rge       = high  + averagetruerange[2](close) / 0.4 / ShiftText / 1
    //
    x = GetTimeFrame
    IF (x MOD 60) <> 0 THEN
       TF = 0                         //TF = seconds
       N  = x                         //N  = number of seconds
       DRAWTEXT("#N# Sec", BarIndex,Rge,SansSerif,Standard,18) COLOURED(20,150,150,255)
    ELSE
       IF x >= 31536000 THEN
          TF = 6                      //TF = years
          N  = floor(x / 31536000,0)  //N  = number of years
          DRAWTEXT("#N# Yrs", BarIndex,Rge,SansSerif,Standard,18) COLOURED(20,150,150,255)
       ELSIF x >= 2592000 THEN
          TF = 5                      //TF = months
          N  = floor(x / 2592000,0)   //N  = number of months
          DRAWTEXT("#N# Mth", BarIndex,Rge,SansSerif,Standard,18) COLOURED(20,150,150,255)
       ELSIF x >= 604800 THEN
          TF = 4                      //TF = weeks
          N  = floor(x / 604800,0)    //N  = number of weeks
          DRAWTEXT("#N# wks", BarIndex,Rge,SansSerif,Standard,18) COLOURED(20,150,150,255)
       ELSIF x >= 86400 THEN
          TF = 3                      //TF = days
          N  = floor(x / 86400,0)     //N  = number of days
          DRAWTEXT("#N# Day", BarIndex,Rge,SansSerif,Standard,18) COLOURED(20,150,150,255)
       ELSIF x >= 3600 THEN
          TF = 2                      //TF = hours
          N  = floor(x / 3600,0)      //N  = number of hours
          DRAWTEXT("#N# hrs", BarIndex,Rge,SansSerif,Standard,18) COLOURED(20,150,150,255)
       ELSE
          TF = 1                      //TF = minutes
          N  = floor(x / 60,0)        //N  = number of minutes
          DRAWTEXT("#N# Min", BarIndex,Rge,SansSerif,Standard,18) COLOURED(20,150,150,255)
       ENDIF
    ENDIF
    RETURN// TF AS "TF",N AS "Units"
    Nicolas thanked this post
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Referencing the selected timeframe in code


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by robertogozzi
3 years, 5 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 11/15/2021
Status: Active
Attachments: No files
Logo Logo
Loading...