I have created an indicator which shows you the high and the low price on the one hour candle stick! (only one hour chart)
defparam CALCULATEONLASTBARS=360
if time=010000 then
value=high
value2=low
Top = value*pointsize
DRAWTEXT("---#Top#---",barindex,value)
Bottom = value2*pointsize
DRAWTEXT("----#Bottom#----",barindex,value2)
endif
return
its 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
I 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:
defparam CALCULATEONLASTBARS=360
// MyTime = 010000
if time=MyTime then
value=high
value2=low
Top = value//*pointsize
DRAWTEXT("---#Top#---",barindex,value)
Bottom = value2//*pointsize
DRAWTEXT("----#Bottom#----",barindex,value2)
endif
return
I commented *POINTSIZE, otherwise you won’t see the HIGH and LOW of the candlestick.
Roberto
Thanks@roberto!! it works!!
Hi 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
DEFPARAM DrawOnLastBarOnly = True
is 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:
defparam CALCULATEONLASTBARS=360
defparam DrawOnLastBarOnly =True
// MyTime = 010000
if time=MyTime then
value=high
value2=low
mybar =barindex
Top = value//*pointsize
//DRAWTEXT("---#Top#---",barindex,value)
Bottom = value2//*pointsize
//DRAWTEXT("----#Bottom#----",barindex,value2)
endif
DRAWTEXT("---#Top#---",mybar,value+10*pointsize)
DRAWTEXT("----#Bottom#----",mybar,value2-10*pointsize)
return
I added an offset not to display text too close to bars, but you can remove/change it at your convenience, of course.
Thanks 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
Variables cannot be used with DEFPARAM, so you will have to modify the code anytime you want to change back to history.
so 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).
Thank you both!!
how do I make a loop? please will you be able to help out?
Thanks
There you go:
defparam CALCULATEONLASTBARS=360
defparam DrawOnLastBarOnly =True
History = 0 //0=NO history 1=YES history
MyTime = 010000
MaxLoops = 0
IF History THEN
MaxLoops = 359
ENDIF
FOR i = 0 TO MaxLoops
if time[i]=MyTime then
value=high[i]
value2=low[i]
mybar =barindex[i]
Top = value//*pointsize
//DRAWTEXT("---#Top#---",barindex,value)
Bottom = value2//*pointsize
//DRAWTEXT("----#Bottom#----",barindex,value2)
endif
DRAWTEXT("---#Top#---",mybar,value+10*pointsize)
DRAWTEXT("----#Bottom#----",mybar,value2-10*pointsize)
NEXT
return
Thanks you very much.. it’s works!! Thanks again really appreciate your help