Announcement

Collapse
No announcement yet.

"+" doesn't add

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

  • "+" doesn't add

    Not sure where to go with this, posting here.
    I've been working on an .efs and for some reason the + has started to concatenate rather than add.
    snippet:

    var x;
    var y;
    var x1;
    var x7;

    x = close(-1);
    var y = study.getValue(MAStudy.MA);

    if (x > y) {
    x1 = y + 1;
    x7 = y + 7;
    }


    If y is equal to 981.666618
    then x1 will be 981.6666181
    and x7 will be 981.6666187.

    If I change the operation to "-" then it works ok.
    ideas?

    TIA

    Dale

  • #2
    Hi,

    Can you post the entire code? I suspect the part with the error isn't in what you posted.

    Garth
    Garth

    Comment


    • #3
      Sure gspiker,

      thanks for checking it out.



      var study = new MAStudy(34, 0, "Close", MAStudy.EXPONENTIAL);
      var studyHT = new MAStudy(12, 0, "High", MAStudy.EXPONENTIAL);
      var studyLT = new MAStudy(12, 0, "Low", MAStudy.EXPONENTIAL);
      var studyr = new PercentRStudy(34);

      function preMain() {
      setPriceStudy(true);
      }

      var bIsLong = false;
      var bIsShort = false;
      var bDebug = true;
      var strItem = "System Alert: " + getSymbol();
      var BarCntr = 0;
      var space = .5;

      function main() {
      if (getBarState() == BARSTATE_CURRENTBAR)
      return;

      BarCntr +=1;

      var ClosePrice = 0.00;
      var LowPrice = 0.00;
      var HighPrice = 0.00;
      var v = 0;
      var y = 0;
      var z = 0;
      var test1 = 0;
      var test2 = 0;

      if (getBarState() == BARSTATE_NEWBAR)
      {
      ClosePrice = close(-1,1);
      LowPrice = low(-1);
      HighPrice = high(-1);
      v = study.getValue(MAStudy.MA,-1,1);
      y = studyr.getValue(PercentRStudy.PERCENTR,-1,1);
      z = -1;
      }
      else
      {
      ClosePrice = close();
      LowPrice = low();
      HighPrice = high();
      v = study.getValue(MAStudy.MA);
      y = studyr.getValue(PercentRStudy.PERCENTR);
      z = 0;
      }

      if(v == null || y == null)
      return;

      Trace("#=" + BarCntr + " 34MA = " + v + " ClosePrice=" + ClosePrice + " %R=" + y + " bIsLong=" + bIsLong + " bIsShort=" + bIsShort );
      if(ClosePrice >= v) {
      test1 = v;
      test1 += 1;
      test2 = v;
      test2 += 7;
      Trace("ClosePrice >= v");
      if(!bIsLong) {
      Trace("!bIsLong v+1=" + test1 + " v+7=" + test2 + " y=" + y);
      if (ClosePrice >= test1 && ClosePrice <= test2 && y > -50) {
      Trace("Going Long: close()=" + ClosePrice);
      Alert.addToList(strItem, "Price is >= 34 Bar MA", Color.black, Color.green);
      Alert.playSound("swoosh.wav");
      drawShapeRelative(z, LowPrice - space, Shape.UPARROW, null, Color.lime, Image.ONTOP, "Buy" + BarCntr);
      drawTextRelative(z, LowPrice - (space * 2), "Buy", Color.black, Color.lime, Text.FRAME | Text.ONTOP | Text.BOLD, null, 9, "text buy" + BarCntr );
      bIsLong = true;
      bIsShort = false;
      }
      }
      } else {
      Trace("ClosePrice < v");
      if(!bIsShort) {
      Trace("!bIsShort");
      if (ClosePrice <= v-1.00 && ClosePrice >= v-7.00 && y < -50) {
      Trace("Going Short: close()=" + ClosePrice);
      Alert.addToList(strItem, "Price is < 34 Bar MA", Color.black, Color.red);
      Alert.playSound("train.wav");
      drawShapeRelative(z, HighPrice + space, Shape.DOWNARROW, null, Color.red, Image.ONTOP, "Sell" + BarCntr);
      drawTextRelative(z, HighPrice + (space * 2), "Sell", Color.black, Color.red, Text.FRAME | Text.BOTTOM | Text.BOLD, null, 9, "text sell" + BarCntr );
      bIsLong = false;
      bIsShort = true;
      }
      }
      }

      //return v;
      return;
      }

      function Trace(strText)
      {
      if (bDebug) {
      debugPrint(strText + "\n");
      }
      }

      Comment


      • #4
        Hello Dale,

        I agree with Garth, the code you've posted shouldn't be treating y as a string. At any rate, one solution would be to use eval(y) in your statements for x1 and x7.

        PHP Code:
        if (y) {
            
        x1 = eval(y) + 1;
            
        x7 = eval(y) + 7;

        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment


        • #5
          Hello Dale,

          In this case, when you set v using: v = study.getValue(MAStudy.MA,-1,1);, v becomes an array with a size of 1. All you need to do is reference v as an array element.

          PHP Code:
          if(ClosePrice >= v) {
              
          test1 v[0];
              
          test1 += 1;
              
          test2 v[0];
              
          test2 += 7
          Jason K.
          Project Manager
          eSignal - an Interactive Data company

          EFS KnowledgeBase
          JavaScript for EFS Video Series
          EFS Beginner Tutorial Series
          EFS Glossary
          Custom EFS Development Policy

          New User Orientation

          Comment


          • #6
            Thanks Jason.
            That fixed it.
            Still don't quite understand it...I had an earlier version (much simpler) and the math was working OK.

            Comment

            Working...
            X