a little help on adding variables
Forums › ProRealTime English forum › ProBuilder support › a little help on adding variables
- This topic has 10 replies, 3 voices, and was last updated 6 years ago by crolakstrading.
-
-
05/08/2018 at 10:38 PM #70013
I have created an indicator which shows you the high and the low price on the one hour candle stick! (only one hour chart)
12345678910111213defparam CALCULATEONLASTBARS=360if time=010000 thenvalue=highvalue2=lowTop = value*pointsizeDRAWTEXT("---#Top#---",barindex,value)Bottom = value2*pointsizeDRAWTEXT("----#Bottom#----",barindex,value2)endifreturnits only on the 12 am candle stick at the moment!!!
is there a way to add a variable or anything to change the candle stick very easily?
Ex: lets says if i want to see 6am candle’s high and low price. to change it easily without going in to the code and change the time!!i have tried to add variables but doesn’t seems to be working.. probably im not doing it right!! please any help appreciated!
many thanks
05/09/2018 at 12:48 AM #70017I added variable MyTime (see attached screenshot) setting 010000 (leading ZEROs are dropped by PRT) as default thet you may change from the Indicator Properties on the chart.
You can import the attached .ITF file or copy & paste this code:
123456789101112131415defparam CALCULATEONLASTBARS=360// MyTime = 010000if time=MyTime thenvalue=highvalue2=lowTop = value//*pointsizeDRAWTEXT("---#Top#---",barindex,value)Bottom = value2//*pointsizeDRAWTEXT("----#Bottom#----",barindex,value2)endifreturnI commented *POINTSIZE, otherwise you won’t see the HIGH and LOW of the candlestick.
Roberto
05/14/2018 at 8:34 AM #70329Thanks@roberto!! it works!!
1 user thanked author for this post.
11/13/2018 at 7:28 PM #84785Hi roberto,
just a quick question regarding this code.. this shows all past the history as,
defparam CALCULATEONLASTBARS=360
is it possible to have only the current candle high/low at that time and not show all past history but with a boolean or something – to click and to show up all the past history when we want??
please let me know.. thanks in advance
Roh
11/14/2018 at 12:01 AM #847971DEFPARAM DrawOnLastBarOnly = Trueis often the solution, but not in this case if used alone, since if the last bar is NOT equal to MyTime, it would draw nothing!
So we need to save the values of the prices (they are already saved) and bar, then draw those values at any subsequent bar:
123456789101112131415defparam CALCULATEONLASTBARS=360defparam DrawOnLastBarOnly =True// MyTime = 010000if time=MyTime thenvalue=highvalue2=lowmybar =barindexTop = value//*pointsize//DRAWTEXT("---#Top#---",barindex,value)Bottom = value2//*pointsize//DRAWTEXT("----#Bottom#----",barindex,value2)endifDRAWTEXT("---#Top#---",mybar,value+10*pointsize)DRAWTEXT("----#Bottom#----",mybar,value2-10*pointsize)returnI added an offset not to display text too close to bars, but you can remove/change it at your convenience, of course.
1 user thanked author for this post.
11/14/2018 at 12:24 AM #84799Thanks you very much for your help!! it works.. if you remove defparam DrawOnLastBarOnly =True and use defparam CALCULATEONLASTBARS=360 will sow the history too..
how can i add a “boolean” to both above so i can have the current time but when i want to see the history (defparam CALCULATEONLASTBARS=360) then i can click and get it in the chart!! i tried but didnt work.. please see the pic
11/14/2018 at 12:30 AM #84801Variables cannot be used with DEFPARAM, so you will have to modify the code anytime you want to change back to history.
1 user thanked author for this post.
11/14/2018 at 11:12 AM #84825so you will have to modify the code anytime you want to change back to history.
Or make a loop starting from current barindex ? A boolean variable should work in this case, as an option to select the code without the loop (no history plotted) or with the loop (all history plotted).
2 users thanked author for this post.
11/14/2018 at 12:12 PM #84832Thank you both!!
how do I make a loop? please will you be able to help out?
Thanks11/14/2018 at 12:31 PM #84838There you go:
12345678910111213141516171819202122defparam CALCULATEONLASTBARS=360defparam DrawOnLastBarOnly =TrueHistory = 0 //0=NO history 1=YES historyMyTime = 010000MaxLoops = 0IF History THENMaxLoops = 359ENDIFFOR i = 0 TO MaxLoopsif time[i]=MyTime thenvalue=high[i]value2=low[i]mybar =barindex[i]Top = value//*pointsize//DRAWTEXT("---#Top#---",barindex,value)Bottom = value2//*pointsize//DRAWTEXT("----#Bottom#----",barindex,value2)endifDRAWTEXT("---#Top#---",mybar,value+10*pointsize)DRAWTEXT("----#Bottom#----",mybar,value2-10*pointsize)NEXTreturn2 users thanked author for this post.
11/14/2018 at 7:20 PM #84881Thanks you very much.. it’s works!! Thanks again really appreciate your help
-
AuthorPosts
Find exclusive trading pro-tools on