Announcement

Collapse
No announcement yet.

setChartBG Button

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

  • setChartBG Button

    Good morning guys!

    I am trying to place a button on a chart that will allow me to quickly change the chart background color but am having no luck. Thank you in advance.

    Charley

    PHP Code:
    var fpArray = new Array();

    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Chart BG");
        
    setShowCursorLabel(false);
        
    setShowTitleParameters(false);
        
    setDefaultChartBG(Color.black);
        
        var 
    x=0;
        
        
    fpArray[x] = new FunctionParameter("aColor"FunctionParameter.COLOR);
        
    with(fpArray[x++]){    
            
    setName("Button Color");
            
    setDefault(Color.grey);
        }
        
    fpArray[x] = new FunctionParameter("bColor"FunctionParameter.COLOR);
        
    with(fpArray[x++]){    
            
    setName("Chart Color");
            
    setDefault(Color.black);
        }
        
    fpArray[x] = new FunctionParameter("cColor"FunctionParameter.COLOR);
        
    with(fpArray[x++]){    
            
    setName("Chart Color");
            
    setDefault(Color.white);                                                                             
        }
    }
    function 
    main(aColorbColorcColor) {
        
            
    drawTextPixel(012"@URL=EFS:ChartBG"nullaColorText.RELATIVETOLEFT Text.RELATIVETOBOTTOMnullnull"Button"4016);
        
        
        function 
    ChartBG(nButtonPressed) {
            if (
    getButtonPressed(nButtonPressed) == 1) {
                
    setChartBG(cColor);
            }
            else if (
    getButtonPressed(nButtonPressed) == 2) {
                
    setChartBG(bColor);
            }
        }
    }
    function 
    getButtonPressed(nButtonPressed) {
        
        if (
    nButtonPressed == BUTTON_LEFT) {
            return(
    1);
        }
        else if 
            (
    nButtonPressed == BUTTON_RIGHT) {
            return(
    2);
        }


  • #2
    try:
    PHP Code:
    var fpArray = new Array(); 

    function 
    preMain() { 
        
    setPriceStudy(true); 
        
    setStudyTitle("Chart BG"); 
        
    setShowCursorLabel(false); 
        
    setShowTitleParameters(false); 
        
    setDefaultChartBG(Color.black); 
         
        var 
    x=0
         
        
    fpArray[x] = new FunctionParameter("aColor"FunctionParameter.COLOR); 
        
    with(fpArray[x++]){     
            
    setName("Button Color"); 
            
    setDefault(Color.grey); 
        } 
        
    fpArray[x] = new FunctionParameter("bColor"FunctionParameter.COLOR); 
        
    with(fpArray[x++]){     
            
    setName("Chart Color"); 
            
    setDefault(Color.black); 
        } 
        
    fpArray[x] = new FunctionParameter("cColor"FunctionParameter.COLOR); 
        
    with(fpArray[x++]){     
            
    setName("Chart Color"); 
            
    setDefault(Color.white);                                                                              
        } 

    var 
    Toggle=0;//global so the change is effected within main

    function main(aColorbColorcColor) { 
        
    drawTextPixel(012"@URL=EFS:ChartBG"nullaColorText.RELATIVETOLEFT Text.RELATIVETOBOTTOMnullnull"Button"4016); 
        if(
    Toggle==1){
            
    setChartBG(cColor); //setChartBG() is called from main(). 
                    
    Toggle=0;//just to keep setChartBg() from running on each tick
        
    }else if(Toggle==2){
            
    setChartBG(bColor);//setChartBG() is called from main(). 
                    
    Toggle=0;//just to keep setChartBg() from running on each tick
        
    }//NOTE: because the background color is changed in main() the change 
         //must wait until the next tick is processed before the change in color takes place.
         
         

    function 
    getButtonPressed(nButtonPressed) { 
         
        if (
    nButtonPressed == BUTTON_LEFT) { 
            return(
    1); 
        } 
        else if  
            (
    nButtonPressed == BUTTON_RIGHT) { 
            return(
    2); 
        } 
    }  
    function 
    ChartBG(nButtonPressed) { 
        if (
    getButtonPressed(nButtonPressed) == 1) { 
            
    Toggle=1;
        } 
        else if (
    getButtonPressed(nButtonPressed) == 2) { 
            
    Toggle=2;
        } 

    Wayne
    Last edited by waynecd; 11-21-2014, 11:59 AM.

    Comment


    • #3
      Thank you Wayne, I am definitely going to owe you a cold one one of these days.

      Comment


      • #4
        Glad it helped.

        Wayne

        Comment

        Working...
        X