Using Both Text and Lines

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #74104 quote
    juanj
    Participant
    Master

    Good Day

    I am building an on chart indicator that contains both text as well as lines.

    But it seems that the only way to return text is using the Return command with no further elements. (i.e. Return *nothing else*)

    For Example:

    MA = Average[20](close)
    Rge = averagetruerange[10](close)
    
    If low – high[1] > 0.0001 THEN
    DRAWTEXT(“GAP”, barindex, High+Rge/0.2,SansSerif,Italic,10)coloured(0,0,255,255)
    DRAWARROWUP(barindex, lOW-Rge)coloured(0,0,255,255)
    EndIf
    
    Return MA as “MA”
    
    //doesn’t return the text or the arrow, only the MA

    So the question is how do I return both the MA as well as the Text/Arrow?

    #74113 quote
    robertogozzi
    Moderator
    Master

    To write code, please use the <> “insert PRT code” button, to make code easier to read. Thank you.

    #74116 quote
    robertogozzi
    Moderator
    Master

    I tried it on DAX daily and it works fine, printint text, arrows and ma.

    #74121 quote
    juanj
    Participant
    Master

    Interesting, here is the full code set showing no text or arrows;

     

    Defparam calculateonlastbars = 800
    
    //Variables:
    
    //Periods = 21
    //Deviations = 1.618
    //RSITopThreshold = 95
    //RSIBottomThreshold = 5
    //RSIPeriod = 2
    //ADXPeriod = 14
    //ADXVal = 20
    //MAPeriod = 20
    
    // ELSASTIC WEIGHTED MOVING AVERAGE
    PRICE  = LOG(customclose)
    alpha  = 2/(PERIODS+1)
    // EWMA (EMA)
    if barindex < PERIODS then
    EWMA = AVERAGE[3](PRICE)
    else
    EWMA = alpha * PRICE + (1-alpha)*EWMA
    endif
    // ELASTIC WEIGHTED STANDARD DEVIATION (ESD)
    error = PRICE - EWMA
    dev   = SQUARE(error)
    if barindex < PERIODS+1 then
    var  = dev
    else
    var   = alpha * dev + (1-alpha) * var
    endif
    ESD   = SQRT(var)
    
    //ZeroLag Data
    //lag = ROUND((period-1)/2)
    //data = (close + (close-close[lag]))
    //ZLEMA = exponentialaverage[period](data)
    //BolUp = ZLEMA+STD[period]*dev
    //BolDn = ZLEMA-STD[period]*dev
    
    // BANDS
    UB = EXP(EWMA + (DEVIATIONS*ESD))
    BB = EXP(EWMA - (DEVIATIONS*ESD))
    MID = EXP(EWMA)
    
    RSI2 = RSI[RSIPeriod](close)
    
    BollR = UB-BB
    BRSI = BB + (BollR*(RSI2*0.01))
    BRSIT = BB + (BollR*(RSITopThreshold*0.01))
    BRSIB = BB + (BollR*(RSIBottomThreshold*0.01))
    
    //Dev Scaled MA
    
    if barindex < MAPeriod then
    DSMA = AVERAGE[3](PRICE)
    ElsIf barindex > MAPeriod Then
    //Smooth with a Super Smoother
    a1 = exp(-1.414*3.14159 / (.5*MAPeriod))
    b1 = 2*a1*Cos(1.414*180 / (.5*MAPeriod))
    c2 = b1
    c3 = -a1*a1
    c1 = 1 - c2 - c3
    //Produce Nominal zero mean with zeros in the transfer response
    //at DC and Nyquist with no spectral distortion
    //Nominally whitens the spectrum because of 6 dB per octave
    //rolloff
    Zeros = Close - Close[2]
    //SuperSmoother Filter
    Filt = c1*(Zeros + Zeros[1]) / 2 + c2*Filt[1] + c3*Filt[2]
    //Compute Standard Deviation
    RMS = 0
    For count = 0 to MAPeriod - 1 do
    RMS = RMS + Filt[count]*Filt[count]
    next
    RMS = SqRt(RMS / MAPeriod)
    //Rescale Filt in terms of Standard Deviations
    ScaledFilt = Filt / RMS
    alpha1 = Abs(ScaledFilt)*5 / MAPeriod
    DSMA = alpha1*Close + (1 - alpha1)*DSMA[1]
    endif
    
    //KASE Deviation Stoploss Bands
    
    n = 30
    periodFast = 9
    periodSlow = 21
    
    DTR = max(max(High - Low[2], abs(High - Close[2])),max(abs(Low - Close[2]),(abs(Low - Close[2]))))
    avg = average[n](DTR)
    st = std[n](DTR)
    
    maFast = average[periodFast,1](close)
    maSlow = average[periodSlow,1](close)
    
    if maFast<maSlow then
    WarningLine = typicalprice+avg
    Dev1 = typicalprice+avg + st
    Dev2 = typicalprice+avg + 2.2*st
    Dev3 = typicalprice+avg + 3.6*st
    else
    WarningLine = typicalprice-avg
    Dev1 = typicalprice-avg - st
    Dev2 = typicalprice-avg - 2.2*st
    Dev3 = typicalprice-avg - 3.6*st
    endif
    
    //RSI Divergence
    
    MinBarRange = 3
    
    Rge = averagetruerange[10](close)
    MyRSI = rsi[RsiPeriod](Close)
     
    ONCE ShiftText = 3
     
    RsiMax = MyRSI < MyRSI[1] and MyRSI[1] > MyRSI[2] and MyRSI[1] > RSITopThreshold
    RsiMin = MyRSI > MyRSI[1] and MyRSI[1] < MyRSI[2] and MyRSI[1] < RSIBottomThreshold
     
    if RsiMax then
    RSIMax1 = MyRSI[1]
    High1 = High[1]
     
    for I = MinBarRange to  80
    if RsiMax[I] then
    RSIMax2 = MyRSI[I + 1]
    High2 = High[I + 1]
    If High1 > High2 and RSIMax1 < RSIMax2 then
    DRAWARROWDOWN(barindex, High + Rge / ShiftText)coloured(255,192,203,255)
    DRAWTEXT("Regular", barindex, High + Rge / ShiftText / 0.3,SansSerif,Italic,10)coloured(0,0,255,255)
    elsif High1 < High2 and RSIMax1 > RSIMax2 then
    DRAWARROWDOWN(barindex, High + Rge / ShiftText)coloured(255,192,203,255)
    DRAWTEXT("Hidden", barindex, High + Rge / ShiftText / 0.2,SansSerif,Italic,10)coloured(0,0,255,255)
    endif
    break
    endif
    next
    endif
     
    if RsiMin then
    RSIMin1 = MyRSI[1]
    Low1 = Low[1]
     
    for I = MinBarRange to  80
    if RSIMin[I] then
    RSIMin2 = MyRSI[I + 1]
    Low2 = Low[I + 1]
    If Low1 < Low2 and RSIMin1 > RSIMin2 then
    DRAWARROWUP(barindex, lOW - Rge / ShiftText)coloured(0,0,255,255)
    DRAWTEXT("Regular", barindex, lOW - Rge / ShiftText / 0.3,SansSerif,Italic,10)coloured(0,0,255,255)
    elsif Low1 > Low2 and RSIMin1 < RSIMin2 then
    DRAWARROWUP(barindex, lOW - Rge / ShiftText)coloured(0,0,255,255)
    DRAWTEXT("Hidden", barindex, lOW - Rge / ShiftText / 0.2,SansSerif,Italic,10)coloured(0,0,255,255)
    endif
    break
    endif
    next
    endif
    
    If low - high[1] > 0.0001 THEN
    DRAWRECTANGLE(barindex[1],close[1],barindex,low) COLOURED(0,0,0,255)
    DRAWARROWDOWN(barindex, High + Rge / ShiftText)coloured(255,192,203,255)
    DRAWTEXT("GAP", barindex, High + Rge / ShiftText / 0.2,SansSerif,Italic,10)coloured(0,0,255,255)
    ElsIf low[1] - high > 0.0001 THEN
    DRAWRECTANGLE(barindex[1],close[1],barindex,high) COLOURED(0,0,0,255)
    DRAWARROWUP(barindex, lOW - Rge / ShiftText)coloured(0,0,255,255)
    DRAWTEXT("GAP", barindex, lOW - Rge / ShiftText / 0.3,SansSerif,Italic,10)coloured(0,0,255,255)
    ENDIF
    
    //ADX ActiveTrend Indicator
    
    //If hour < 9 or hour > 17 Then
    //BACKGROUNDCOLOR(0,0,0,0)
    If ADX[ADXPeriod] > ADXR[ADXPeriod] and ADX > ADXVal Then
    BACKGROUNDCOLOR(0,127,255,25)
    ElsIf ADX[ADXPeriod] < ADXR[ADXPeriod] and ADX <= ADXVal Then
    BACKGROUNDCOLOR(255,99,71,25)
    EndIf
    
    RETURN MID as "EWMA(EMA)", UB style(line,2) as "+ESD", BB style(line,2) as "-ESD", BRSI coloured(0,0,255) style(line,2) as "RSI2", BRSIT coloured(0,255,0) style(line,2) as "95", BRSIB coloured(255,0,0) style(line,2) as "5", DSMA coloured(142,123,38) style(line,2) AS "Dev MA", Warningline coloured(255,0,0) style(dottedline,1) as "WarningLine", Dev1 coloured(2, 118, 253) style(dottedline,1) as "DevStop1", Dev2 coloured(20, 100, 244) style(dottedline,1) as "DevStop2", Dev3 coloured(1, 71, 250) style(dottedline,1) as "DevStop3"
    
    #74231 quote
    GraHal
    Participant
    Master

    Works good for me also juanj … see attached

    #74234 quote
    juanj
    Participant
    Master

    Where are your price candles? The indicator is to be overlaid on price. Mine shows everything except the text?

    #74238 quote
    GraHal
    Participant
    Master

    Yes I know, but I’ve got so many added lines on my Price Chart I wanted to see all what yours showed first as a separate Indicator else I would not see all your intricacies.

    I’ve made the text bigger, but is there anyway to make arrows bigger?

    #74248 quote
    juanj
    Participant
    Master

    For what it’s worth, here is an explanation of how the indicator works.

    Idea: Having an all in one indicator that provides all the information I need on the chart itself.

    1. Exponentially Calculated Bollinger Band
    2. Background Filter indicating the Trend strength using ADX in relation to ADXR (Dark Blue = Trending, Light Red = Ranging)
    3. The oscillating blue line is a normalized RSI2 (Above green line = Good long exit, Below red line = Good short exit)
    4. Dashed lines = KASE Dev stop levels (switching on a 9EMA and 21EMA cross – keeping you with Price Action)
    5. Golden Line = Deviation based Moving Average
    GraHal and Nicolas thanked this post
    #74361 quote
    robertogozzi
    Moderator
    Master

    Remove ONCE from line 114 and text will appear…. magically!!!!

    #74429 quote
    juanj
    Participant
    Master

    Thanks RobertoGozzi, your magic works

    #74430 quote
    robertogozzi
    Moderator
    Master

    Glad to know, but beware.., that trick can be made only ONCE!!!

    AhAhAh…. I’m kidding.

    #195350 quote
    Wolf
    Participant
    New

    Hi Roberto,

    I am Italian like you but I write in English so everyone can understand.

    I would like to have text displayed and I am struggling to understand how to get it done.

    I know drawtext should be used by I visibly miss something. can you please show me a sample of full code to simply display for example a text? Possible on top right corner of the indicator..

     

    Thanks a lot

    #195355 quote
    Wolf
    Participant
    New

    I found it, it works! 🙂

    #195357 quote
    robertogozzi
    Moderator
    Master

    @Wolf

    Do not double post. Ask your question only once and only in one forum. All double posts will be deleted anyway so posting the same question multiple times will just be wasting your own time and will not get you an answer any quicker. Double posting just creates confusion in the forums.

    Thanks 🙂

    #195365 quote
    Wolf
    Participant
    New
    Hi Roberto,
    I know sorry, I even wanted to delete my posts then but did not know how to delete them.
    Is there anyway to shift the text a bit to the right so it’s not just above the bars?
    Thanks
    🙂
Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.

Using Both Text and Lines


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
juanj @juanj Participant
Summary

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

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 06/22/2018
Status: Active
Attachments: 3 files
Logo Logo
Loading...