a little help on adding variables

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #70013 quote
    crolakstrading
    Participant
    Senior

    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

    #70017 quote
    robertogozzi
    Moderator
    Master

    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

    #70329 quote
    crolakstrading
    Participant
    Senior

    Thanks@roberto!! it works!!

    robertogozzi thanked this post
    #84785 quote
    crolakstrading
    Participant
    Senior

    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

    #84797 quote
    robertogozzi
    Moderator
    Master
    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.

    crolakstrading thanked this post
    #84799 quote
    crolakstrading
    Participant
    Senior

    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

    #84801 quote
    robertogozzi
    Moderator
    Master

    Variables cannot be used with DEFPARAM, so you will have to modify the code anytime you want to change back to history.

    crolakstrading thanked this post
    #84825 quote
    Nicolas
    Keymaster
    Master

    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).

    robertogozzi and crolakstrading thanked this post
    #84832 quote
    crolakstrading
    Participant
    Senior

    Thank you both!!
    how do I make a loop? please will you be able to help out?
    Thanks

    #84838 quote
    robertogozzi
    Moderator
    Master

    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
    Nicolas and crolakstrading thanked this post
    #84881 quote
    crolakstrading
    Participant
    Senior

    Thanks you very much.. it’s works!! Thanks again really appreciate your help

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.

a little help on adding variables


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 10 replies,
has 3 voices, and was last updated by crolakstrading
7 years, 2 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/08/2018
Status: Active
Attachments: 5 files
Logo Logo
Loading...