How to get current TimeFrame inside indicator code?
Forums › ProRealTime English forum › ProBuilder support › How to get current TimeFrame inside indicator code?
- This topic has 6 replies, 4 voices, and was last updated 7 years ago by robertogozzi.
-
-
04/12/2017 at 12:59 AM #31811
Hi,
How can my indicator automatically know about current time frame for the chart (like daily, 4hrs, 1hr, 15min, 5min etc)?
04/12/2017 at 4:46 PM #31871This code snippet can return the current timeframe information as a value in minutes: (not from me, came from a topic on the French forum if I remember correctly)
1234567891011121314once NbBar = 1if 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"04/12/2017 at 5:48 PM #3188207/25/2017 at 7:35 PM #41604Would anyone be so kind to explain what the code just 2 posts above is doing? I am completely lost on understanding it.
It begins already with the if statement: BarIndex will never/seldom be less than 3 (at least on my computer I see only values around 500 minimum) , so the caculation should never be executed!
I tested all the times I can load with that code, for 4 hours it gives Timeframe=1.500 although the abs(barminutes) is correct 240 and for 7 hours Timeframe=180 with abs(barminutes)=420.
I need to limit calculation in one of my scripts depending on the timeframe of the chart and usually I am of the opinion “one must not invent the wheel for the 101st time”, but I don’t like to just c&p code hoping it will work without understanding it. That’s the code from above:
get timeframe of current chart1234567891011121314once NbBar = 1if 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"Thanks a lot.
07/25/2017 at 8:10 PM #41606Why
1if BarIndex < NbBar+2 thenis not written as
1if BarIndex < 3 then?
Because NbBar NEVER changes!
1 user thanked author for this post.
07/26/2017 at 12:24 PM #41658Thanks for your answer. It gave me indirectly the first solution (the if statement says simply: only take the first two bars for caculation) – sometimes I am a blockhead!
You said NbBar never changes – 2 also never changes, so consequently NbBar+2 will ALWAYS be 3 and it is legitimate to write
1if BarIndex < 3 thenNbBar is only used once agin in that code, in the line
1Mybarminutes = lowest[NbBar](barminutes)[1]and as it never changes and in the meantime its value has not been changed (by looping or something like that), it is as well legitimate to write
1Mybarminutes = lowest[1](barminutes)[1]and NbBar=1 is not needed any longer. Correct?
Thank you so much.
07/26/2017 at 1:43 PM #41678 -
AuthorPosts
Find exclusive trading pro-tools on