Announcement

Collapse
No announcement yet.

Problem changing background color

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

  • Problem changing background color

    I am having trouble changing the background bar color when the current bar is the first bar of a new day. It works fine for all previous days, but the background color of the current day doesn't change until the second bar. Is there some kind of DrawBarBgColor function that I am missing?

    Dale Sullivan


    PHP Code:

    /**************************************************
    Created by Dale Sullivan  October 2003

    This program shows where a day starts and ends.  I find
    that this is especially useful on 60 minute charts.
    ***************************************************/

    var vTempColor;
    var 
    vBgColor1;
    var 
    vBgColor2;

    function 
    preMain() {

        
    setComputeOnClose(true);
        
    setPriceStudy(true);
        
    setStudyTitle("NewDay");
        
    setCursorLabelName("NewDay");

        var 
    fp1 = new FunctionParameter("v1stBgColor"FunctionParameter.COLOR);
            
    fp1.setDefault(Color.white);   // First color = white

        
    var fp2 = new FunctionParameter("v2ndBgColor"FunctionParameter.COLOR);
            
    fp2.setDefault(Color.RGB(0xE80xE80xE8));   //Second color = very light grey

    }

    function 
    main(v1stBgColorv2ndBgColor) {
        if(
    vBgColor1 == null)
            
    vBgColor1 v1stBgColor;
        if(
    vBgColor2 == null)
            
    vBgColor2 v2ndBgColor;

        var 
    vThisBarDate getDay(); 
        var 
    vPreviousBarDate getDay(-1);

        if(
    vThisBarDate != vPreviousBarDate){
                    
    //Swap colors
                
    vTempColor vBgColor1;
                
    vBgColor1 vBgColor2;
                
    vBgColor2 vTempColor;
        }
            
    setBarBgColor(vBgColor1);

    Attached Files

  • #2
    Hello Dale,

    Your formula is actually working properly. The background coloring does not center on the bars. It colors from the center of the current bar to the center of the next bar. In the image below, the cursor is on the 6:30 bar for 1/9, which is the first bar for today and has a white background.


    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
      Hello Dale,

      A very kind gentleman, and a wise one at that I must say, just came to me and suggested I try your formula in replay mode. I now see the problem you're having with this formula in real time. I made a few modifications to your formula. It should work properly for you now. Try the attached.
      Attached Files
      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


      • #4
        Hi Jason,

        Thanks for the help. And thanks also to the very kind and wise gentleman.

        After I studied your changes to my formula I was able to see where I went wrong. After I removed the setComputeOnClose(true) statement, the rest was pretty obvious. I just had to change the new day comparison so the color change only happens once on the first bar of a new day.

        That was also an interesting method you used to swap the colors.

        Thanks again.

        Dale

        Comment

        Working...
        X