Announcement

Collapse
No announcement yet.

Set Bar Colors 7.8 vs. 7.9 problem

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

  • Set Bar Colors 7.8 vs. 7.9 problem

    I just noticed some studies I created (trendline stuff) that used the setBar() command for line colors no longer work.

    setBar(Bar.FgColor, x,x, Color.red) fails in 7.9

    setBarFgColor(Color.red, x) does work in 7.9

    Are all the setBar(style,x,x,x) type commands now dead in 7.9 or is this a specific bug of some sort?

    It will take a lot of editing to change all (dozens) or my studies to use the new EFS2 format if true.

    Thanks

    Tex
    Tex

  • #2
    Hello Tex,

    setBar() is working fine on my end. Please post your code and I'll see if there is something causing a problem. Is the series index number you are referencing exist for the bar index you are trying to change?
    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
      Well, it's older code and maybe wasn't written super well, but here it is. I also notice in the editor that the usual BLUE colors for commands are BLACK for the setbar() thing while BLUE for the setBarFgColor() thing.

      Here is the old code:


      if((LastTrend == 1) || (LastTrend == 0)) // The trend is up (or new), put green line under it
      {
      if(trendL0 < vLow[0]) // Is the trend changing?
      {
      setBar(Bar.FgColor, 0, 7, Color.yellow); // Nope, keep things going
      setBar(Bar.FgColor, 0, 8, Color.green);
      setBar(Bar.Thickness, 0, 7, 1);
      setBar(Bar.Thickness, 0, 8, 2);
      LastTPrice = trend1;
      LastTrend = 1;
      }
      else
      {
      if(vClose[0] > tPriceM0) // Trend is close, verify it
      { // It's the same, keep going
      setBar(Bar.FgColor, 0, 7, Color.yellow);
      setBar(Bar.FgColor, 0, 8, Color.green);
      setBar(Bar.Thickness, 0, 7, 1);
      setBar(Bar.Thickness, 0, 8, 2);
      LastTPrice = trend1;
      }
      else
      { // Trend really changed, swap colors
      setBar(Bar.FgColor, 0, 7, Color.red);
      setBar(Bar.FgColor, 0, 8, Color.yellow);
      setBar(Bar.Thickness, 0, 7, 2);
      setBar(Bar.Thickness, 0, 8, 1);
      LastTrend = -1;
      LastTPrice = trend1;
      }
      }
      }


      Here is the new code that works fine:

      if((LastTrend == 1) || (LastTrend == 0)) // The trend is up (or new), put green line under it
      {
      if(trendL0 < vLow[0]) // Is the trend changing?
      {
      setBarFgColor(Color.yellow, 7);
      setBarFgColor(Color.green, 8);
      setBarThickness(1, 7);
      setBarThickness(2, 8);
      LastTPrice = trend1;
      LastTrend = 1;
      }
      else
      {
      if(vClose[0] > tPriceM0) // Trend is close, verify it
      { // It's the same, keep going
      setBarFgColor(Color.yellow, 7);
      setBarFgColor(Color.green, 8);
      setBarThickness(1, 7);
      setBarThickness(2, 8);
      LastTPrice = trend1;
      }
      else
      { // Trend really changed, swap colors
      setBarFgColor(Color.red, 7);
      setBarFgColor(Color.yellow, 8);
      setBarThickness(2, 7);
      setBarThickness(1, 8);
      LastTrend = -1;
      LastTPrice = trend1;
      }
      }
      }


      The only difference I can see is the lack of the bar index which I used in other code that also no longer functions.


      Tex

      Comment


      • #4
        Hello Tex,

        The setBar() function's intended usage is to change historical bars (i.e. bar indexes of -1 or older). In previous versions it did allow you to change bar 0, but that was not intended. For the current bar you need to use setBarFgColor(), setBarBgColor(), setBarThickness() and setBarStyle().
        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


        • #5
          Well, my ignorance is showing. Your simple comment about intended use included in the Help File would have saved me a ton of editing, but find/replace commands make it relatively painless.

          Looks like I have a lot of editing to do. I notice this same Bar Index "0" problem in a ton of other commands.

          However, in the editor, the usual blue color for commands has changed the setbar(Bar.FgColor) from blue to black... is this a hint I shouldn't be using them anymore?

          Tex

          Comment


          • #6
            Hello Tex,

            The "0" bar index only affects setBar, nothing else. The blue color for the keyword is not a problem either. Those colors are set by an internal file in the application that just needs to be updated. There is no negative affect to the formula language performance to worry about based on the keyword coloring.
            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


            • #7
              setBar

              Hi,

              I want to unpaint some study values after some time and I used

              setBar(Bar.FgColor,-0, 0, null)

              when a new bar comes but it does not seem to work.

              Is there a way to get the Background color of the chart so that I can use setBar(Bar.BgColor,...) or is there a way to make a study draw only the last 10 values in realtime?

              I tried to use reloadEFS() but it does not seem to work either.

              Thank you,

              Comment


              • #8
                sorry for the typo

                I meant:

                setBar(Bar.FgColor,-10, 0, null)

                Comment


                • #9
                  sorry to bother you with this but I solved the problem with reloadEFS().

                  I had a dumb mistake b4 while using reloadEFS().

                  thnx

                  Comment


                  • #10
                    plucky
                    You should not need to use reloadEFS(). Try passing a value (a color in your case) when using setBar() as in the example below
                    Alex

                    PHP Code:
                    function preMain() {
                        
                    setPriceStudy(true);
                        
                    setStudyTitle("SMA");
                        
                    setCursorLabelName("SMA");
                        
                    setDefaultBarThickness(2);
                    }

                    var 
                    bInit false;
                    var 
                    vAvg null;
                    var 
                    vColor null;

                    function 
                    main() {

                        if(
                    bInit==false){
                            
                    vAvg sma(10);
                            
                    vColor=Color.blue;
                            
                    setDefaultBarFgColor(vColor);
                            
                    bInit=true;
                        }

                        if(
                    close(0)>vAvg.getValue(0)) 
                            
                    setBarFgColor(Color.lime);

                        
                    setBar(Bar.FgColor,-10,0,vColor);

                        return 
                    vAvg.getValue(0);

                    Comment


                    • #11
                      Hi Alex,

                      Thank you for this but it does not work. If you try the code you supplied, you will see that it will paint the study 10 bars ago to blue. What I want is that the study should be invisible after 10 bars and the only way I could do it is to use relaodEFS() on a new bar. Do you have any other suggestions?

                      thanks again

                      Comment


                      • #12
                        plucky
                        I am not sure I understand what you mean with "invisible". I just used blue as an example but you can change it to whatever is the color of the chart background.
                        Regardless if what you are trying to do is plot only the last 10 data points of a study then one way to do this could be to mimic those last 10 data points of the plot by using drawLineRelative(). You would then return the study as a string which allows you to see the values in the Cursor Window even where there is no plot. I think this may be more efficient (and perhaps less dangerous) than using reloadEFS().
                        The script enclosed below provides an example of how to do what I just explained.
                        Alex

                        Edit after post: As per Steve Hare's suggestion I modified the drawLineRelative() command to be more efficient

                        PHP Code:
                        function preMain() {
                            
                        setPriceStudy(true);
                            
                        setStudyTitle("SMA");
                            
                        setCursorLabelName("SMA");
                        }

                        var 
                        bInit false;
                        var 
                        vAvg null;
                        var 
                        vCount 0;

                        function 
                        main() {

                            if(
                        getBarState()==BARSTATE_NEWBAR){
                                
                        vCount++;
                                if(
                        vCount>=10vCount=0;
                            }

                            if(
                        bInit==false){
                                
                        vAvg sma(10);
                                
                        bInit=true;
                            }

                            
                        drawLineRelative(-1,vAvg.getValue(-1),0,vAvg.getValue(0), PS_SOLID,2Color.blue"Line"+vCount);

                            return 
                        formatPriceNumber(vAvg.getValue(0));

                        Comment


                        • #13
                          that's very clever Alex... Thank you

                          Comment


                          • #14
                            plucky
                            Thanks and you are most welcome
                            Alex

                            Comment

                            Working...
                            X