Announcement

Collapse
No announcement yet.

VIX background color problem

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

  • VIX background color problem

    Hope everyone had a great holiday!

    I am trying to simply set the background color in a daily plot of the $VIX to red when the VIX is rising and green when falling. I am doing something wrong as the background color does not change at many of the peaks and troughs.

    Any help would be appreciated
    Thanks
    Shaeffer
    PHP Code:
    function preMain(){
        
    setPriceStudy(false);
        
    setStudyTitle("VIX-UD-BG");
        
    setShowCursorLabel(false);
        
    setShowTitleParametersfalse );
        
    setDefaultBarBgColorColor.black); 
        
        
    setDefaultBarFgColor(Color.RGB(204,153,255),0);  // Purple
        
    setPlotTypePLOTTYPE_LINE,0);
        
    setDefaultBarThickness(2,0);
        
    }
    var 
    xVIX  null;
    //var xVIXO  = null;
    var bInit false;

    function 
    main() {

    var 
    vVIX;
    var 
    vVIX1;

        if(
    bInit == false){
            
    xVIX   close(sym("$VIX"));
            
    //xVIXO  = open(sym("$VIX"));
            
    bInit  true;
        }
     
        
    vVIX   xVIX.getValue(0);
        
    //vVIXO  = xVIXO.getValue(0);
        
    vVIX1  xVIX.getValue(-1);

    //   Close to previous Close relationship       
        
    if (vVIX vVIX1){                // VIX rising (more fear)
            
    setBarBgColor(Color.maroon);  // market s/b falling
        
    }else if (vVIX vVIX1){            // VIX falling (less fear)
            
    setBarBgColor(Color.green);     // market s/b rising
        
    }else{
            
    setBarBgColor(Color.blue);
        } 

    return (
    vVIX);

    Attached Files
Working...
X