Determine the charts time frame in a program

Forums ProRealTime English forum ProBuilder support Determine the charts time frame in a program

Viewing 15 posts - 1 through 15 (of 27 total)
  • #105413

    Team,

    is there a possibility to read out in a indicator or strategy program what the timeframe of the chart is to which the indicator is applied?

    Thanks for a quick info.

     

    #105415

    I don’t fully understand what you are asking, sorry.

    I always put the applicable TF in the title of my Systems, for example … MA Cross DJI 5M v1 

    If using MTF then applicable TFs would be stated in the System code, for example … (Timeframe 5mn, updateonclose)

    #105418

    As for strategies, as GraHal pointed out, you select the TF where you want your code to be executed, and in your code you’d better use comment lines to store info about the author, version, update history, instrument and TF.

    As for indicators, the only way to know the TF is to use OPENTIME (or TIME)  and do some math between the current one and that of the previous bar.

    Be warned that PRT do not support date/time math, so they only treat everything as a real number and you will have to take care of minutes made of 60 seconds (not 100) and hours made of 60 minutes…..

     

    #105538

    I coded this indicator which seems to work quite well at returning values to show what time frame the chart it is applied to is. It can detect every possible time frame for second, minute and hour charts as well as if it is a daily or monthly chart

    The indicator returns five values and only one should be positive for each chart:

    tfs = time frame in seconds (1 = 1 second chart, 2 = 2 second chart etc)

    tfm = time frame in minutes (1 = 1 minute chart, 2 = 2 minute chart etc)

    tfh = time frame in hours (1 = 1 hour chart, 2 = 2 hour chart etc)

    tfd = daily time frame ( 1 = daily chart)

    tfmo = monthly time frame( 1 = monthly chart)

    It works by checking the difference in seconds, minutes, hours, months and days between candle times and if it has x candles in a row with the same difference then it returns the difference as a value. You can increase or decrease the x value if you want – the higher the value the longer the indicator takes before it returns what it thinks the chart time frame is and the lower the value the shorter the time it takes but with a potential increase in the possibility of it being wrong – especially on charts like the 1 second chart where candles are missing and the difference between candles is not always exactly 1 second. A value of 6 for x seems to be a good compromise on popular instruments.

    You could CALL the indicator from a strategy or another indicator to then know in them what time frame chart they were being applied to and then set different variables based on the time frame.

     

    #105563

    This is the snippet Nicolas posted somewhere (I can’t remember where):

     

    1 user thanked author for this post.
    #105594

    I did find that code snippet from Nicolas but it does not work on second time frame charts and daily for example is shown as a 41760 chart which seemed a little difficult to interpret. Pro Real code does not have a OPENSECOND instruction so my code had to find a way around that and also the fact that there is not always a bar every second and sometimes the gap between bars on a 1 second chart can be several seconds for several bars!

    #123797

    Following on from an off forum chat with RobertoGozzi I decided to modify my time frame detector so that the results could be easily called from a strategy or another indicator and then easily used in them.

    It now returns a single number in the range 10001 to 59999. The first digit (on the left) indicates the time frame as follows:

    • 1 = seconds
    • 2 = minutes
    • 3 = hours
    • 4 = daily
    • 5 = monthly

     

    The remaining four digits show the quantity of time so 10001 would be 1 second. 20005 would be 5 minutes and 30004 would be 4 hours.

    You can call the indicator with this code:

    x is the number of bars needed in a row for confirmation of the time frame. You will now have in your strategy or indicator two variables.

    • smhdmo = the time frame from 1 to 5 the same as listed above.
    • timeqty = the quantity of time so 1 minute or 4 hours or 9999 seconds

     

    You can now use these to automate indicator settings like so:

    If you prefer then you can delete the last two lines in the CALL code so that it just returns one variable and then use that in your strategy or indicator.

     

    Here is the new time frame detector code. It can detect any quantity of seconds, minutes or hours up to 9999 (values over 9999 will give an incorrect result returned) but for daily and monthly it is limited to just 1 day or 1 month.

     

     

    2 users thanked author for this post.
    #126667

    i just tried to use Time Frame Detector v2 in an indicator prt v 11, but it return always mytyme = zero . This is the calling source. Any ideas to solve?

    #126672

    Does it return zero or does it just display nothing? It won’t display anything unless you add this to your code:

    I just tested on v11 daily chart and it worked just fine.

    Also did you add x as an external variable?

    #126674

    Here are the two files that you need.  ‘TFD Calling Indicator’ calls ‘Time Frame Detector v2’ with whatever x value you choose.

    1 user thanked author for this post.
    #126700

    Does it return zero or does it just display nothing? It won’t display anything unless you add this to your code:

    I just tested on v11 daily chart and it worked just fine.

    Also did you add x as an external variable?

    This is the sample code i use, i call detector and display return values to chart, (debug use only see attached image).

    I think it return zero, don’t you?

     

    #126723

    I can’t see what instrument or time frame you are testing on in your image. Did you use the ITF files that I posted for you?

    Also perhaps in 40 bars it has not had sufficient quality of bars to identify the time. Change it to this:

     

    1 user thanked author for this post.
    #126740

    now is running, but i see that x must be less than 20, in 15 minute timeframe.

    Thank you

    #126745

    The code checks the time difference between candles so if the data is not clean then it cannot get a match. I actually spotted a whole load of weird data this morning where daily candles do not always open at the same time so for example some Monday candles open at 0404 and some Tuesday candles open at 1313 or 1414. This sort of data will make it impossible to confirm a candle is a daily candle!

    I have commented to Nicolas about it off forum and hopefully he will get some one at PRT to check it out.

    1 user thanked author for this post.
    #126782

    something is wrong..

    look at this code and check with me with using FCA”Italy Share”, Milan, timeframe 15 minutes loading 1k candle from today.

    Run it,  Detector return “Mytyme” > Zero for the first time at bar number 60.

    then, i make a second calling code specular to first code, where first condition is coded “if barindex >= 60”.
    I run it, Detector return “Mytyme” > Zero for the first time at bar number 91.

    i dont’ understand…  it look like that detector need to be called many tymes … but is not correct, i expect that Detector is called once ad it run immediatly correct value.

     

    1 user thanked author for this post.
Viewing 15 posts - 1 through 15 (of 27 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login