Announcement

Collapse
No announcement yet.

How do I add 1 or 2 to a global variable?

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

  • How do I add 1 or 2 to a global variable?

    hello,

    In EFS how do I add the number 1 or 2 to a global variable?

    Here is the code I'm using:

    // Declaring Global Variables
    var EntryBarNo=0;
    var BarsSinceEntry=0;

    function main() {

    BarsSinceEntry = getCurrentBarCount() - EntryBarNo + 1 ;

    return null;

    }

    EntryBarNo is the bar number recorded at the exact time of order entry.

    Also, a second question is: Is it ok when declaring global variables to set them to 0 so that when the program first starts it assigns a value of zero to the variable. Is this ok?

    If you could please let me know what I am doing wrong that would be very much appreciated.

    Thanks in advance.

    Regards

    Rod

  • #2
    regarding my previous question, to add 1 to a variable i used this:

    Var1 = 1 + Close(0);

    and this worked.

    however, Var1 = Close(0) + 1; does not work.

    my question is: Is the first way of doing it stable? or can doing it this way cause problems?

    thanks in advance.

    regards

    Rod

    Comment


    • #3
      Rod

      Var1 = 1 + Close(0);
      and this worked.
      however, Var1 = Close(0) + 1; does not work.
      FWIW both methods will work and return the same result (see enclosed screenshot)
      Alex




      Originally posted by Rocket130713
      regarding my previous question, to add 1 to a variable i used this:

      Var1 = 1 + Close(0);

      and this worked.

      however, Var1 = Close(0) + 1; does not work.

      my question is: Is the first way of doing it stable? or can doing it this way cause problems?

      thanks in advance.

      regards

      Rod

      Comment

      Working...
      X