Switch indicators on/off

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #173047 quote
    dave_mozdave_moz
    Participant
    Junior

    Could anyone tell me if there is a way to show or hide an indicator based on conditions relating specifically to the current candle only?

    e.g.
    If low<EMAx and close>EMAx then display EMAx.

    I did try a custom EMA indicator but the the EMA only displayed on each candle in the past which met the criteria rather than just plotting the EMA on the chart.

    Thanks.

    #173048 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Try this one (not tested):

    MyEma = average[20,1](close)
    t    = 0   //transparency = invisible
    If low < MyEma and close > MyEma then
       t = 255
    Endif
    Return MyEma coloured(0,255,0,t) as “MyEma”

    it takes advantage of the optional 4th COLOUR parameter, transparency (0-255), to make ema visible only when conditions are met.

    #173049 quote
    GraHalGraHal
    Participant
    Master

    Impressive Wizardry! 🙂

    Link to above added as Log 293 here …

    Snippet Link Library

    robertogozzi thanked this post
    #173051 quote
    dave_mozdave_moz
    Participant
    Junior

    Hi,

    Unfortunately this is still only displaying the MA on candles which meet the criteria.

    #173054 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Isn’t that what you meant with “If low<EMAx and close>EMAx then display EMAx”?

    #173055 quote
    dave_mozdave_moz
    Participant
    Junior

    Sorry, I didn’t make it clear.

    I want to be able to display MA[x] on the whole chart but only if the last day’s candle meets the requirements.

    So if today meets the conditions then MA[x] is displayed on the whole chart.

    Hope that makes sense!

    #173065 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    There’s no instruction to achieve that, so it must be coded.

    I’ll make it asap.

    #173066 quote
    dave_mozdave_moz
    Participant
    Junior

    Great, thanks.

    #173077 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Bob’s your uncle:

    DEFPARAM DrawOnLastBarOnly = True
    Periods  = 20      //Ema periods
    LookBack = 200     //plot Ema on the last 200 bars
    MyEma = average[Periods,1](close)
    If low < MyEma and close > MyEma then
       FOR i = (LookBack - 1) DownTo 0
          j = i + 1
          DrawSegment(BarIndex[j],MyEma[j],BarIndex[i],MyEma[i]) coloured(0,255,0,255) style(Line,3)
       NEXT
    Endif
    Return

    Line 2 are the Ema periods and Line 3 are the number of bars you want the Ema to be plotted when conditions are met.

    dave_moz thanked this post
    #173085 quote
    dave_mozdave_moz
    Participant
    Junior

    That’s amazing, thank you!
    Works like a charm.

    icharttop thanked this post
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Switch indicators on/off


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 9 replies,
has 3 voices, and was last updated by dave_mozdave_moz
5 years, 2 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/03/2021
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...