Announcement

Collapse
No announcement yet.

getChartBG()

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

  • getChartBG()

    I'm trying to use the utility function getChartBG(), but I can't get anything useful from it. Here's the sample code:

    function preMain() {
    setPriceStudy(true);
    setDefaultBarBgColor(Color.blue, 0);
    }

    function main() {
    var BackGroundColor = getChartBG();
    return BackGroundColor.toString(16);
    }

    It returns a value of ffffff. When I change the color from blue to red or anything else, it still returns that same value of ffffff.

    When I try to test it using an if statement like this:

    if (BackGroundColor = Color.red) return;

    it returns true even though the background color is blue.

    Can someone help?

  • #2
    dcook
    The getChartBG() function returns the background color of the chart as set by the Properties of the chart or by the setChartBG() function and not the background color of the bar.
    Enclosed below is an example of its usage
    Alex

    PHP Code:
    function main(){
     
        var 
    study sma(10);
        
        if(
    close(0)>study.getValue(0)){
            
    setChartBG(Color.lime);
        }else{
            
    setChartBG(Color.yellow);
        }
        
        if(
    getChartBG()==Color.lime){
            
    debugPrintln("Chart is lime");
        }else if(
    getChartBG()==Color.RGB(255,255,0)){//RGB color for yellow
            
    debugPrintln("Chart is yellow");
        }
        
        return 
    study.getValue(0)

    Originally posted by dcook
    I'm trying to use the utility function getChartBG(), but I can't get anything useful from it. Here's the sample code:

    function preMain() {
    setPriceStudy(true);
    setDefaultBarBgColor(Color.blue, 0);
    }

    function main() {
    var BackGroundColor = getChartBG();
    return BackGroundColor.toString(16);
    }

    It returns a value of ffffff. When I change the color from blue to red or anything else, it still returns that same value of ffffff.

    When I try to test it using an if statement like this:

    if (BackGroundColor = Color.red) return;

    it returns true even though the background color is blue.

    Can someone help?

    Comment


    • #3
      Thanks. That helps. Now here's something else I'm trying to do along those same lines. I want to be able to backtest eMini-Master.com. When applying POLR_1.efs, POLR_2.efs, POLR_3.efs, and POLR_Combo.efs, they all open separate panes below the price chart and output either blue (which means bullish) or red (which means bearish). I want to be able to read back whether the color is blue or red and backtest. This is the sort of thing I'm trying to do, but it doesn't work:

      var POLR3Call = null;
      var bInit = false;

      function main() {
      if (bInit == false) {
      POLR3Call = efsExternal("Advanced/eMini-Master.com/POLR_3.efs");
      bInit = true;
      }

      var POLR3Color = getChartBG(POLR3Call); //this doesn't work, but you can understand what I'm trying to do
      if(POLR3Color==Color.blue){
      debugPrintln("POLR_3 is blue");
      }else if(POLR3Color==Color.red){
      debugPrintln("POLR_3 is red");
      }
      return POLR3Color.toString(16); //this just returns ffffff
      }

      Comment


      • #4
        dcook
        I don't subscribe to those studies so I can't verify what they are actually returning. Regardless here are some things you need to consider
        - The getChartBG() function has no parameters so getChartBG(POLR3Call) is not a valid usage
        - As I already explained in my previous reply getChartBG() will only return the background color of the chart as set by either the Properties of the chart or the setChartBG() function.
        - The efsExternal() function can only return values that are numbers. Unless the scripts you are calling are returning the colors as numbers you will not be able to retrieve them with that function. If they are returned as strings you could try using either call() or callFunction()
        - From what you describe those scripts are painting the background of the indicator pane(s). If this is the case then they are doing that using the setBarBgColor() function and may not be returning anything at all.
        As it is not clear what the studies are returning and these are encrypted you need to contact the developers of those studies for assistance.
        Alex

        Comment

        Working...
        X