Announcement

Collapse
No announcement yet.

Change band color

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Change band color

    Is it possible to dynamically change the color of certain sections of a band based on a given criterion?, e.g. if MACD > 0 then change band color to green (from that point on, until MACD < 0 and then you change the color to red).

  • #2
    here's a modified builtinmacd (originally provided by Alex)

    you can modify the colors of the instantcolorlines in the efs editor.
    Hope this helps.

    kz
    Attached Files

    Comment


    • #3
      Actually, I couldn't make any of the suggestions work with bands. However I found the following solution, based on drawLineRelative() and it works fine:

      if (dblMACD >= 0) strBasisColor = "Color.green"; else strBasisColor = "Color.red";

      drawLineRelative(-1,0,0,0, PS_SOLID, 2, eval(strBasisColor),fnGetTagID());
      addBand(0,PS_SOLID,2,eval(strBasisColor),"0line");

      It basically draws a mini line segment for each bar and creates a band as it goes.
      I still have to use the addBand() at the end to create an extension of the band to the rightmost edge of the indicator pane.

      Comment


      • #4
        are you only trying to change the color of the horizontal bands?

        my mistake if that's what you're trying to accomplish. I originally thought you meant the MACD or signal line...

        kz

        Comment


        • #5
          kz - yes that's what I was trying to do, basically change the color of the horizontal band based on the color of the MACD. My solution seems to work but I was wondering if there was a more elegant one. Also what is the purpose of INSTANTCOLORLINE, it seems to have the same way as a regular LINE, what's the difference?

          Comment


          • #6
            look at this new version - lines 84-89
            you could also look at the signal line if you'd prefer by changing the study lines where appropriate.

            the "6" is the width of the band, 0 is the level.

            instantcolorline allows the line to change at the peaks and valleys whereas the other normal line changes seems to have a lag on the color change points

            if you want them to be a solid color, just change them back
            to "PLOTTYPE_LINE"

            Kirk
            Attached Files

            Comment


            • #7
              Thanks for the info. I tried INSTANTCOLORLINE and it works well.

              Comment

              Working...
              X