Announcement

Collapse
No announcement yet.

Changing background colour based on time of the day

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

  • Changing background colour based on time of the day

    So I have this script that changes the background colour of the chart if the time falls within the RTH.

    Code:
    START_T = 1430;
    END_T = 2100;
    
    function preMain() 
    {
    	setComputeOnClose(true);
    	setPriceStudy(true);
    	setStudyTitle("BGColourT");
    	setCursorLabelName("BGColourT");
    	setShowTitleParameters(false);
    	
    	var fp1 = new FunctionParameter("colour1", FunctionParameter.COLOR);
    	fp1.setDefault(Color.RGB(225, 225, 225));
    
    	var fp2 = new FunctionParameter("colour2", FunctionParameter.COLOR);
    	fp2.setDefault(Color.RGB(192, 192, 192));
    }
    
    function main(colour1, colour2) 
    {
    	var vHour = getHour(0);
    	var vMin = getMinute(0);
    	
    	vHour = vHour.toString();
    	vMin = vMin.toString();		
    
    	if (vHour < 10)
    		vHour = "0" + vHour;
    	if (vMin < 10)
    		vMin = "0" + vMin;
    	
    	var vTime = vHour + vMin;
    
    	if (vTime >= START_T && vTime <= END_T)
    		setBarBgColor(colour2);
    	else
    		setBarBgColor(colour1);
    	return;
    }

    It works fine except that it colours the background only up to the current bar. I'd like the colouring to be done for the entire period, so the border should be where the red line is. What am I doing wrong?

    Thanks.

    PS. The times are London times.
    Click image for larger version

Name:	NQ.png
Views:	1
Size:	60.0 KB
ID:	246877

  • #2
    Please could someone from eSignal help? Thanks.

    Comment


    • #3
      OK, I think the only solution is to set the default background colour to colour2, so the space to the right takes the same colour as the RTH.
      Last edited by bf2; 04-09-2013, 11:56 AM.

      Comment


      • #4
        "setBarBgColor();" is tied to one of the return indexes in main() so it will only color the background for existing return indexes or the default of return index 0.
        The default is for return index of 0 (you don't need to have a return statement in the function for setBarBgColor(Color.red) to work.
        But if you use a return index of 1 for setBarBgColor() in an efs that has only one or no return value then the background color won't be changed.

        That is why it won't color the background after the last bar on the chart.

        For example,
        in the following script uncomment one test section at a time as it runs in a chart.
        PHP Code:
        function preMain(){
            
        setPriceStudy(true);
        }

        function 
        main(colour1colour2){
            
        //uncomment below TO test
            //if ( isLastBarOnChart()) setBarBgColor(Color.red);//draws ok
        //-----next test----------//
            //if ( isLastBarOnChart()) setBarBgColor(Color.red);//draws ok
            //return;
        //-----next test----------//
            //if ( isLastBarOnChart()) setBarBgColor(Color.red,0);//draws ok
            //return;
        //-----next test----------//
            //if ( isLastBarOnChart()) setBarBgColor(Color.red,1);//draws ok
            //return new Array("","");
        //-----next test----------//
            
        if ( isLastBarOnChart()) setBarBgColor(Color.red,1);//DOESN'T DRAW
            
        return "";

        Wayne
        Last edited by waynecd; 05-14-2013, 02:30 PM.

        Comment

        Working...
        X