Chart TIMEFRAME detection in an indicator?
Forums › ProRealTime English forum › ProBuilder support › Chart TIMEFRAME detection in an indicator?
- This topic has 8 replies, 3 voices, and was last updated 4 years ago by robdav.
-
-
02/23/2018 at 11:28 AM #63645
Hi
I have two questions related to timeframes.
- Is it possible for an indicator to detect what timeframe the chart is when it’s applied? I’ve looked at https://www.prorealcode.com/documentation/timeframe/ and also https://www.prorealcode.com/prorealtime-indicators/higher-timeframe-rsi/ but not sure if it can be done. I work entirely on charts of different minute timeframes.
- With the TIMEFRAME statement, can you specify minutes as opposed to hourly, daily etc?
Thanks again.
Rob
02/23/2018 at 11:50 AM #63651TIMEFRAME statement is only available for ProScreener program. It should be used also for ProOrder, but in a future update.
About code to detect which timeframe is the current chart, you can use this one:
1234567891011121314once NbBar = 1//if BarIndex < NbBar+2 thenMyDay=opendaydayminutes = 1440*(MyDay-MyDay[1])MyHour=openhourhourminutes = 60*(MyHour-MyHour[1])MyMin=openminutebarminutes = MyMin - MyMin[1] + hourminutes + dayminutesbarminutes=abs(barminutes)Mybarminutes = lowest[NbBar](barminutes)[1]//endifreturn Mybarminutes as "Timeframe"1 user thanked author for this post.
02/23/2018 at 1:34 PM #63670Hi Nicolas,
Thanks for this but I’m experiencing a problem with it. Is there a workaround you can think of? I have tried calling it using CALL but I still get the error when trying to create the Donchain channel.
Thanks again, Rob
123456789101112131415161718once NbBar = 1//if BarIndex < NbBar+2 thenMyDay=opendaydayminutes = 1440*(MyDay-MyDay[1])MyHour=openhourhourminutes = 60*(MyHour-MyHour[1])MyMin=openminutebarminutes = MyMin - MyMin[1] + hourminutes + dayminutesbarminutes=abs(barminutes)Mybarminutes = lowest[NbBar](barminutes)[1]//endiflower = lowest[Mybarminutes](low)upper = highest[Mybarminutes](high)middle = (upper + lower) / 2return lower as "lower", upper as "upper", middle as "middle"02/23/2018 at 1:37 PM #6367202/23/2018 at 1:51 PM #63677I agree it’s a bit odd so I’ll try and explain.
If I add this indicator to a twenty minute chart, I was hoping it would detect that it’s a twenty minute chart and simply create a 20 period Donchian channel rather than having to set the period manually.
Try adding it and you’ll see the problem.
02/23/2018 at 2:04 PM #63681This code should work ok:
1234567891011121314151617once NbBar = 2MyDay=opendaydayminutes = 1440*(MyDay-MyDay[1])MyHour=openhourhourminutes = 60*(MyHour-MyHour[1])MyMin=openminutebarminutes = MyMin - MyMin[1] + hourminutes + dayminutesbarminutes=abs(barminutes)Mybarminutes = lowest[max(1,NbBar)](barminutes)[1]if barindex>MyBarminutes thenlower = lowest[Mybarminutes](low)upper = highest[Mybarminutes](high)middle = (upper + lower) / 2endifreturn lower as "lower", upper as "upper", middle as "middle", mybarminutesStill don’t have understood the relationship between how much minutes in a single bar and the period of the donchian channel ❓
1 user thanked author for this post.
02/23/2018 at 2:15 PM #6368505/13/2020 at 4:30 PM #131521Hi Nicolas (I write in English since this topic belongs to the englishspeaking forum)
Wondering how I could detect the timeframe to change automatically some parameters in an indicator, I began to test the code you posted on this page (I just made a copy/paste of the above code, without changing anything).
But I get some very strange results, rather regularly(see the attached file) :for example, for the CAC40 index in 1 hr, I get 60 min (normally), but with a very regular periodicity, on the same graph, the result becomes 960, or 3840, or even 6720 and 37920 (see the attached file). There must be some bug by there !…
Could you give a look ? Thanks in advance.
Patrick
05/13/2020 at 5:46 PM #131538Hi Patrick
I came across an issue with this code and managed to mess it about to get it to be constant. However, I can’t see your code so I don’t know if it will help you.
Cheers
Rob
PS my changes make little sense but it worked for me, I was getting blips.
123456789101112131415161718192021// Some hacky code to work out what the chart timeframe is in minutes up to 1597MyDay=OpenDayDayMinutes = 1440*(MyDay-MyDay[1])MyHour=OpenHourHourMinutes = 60*(MyHour-MyHour[1])MyMin=OpenMinuteBarMinutes = MyMin - MyMin[1] + HourMinutes + DayMinutesBarMinutes = ABS(BarMinutes)IF BarMinutes = 5 THENChartTimeframe = 5ELSIF BarMinutes = 15 THENChartTimeframe = 15ELSIF BarMinutes = 30 THENChartTimeframe = 30ELSIF BarMinutes = 60 THENChartTimeframe = 60ENDIFRETURN ChartTimeframe as "Chart timeframe" -
AuthorPosts
Find exclusive trading pro-tools on