Announcement

Collapse
No announcement yet.

using a counter

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

  • using a counter

    I would like to execute the code set out at the end and which is summarized below

    if (high(0) < high(-1)) {FlagB = high(“-count”)}
    // ie high(-1) high(-2) high(-3) etc

    until count ends

    if (high(0) < high(-1)) {start “count”}
    if (high(0) > high(-1)) {end “count”}

    then start the process again

    However I cant seem to link the count into the above -

    I have set out what I have done below

    could someone set out where I am going wrong

    The message I get is

    "Undefined function call"

    this refers to the very last line where I try to use the counter as a reference for which high(-x) to use in plotting the output


    Thanks


    function preMain() {

    setPriceStudy(true);
    setPlotType(PS_DASH,0);
    setCursorLabelName("FlagB", 0);
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarThickness(3, 0);


    var fp1 = new FunctionParameter("counter", FunctionParameter.NUMBER);
    fp1.setLowerLimit(1);
    fp1.setDefault(1);

    var FlagB = null;
    var counter = null;

    function main(counter) {


    if(high(0)<high(-1)) {counter=1}
    if(high(0)>high(-1)) {counter=0}

    if(high(0)<high(-1)) {FlagB = -counter}

    //debugClear();
    //debugPrintln('done');
    //debugPrintln('counter is ' +counter);

    for (var counter = (counter); counter < 100; counter++){
    if (counter == 100){
    break}
    if (counter == -100){
    break}

    }
    return(FlagB(-"counter"));
    }}

  • #2
    Re: using a counter

    RobertHere
    Here are some errors that I am seeing.
    One is that you did not properly close the preMain() function with the result that your main() function is enclosed in it
    Another is that in the return statement you are calling FlagB as a function but this has not been defined. Furthermore you are passing to it the string "counter" rather than a value as would be expected
    There may be other issues in your script [both in the construct and logic]. These are just the more obvious
    As you seem to be unfamiliar with programming in JavaScript/EFS you may find it to your benefit to review the JavaScript for EFS video series and the Core JavaScript Reference Guide. Those will provide you with a thorough introduction to programming in JavaScript which is at the foundation of EFS. Then go through the EFS KnowledgeBase and study the Help Guides and Tutorials which will provide you with the specifics of EFS.
    Lastly search the forums as the subject of counters has been covered at length and you should find several examples that will do what you want or similar
    Alex


    Originally posted by RobertHere
    I would like to execute the code set out at the end and which is summarized below

    if (high(0) < high(-1)) {FlagB = high(“-count”)}
    // ie high(-1) high(-2) high(-3) etc

    until count ends

    if (high(0) < high(-1)) {start “count”}
    if (high(0) > high(-1)) {end “count”}

    then start the process again

    However I cant seem to link the count into the above -

    I have set out what I have done below

    could someone set out where I am going wrong

    The message I get is

    "Undefined function call"

    this refers to the very last line where I try to use the counter as a reference for which high(-x) to use in plotting the output


    Thanks


    function preMain() {

    setPriceStudy(true);
    setPlotType(PS_DASH,0);
    setCursorLabelName("FlagB", 0);
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarThickness(3, 0);


    var fp1 = new FunctionParameter("counter", FunctionParameter.NUMBER);
    fp1.setLowerLimit(1);
    fp1.setDefault(1);

    var FlagB = null;
    var counter = null;

    function main(counter) {


    if(high(0)<high(-1)) {counter=1}
    if(high(0)>high(-1)) {counter=0}

    if(high(0)<high(-1)) {FlagB = -counter}

    //debugClear();
    //debugPrintln('done');
    //debugPrintln('counter is ' +counter);

    for (var counter = (counter); counter < 100; counter++){
    if (counter == 100){
    break}
    if (counter == -100){
    break}

    }
    return(FlagB(-"counter"));
    }}

    Comment

    Working...
    X