Announcement

Collapse
No announcement yet.

Syntax dealing with data type problem

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

  • Syntax dealing with data type problem

    Hi Folks,
    I've a question dealing with data types that i'm sure i'm just missing the obvious on but..... declaring a value and occasionaly giving it a new value and then adding a numeric value to it results in a string for some reason ie.

    var gOldvVMA = null;
    var vVMA = null;
    var vMA = null;
    var gPM = 10000;

    function main() {

    if (vMA == null) vMA = new MAStudy(5, 0, "Close", MAStudy.SIMPLE);

    vVMA = call( "AnVolume.efs" ); // returns MA based on Volume

    if(gOldvVMA == null) gOldvVMA = vVMA;
    if(Strategy.isLong() && vVMA > gOldvVMA) gOldvVMA = vVMA;
    if(Strategy.isShort() && vVMA < gOldvVMA) gOldvVMA = vVMA;

    if(vMA.getValue(MAStudy.MA)>vMA.getValue(MAStudy.M A,-1)){
    if(vVMA > gOldvVMA+10/gPM){
    debugPrintln("Values : " + vMA.getValue(MAStudy.MA) + " " + vMA.getValue(MAStudy.MA,-1) + " " + vVMA + " " + gOldvVMA + " " + gOldvVMA+(10/gPM));
    }
    }
    }

    the above switch does not get met but returns

    Form Output Window
    Values : 1.308719 1.3087 1.3074 1.3074 1.3074.001 <- last number is the one in question.

    Last number is a string of the two numbers added together whereas I actually need the value of the two numbers added together (ie 1.3084). Any ideas or solutions would be greatly appreciated.

    Thanks..
    Chris

  • #2
    Chris
    Those values are being concatenated rather than being added because they are strings. You need to convert back to a number the value you want to add . To do that multiply the string value by 1
    Alex

    Comment


    • #3
      Hi Alex.... thanks for responding so quickly , I thought that would do the trick but no luck, perhaps i'm missiing something. I simplified it down a bit and tried it... you can see that i am multiplying by 1

      var gOldvVMA = null;
      var vVMA = null;
      var gPM = 10000;

      function main() {

      var vVMAtmp = call( "AnVolume.efs" ); // returns Volume MA

      vVMA = rnd(vVMAtmp,4)*1;

      drawTextAbsolute(75, 540, "vVMA = " + vVMA + " vVMA add .0010 = " + vVMA+10/gPM, Color.green, null, txtFlags, null, 14, "notradehl");
      }


      the above prints

      vVMA = 1.2967 vVMA add .001 = 1.29670.001 <- still concatenating

      Any thoughts ?
      Chris

      Comment


      • #4
        Chris
        Where you multiplied by 1 is not where the value gets converted to a string. That happens inside your debug statement which is where you need to convert the string back to a value
        Alex

        Comment


        • #5
          Hello Chris,

          Another solution is to put the math calculation inside parentheses. This will force the expression to the result of the calculation before the string concatenation occurs. Try the following:

          drawTextAbsolute(75, 540, "vVMA = " + vVMA + " vVMA add .0010 = " + (vVMA+10/gPM), Color.green, null, txtFlags, null, 14, "notradehl");
          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
            You guys are the best.... thanks !!!!!

            Chris

            Comment

            Working...
            X