Announcement

Collapse
No announcement yet.

Offsetting Background Color

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

  • Offsetting Background Color

    For conditions based on the current bar close(), is it possible to display background color changes not on the current bar but in the right margin offset area ahead of the current bar? If so, how to: Display BgColor on a single bar ahead of the current bar (e.g. current bar +1)? Display BgColor over a range of bars ahead of the current bar (e.g. current bar +1 through bar +3)?

  • #2
    Hello Lancer,

    We have the setBar() function that allows you to set the background color of the current bar or previous bars, but not future bars (setBar(Bar.BgColor, nBarIndex, Color.red); ). However, there is a good alternative you can try. Use the drawLineAbsolute() function and pass the same x coordinate, which would be 1 in this case and (1*Infinity) and 0 values for the y coordinates. Then set the thickness to something like 3.

    PHP Code:
    drawLineAbsolute(1, (1*Infinity), 10PS_SOLID3Color.red"futurebar"); 
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      That works. In some situations there might be object conflicts with that drawLine solution (vs. a BgColor offset), but it does provide the desired effect. Thanks.

      Comment


      • #4
        The attached script displays the line color where desired but the colors do not change when if-statement conditions change (especially for conditions with unary minus values). The logic seems correct, and debug is reporting the correct current bar values for the symbol, but its just not working. Anyone see the problem?
        Attached Files

        Comment


        • #5
          Hello Lancer,

          The problem here is that multiple line objects are being drawn at the same location. We don't have z-order control over which one appears on top. The order is which they are drawn does not always put the last one drawn on top. So you may run into this problem when more than one of the conditions are true. The solution is to create some variable(s) to store the color value(s) when the conditions evaluate to true, then draw one line after the routine. You also need to rearrange the order of the conditions in order for the logic to work out. Try the code below, it should give you a good example of what you need to do. I also added some text labels to show which conditions are currently true.

          PHP Code:
          /*  
          Market Strength:  $ADD (NYSE Advancing Issues minus Declining Issues) MarginColor

          This EFS displays color in the margin to the right of the current bar.
          To display properly, in chart preferences, set right margin offset to 2.

          */


          function preMain() {

              
          setPriceStudy(true);
              
          setStudyTitle("$ADD MarginColor");
              
          setComputeOnClose();
          }

          function 
          main() {
              var 
          cBGcolor Color.grey;
              var 
          cXbull Color.grey;
              var 
          cSbull Color.grey;
              var 
          cBull =  Color.grey;
              var 
          cPos =   Color.grey;
              var 
          cNeg =   Color.grey;
              var 
          cBear =  Color.grey;
              var 
          cSbear Color.grey;
              var 
          cXbear Color.grey;
              
          //Positive
              
          if ((close(0"$ADD") > 50) && (close(0"$ADD") <= 400)) {
                  
          //drawLineAbsolute(2, (1*Infinity), 2, 0, PS_SOLID, 20, Color.RGB(0,100,0), "Positive");  //Color:  Dark Green
                  
          cBGcolor cPos Color.RGB(0,100,0);
              }    
          //Bullish
              
          if ((close(0"$ADD") > 400) && (close(0"$ADD") <= 1000)) {
                  
          //drawLineAbsolute(2, (1*Infinity), 2, 0, PS_SOLID, 20, Color.RGB(0,177,0), "Bullish");  //Color:  Medium Dark Green
                  
          cBGcolor cBull Color.RGB(0,177,0);
              }
          //Strong Bullish
              
          if ((close(0"$ADD") > 1000) && (close(0"$ADD") <= 1500)) {
                  
          //drawLineAbsolute(2, (1*Infinity), 2, 0, PS_SOLID, 20, Color.RGB(0,255,0), "Strong Bullish");  //Color:  Green
                  
          cBGcolor cSbull Color.RGB(0,255,0);
              }
          //Extreme Bullish
              
          if (close(0"$ADD") > 1500) {
                  
          //drawLineAbsolute(2, (1*Infinity), 2, 0, PS_SOLID, 20, Color.RGB(135,206,250), "Extreme Bullish");  //Color:  Light Sky Blue
                  
          cBGcolor cXbull Color.RGB(135,206,250);
              }
          //Negative
              
          if ((close(0"$ADD") < -50) && (close(0"$ADD") >= -400)) {
                  
          //drawLineAbsolute(2, (1*Infinity), 2, 0, PS_SOLID, 20, Color.RGB(100,0,0), "Negative");  //Color:  Dark Red
                  
          cBGcolor cNeg Color.RGB(100,0,0);
              }    
          //Bearish
              
          if ((close(0"$ADD") < -400) && (close(0"$ADD") >= -1000)) {
                  
          //drawLineAbsolute(2, (1*Infinity), 2, 0, PS_SOLID, 20, Color.RGB(177,0,0), "Bearish");  //Color:  Medium Dark Red
                  
          cBGcolor cBear Color.RGB(177,0,0);
              }
          //Strong Bearish
              
          if ((close(0"$ADD") < -1000) && (close(0"$ADD") >= -1500)) {
                  
          //drawLineAbsolute(2, (1*Infinity), 2, 0, PS_SOLID, 20, Color.RGB(255,0,0), "Strong Bearish");  //Color:  Red
                  
          cBGcolor cSbear Color.RGB(255,0,0);
              }
          //Extreme Bearish
              
          if (close(0"$ADD") < -1500) {
                  
          //drawLineAbsolute(2, (1*Infinity), 2, 0, PS_SOLID, 20, Color.RGB(255,0,120), "Extreme Bearish");  //Color:  Red-Magenta
                  
          cBGcolor cXbear Color.RGB(255,0,120);
              }

              
          drawLineAbsolute(2, (1*Infinity), 20PS_SOLID20cBGcolor"futurebar");  
              
              var 
          5;
              
          drawTextAbsolute(x5"Extreme Bullish"Color.whitecXbull
                  
          Text.BOLD|Text.RELATIVETOTOPnull11"Extreme Bullish");
              
          drawTextAbsolute(x20"Strong Bullish"Color.whitecSbull
                  
          Text.BOLD|Text.RELATIVETOTOPnull11"Strong Bullish");
              
          drawTextAbsolute(x35"Bullish"Color.whitecBull
                  
          Text.BOLD|Text.RELATIVETOTOPnull11"Bullish");
              
          drawTextAbsolute(x50"Positive"Color.whitecPos
                  
          Text.BOLD|Text.RELATIVETOTOPnull11"Positive");
              
          drawTextAbsolute(x65"Negative"Color.whitecNeg
                  
          Text.BOLD|Text.RELATIVETOTOPnull11"Negative");
              
          drawTextAbsolute(x80"Bearish"Color.whitecBear
                  
          Text.BOLD|Text.RELATIVETOTOPnull11"Bearish");
              
          drawTextAbsolute(x95"Strong Bearish"Color.whitecSbear
                  
          Text.BOLD|Text.RELATIVETOTOPnull11"Strong Bearish");
              
          drawTextAbsolute(x110"Extreme Bearish"Color.whitecXbear
                  
          Text.BOLD|Text.RELATIVETOTOPnull11"Extreme Bearish");

              return;

          Jason K.
          Project Manager
          eSignal - an Interactive Data company

          EFS KnowledgeBase
          JavaScript for EFS Video Series
          EFS Beginner Tutorial Series
          EFS Glossary
          Custom EFS Development Policy

          New User Orientation

          Comment


          • #6
            Thanks Jason, I'll give that a try. A couple things...

            1) In the original if-statements, the value-range logic was such that only one condition could be true at any time. How then was it possible to have a conflict between statements or have multiple line objects drawing at the same location and time?

            2) I don't understand the reordering of the if-statements. If the order needs to be from least value to largest (as implied by the change to the order of if statements with positive values), then it follows then that the order should start with the -1500 statement, which is the least value of all conditions. Or, must the order always be from lowest positive to highest positive followed by lowest negative (absolute value) to highest negative (absolute value)?

            Comment


            • #7
              Hello Lancer,

              1) You are correct. I overlooked the fact that your conditions were also checking the other side of each range. There's a simpler solution in this case, just set the tag name for all your drawLine calls to the same tag name. Or you could simply add clearLines() to the top of main. Either choice will have the same affect.

              2) Disregard the reordering. That would have only been necessary if you were only checking one side of each range. That was a mistake on my part.
              Jason K.
              Project Manager
              eSignal - an Interactive Data company

              EFS KnowledgeBase
              JavaScript for EFS Video Series
              EFS Beginner Tutorial Series
              EFS Glossary
              Custom EFS Development Policy

              New User Orientation

              Comment

              Working...
              X