Announcement

Collapse
No announcement yet.

Using Indexes

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

  • Using Indexes

    I have the following code running in a real-time script.

    var v1 = getValue("close",0,1,"$ADV");
    var v2 = getValue("close",0,1,"$DECL");
    var v3 = getValue("close",0,1,"$UCHG");
    debugPrintln(v1+" "+v2+" "+v3);
    var x2 = (v1 - v2);
    var x1 = (v1 + v2 + v3);
    debugPrintln(x2+" "+x1);

    The first debug line prints: 692 2159 90
    The second debug prints: -1467 692215990

    Why do I get the correct answer for x2 but not for x1? Do the indexes return text values?

    Thanks.

  • #2
    because Java Script is interpreting the values as strings.

    Try multiplying the variables * 1 to convert them to numbers.

    B
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Thanks, Brad.

      Originally posted by Doji3333
      because Java Script is interpreting the values as strings.

      Try multiplying the variables * 1 to convert them to numbers.

      B

      Comment

      Working...
      X