Announcement

Collapse
No announcement yet.

Globl Variables

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

  • Globl Variables

    Hi, I am sure this is something that is really basic but clearly i am missing something as an inexperienced EFS programmer.

    I can get a simple plot onto a chart, But i cannot get it to continue plotting setting the variable to be the same value each bar, until it changes.
    I wish it to continue drawing a line, not just a single plot on each occurance.

    I have attached some a simple code to illustrate my ignorance!
    If anyone can point out the reasons why their help would be much appreciated....thanks.

    //TEMPLATE

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("XXX");
    setCursorLabelName("upper", 0);

    setDefaultBarFgColor(Color.blue, 0);

    setDefaultBarThickness(4, 0);

    setPlotType(PLOTTYPE_FLATLINES, 0);

    }

    // Global Variables
    var xUpper = null;
    var bInit = false;
    debugClear

    function main() {

    //Initialise
    if(bInit == false) {

    bInit = true;
    }


    // Validate the study variables to ensure they contain valid data.
    if(close(0) == null || close(-1) == null || close(-4) == null || close(-5) == null) {
    return; // Exit the formula if variables contain invalid data.
    }

    if (close(0)>=close(-4) && close(-1)<=close(-5)) {
    var xUpper=close(-1);
    }

    debugPrintln(xUpper);
    return xUpper;

    }

  • #2
    Re: Globl Variables

    Adina
    Remove the var from the following line of code
    var xUpper=close(-1);
    which declares the variable xUpper as a local variable instead of a global variable as you have it initially declared.
    Once you make this change the formula should do what I think you are trying to accomplish (see enclosed screenshot)
    Alex




    Originally posted by Adina
    Hi, I am sure this is something that is really basic but clearly i am missing something as an inexperienced EFS programmer.

    I can get a simple plot onto a chart, But i cannot get it to continue plotting setting the variable to be the same value each bar, until it changes.
    I wish it to continue drawing a line, not just a single plot on each occurance.

    I have attached some a simple code to illustrate my ignorance!
    If anyone can point out the reasons why their help would be much appreciated....thanks.

    //TEMPLATE

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("XXX");
    setCursorLabelName("upper", 0);

    setDefaultBarFgColor(Color.blue, 0);

    setDefaultBarThickness(4, 0);

    setPlotType(PLOTTYPE_FLATLINES, 0);

    }

    // Global Variables
    var xUpper = null;
    var bInit = false;
    debugClear

    function main() {

    //Initialise
    if(bInit == false) {

    bInit = true;
    }


    // Validate the study variables to ensure they contain valid data.
    if(close(0) == null || close(-1) == null || close(-4) == null || close(-5) == null) {
    return; // Exit the formula if variables contain invalid data.
    }

    if (close(0)>=close(-4) && close(-1)<=close(-5)) {
    var xUpper=close(-1);
    }

    debugPrintln(xUpper);
    return xUpper;

    }

    Comment

    Working...
    X