Announcement

Collapse
No announcement yet.

Using value in drawTextRelative

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

  • Using value in drawTextRelative

    I'm trying to place the value (number) from a variable on a chart using the following:

    drawText(variablename, BelowBar1, Color.red);

    but instead of displaying the the value, which is a 3 digit number with a decimal point, it instead displayes on the chart:

    [object Series]

    including the brackets.

    I am running 7.9 so EFS2 works, but I've also tried drawTextRelative with the same results. Can anyone tell me the problem?

    Thanks

  • #2
    werosen
    See this post
    Alex

    Comment


    • #3
      I don't see how the post in your link applies. Could you please explain?

      Comment


      • #4
        werosen
        It applies in the sense that you need to use variablename.getValue(0) instead of variablename.
        If that does not resolve the issue post the code or a working example that reproduces the problem
        Alex

        Comment


        • #5
          OK,I get it now and it almost works. Itnow displays the value, but the value is rounded off instead of the actual value.

          Here's how I calculate the value.

          RussellBarClose = sma(1, sym("AB #F, 5s"));

          This returns the value 610.7 for the current bar.

          Here's how I display the value:

          drawTextRelative(0, BelowBar1, RussellBarClose.getValue(0), Color.white, Color.red, Text.PRESET | Text.CENTER, null, 10);

          But instead of displaying 610.7 on the chart, it displays 611.

          If I try to force the value to 2 digits with:

          RussellPrice = RussellBarClose.toFixed(1);

          and use this new variable name. then nothing will display on the chart.

          Comment


          • #6
            werosen
            Before using toFixed() run a null check on RussellBarClose.getValue(0)
            Alex

            Comment


            • #7
              It works

              Please disregard my last post. Your previous suggestion works perfectly, and I appreciate your assistance very much.

              Comment


              • #8
                Null Check

                How do you run a null check on RussellBarClose.getValue(0)?

                Comment


                • #9
                  werosen
                  if(RussellBarClose.getValue(0)==null) return;
                  Alex

                  Comment


                  • #10
                    Here is the code I used:

                    RussellBarClose = sma(1, sym("AB #F, 5s"));
                    if (RussellBarClose.getValue(0) == null) return;

                    var RussellPrice = RussellBarClose.toFixed(1);

                    drawTextRelative(0, BelowBar1, RussellPrice.getValue(0), Color.white, Color.red, Text.PRESET | Text.CENTER, null, 10);

                    But nothing displays on the chart. The value displays OK if I don't use .toFixed().

                    I don't know if it matters, but there is always a value for the var RusselBarClose.

                    Comment


                    • #11
                      werosen
                      You need to apply toFixed() only to the variable you are using in drawTextRelative(). See in the box below how you would do it.
                      When using toFixed() it converts values into strings which cannot be plotted on a chart. That is why your study no longer displays.
                      Alex

                      PHP Code:
                      var RussellBarClose sma(1sym("AB #F, 5s"));

                      if (
                      RussellBarClose.getValue(0) == null) return;

                      drawTextRelative(0BelowBar1RussellBarClose.getValue(0).toFixed(2), Color.whiteColor.redText.PRESET Text.CENTERnull10); 

                      Comment


                      • #12
                        Perfect. I never would have figured out that syntax.

                        Thanks again for all your help.

                        Comment

                        Working...
                        X