Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

DrawText for a calculated value?

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

    DrawText for a calculated value?

    Hi, i would like to print a number on the chart just like i do with drawtext() but this number should be calculated, for example the current diffrence between two moving averages. but somehow i cant make it work since drawtext() requires a string so when i use something like

    "emaSeries[0]-ema2Series[0]" it will just print that rather than the value.
    Last edited by BigRo; 10-07-2015, 09:54 AM.

    #2
    Hello BigRo,

    Thank you for your inquiry.

    The reason why it is printing "emaSeries[0]-ema2Series[0]" is because you have wrapped this statement with quotation marks. As DrawText() accepts a string for this parameter, it is just going to output that exact string you have specified.

    If you wish to output a value, you will want to create a variable that will hold the value of emaSeries[0] - ema2Series[0] and use that variable with ToString() appended to it.

    Example:
    Code:
    double subtractedEMAs = emaSeries[0] - ema2Series[0];
    
    DrawText("tag", subtractedEMAs.ToString(), .....);
    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      ok, worked and is there a way to round this number because it has 10-15 decimals for example
      0.0008000000000005 or something.

      Comment


        #4
        i was tryin to multiply it by 10000 so i would get the pipvalue as real number by using int instead of double but that doesnt seem to work either.

        Comment


          #5
          ok got it.
          used


          double x = 1234.7;
          int a; // Cast double to int.
          a = (int)x;

          System.Console.WriteLine(a); } }
          // Output: 1234



          Comment


            #6
            Originally posted by BigRo View Post
            ok, worked and is there a way to round this number because it has 10-15 decimals for example
            0.0008000000000005 or something.
            Round2TickSize()?
            ref: http://ninjatrader.com/support/helpG...round2ticksize

            Comment


              #7
              Originally posted by NinjaTrader_ZacharyG View Post
              Hello BigRo,

              Thank you for your inquiry.

              The reason why it is printing "emaSeries[0]-ema2Series[0]" is because you have wrapped this statement with quotation marks. As DrawText() accepts a string for this parameter, it is just going to output that exact string you have specified.

              If you wish to output a value, you will want to create a variable that will hold the value of emaSeries[0] - ema2Series[0] and use that variable with ToString() appended to it.

              Example:
              Code:
              double subtractedEMAs = emaSeries[0] - ema2Series[0];
              
              DrawText("tag", subtractedEMAs.ToString(), .....);
              Please, let us know if we may be of further assistance.

              Dear ZacharyG,

              I tried to implement your idea into my Drawtext, but I get an error. Any idea what I am coding wrong?

              Comment


                #8
                Hello kadan,

                As a heads up, Zachary is no longer with NinjaTrader.

                Please expand the Error column so that we may read the full error message.

                What is the full line of code causing the error?

                From the screenshot it looks like there are too many parameters used in this overload of DrawText(). There are not any overloads that have string, string, bool.

                DrawText(string tag, bool autoScale, string text, int barsAgo, double y, int yPixelOffset, Color textColor, Font font, StringAlignment alignment, Color outlineColor, Color areaColor, int areaOpacity)



                Perhaps you are wanting the first string to be concatenated?

                "EMA 288 max avg. " + countad.ToString()

                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChelseaB View Post
                  Hello kadan,

                  As a heads up, Zachary is no longer with NinjaTrader.

                  Please expand the Error column so that we may read the full error message.

                  What is the full line of code causing the error?

                  From the screenshot it looks like there are too many parameters used in this overload of DrawText(). There are not any overloads that have string, string, bool.

                  DrawText(string tag, bool autoScale, string text, int barsAgo, double y, int yPixelOffset, Color textColor, Font font, StringAlignment alignment, Color outlineColor, Color areaColor, int areaOpacity)



                  Perhaps you are wanting the first string to be concatenated?

                  "EMA 288 max avg. " + countad.ToString()

                  Dear ChelseaB,

                  Concatenate has helped. Thank you very much for your help :-)

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by jaybedreamin, Today, 05:56 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post jaybedreamin  
                  Started by DJ888, 04-16-2024, 06:09 PM
                  6 responses
                  18 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by Jon17, Today, 04:33 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post Jon17
                  by Jon17
                   
                  Started by Javierw.ok, Today, 04:12 PM
                  0 responses
                  12 views
                  0 likes
                  Last Post Javierw.ok  
                  Started by timmbbo, Today, 08:59 AM
                  2 responses
                  13 views
                  0 likes
                  Last Post bltdavid  
                  Working...
                  X