setBar()

ICE Data Services -

setBar()

 

setBar( TYPE (Value | Color | Style | Thickness), BarOffset, SeriesIndex, Value )

 

setBar( TYPE (Value | Color | Style | Thickness), BarOffset, Value | ArrayOfValues )

 

  • Type:  The specific property that you want to modify. See Valid Types below:
  • BarOffset: The offset back to the bar you wish to modify.
  • SeriesIndex: (Optional). Specify the specific return value that you wish to modify.
  • Value: The new value.

 

Valid Types

 

Bar.Value

Bar.Style

Bar.FgColor

Bar.BgColor

Bar.Thickness

 

This function allows you to adjust the value and/or the properties of a prior bar of a study being displayed. For example, if you are calculating and displaying 2 moving average studies in your script, you could use the setBar() function to change the actual value, color, line style or thickness of a previously-displayed value from either one of the studies or even both of the studies.

 

Example:

//The example below shows how the setBar() function can be used to change

//the value, color and bar thickness of previously displayed values of two moving

//averages.

//Define the two Moving Average studies that we will display in our chart

var study1 = new MAStudy(5, 0, "Close", MAStudy.EXPONENTIAL);

var study2 = new MAStudy(25, 0, "Close", MAStudy.EXPONENTIAL);

function main(frPeriod) {
  var nMA1;

  var nMA2; //retrieve the MA values for the current bar

  nMA1 = study1.getValue(MAStudy.MA);

  nMA2 = study2.getValue(MAStudy.MA); //if the FastMA minus the SlowMA is greater than 10 points, we will use the setBar() //function to modify previously displayed values of both moving averages. Once this //change takes place, your Advanced Chart will update your display to reflect these //changes.

  if (nMA1 - nMA2 > 10) {
    //set the value 5 bars ago of the FastMA to 10.75

    //set the value 5 bars ago of the SlowMA to 9.95

    setBar(Bar.Value, -5, new Array(10.75, 9.95)); //set the color of the FastMA 5 bars ago to black //set the color of the SlowMA 5 bars ago to yellow

    setBar(Bar.FgColor, -5, new Array(Color.black, Color.yellow)); //set the bar thickness of the FastMA 5 bars ago to 2 //set the bar thickness of the SlowMA 5 bars ago to 3

    setBar(Bar.Thickness, -5, new Array(2, 3));
  } //return the current MA values to be displayed

  return new Array(nMA1, nMA2);
}

 

Other Examples:

//set the value of the prior bar of the first study you are returning
//from your script to 22.

setBar(Bar.Value, -1, 22);

//set the value of the prior bar of the 4th study you are returning
//from your script to 25.

setBar(Bar.Value, -1, 3, 25);

//set the line style of the third study returned from your script to PS_SOLID (3 bars ago)

setBar(Bar.Style, -3, 2, PS_SOLID);

//Assume your script is returning 3 values to be plotted. The following code will change
//the backround color of each study (at a point 10 bars ago) to blue, green and yellow respectively.

setBar(Bar.BgColor, -10, new Array(Color.blue, Color.green, Color.yellow));