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

value to string

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

    value to string

    Hello,

    I need to store doubles to string and the string name can be/should be "name+currentbar" so that I can use it whenever the condition is met, without working with a list.
    How can I resolve this please and how can I plot then a line at y-value from this string please?

    (now I plot the line from the doubles, I defined 10 variables for this purpose to store values from calculations and once all 10 are used I start again....and I can plot the lines from this, but I dont know now how to plot the lines "forever" from the string.

    Couldn´t get it from the samplestringfunctions.

    Thank you!
    Tony
    Last edited by tonynt; 10-19-2021, 06:25 AM.

    #2
    Hello tonynt,

    Thanks for your post.

    Sorry, but I am not sure what problem you are trying to overcome.

    If I understand correctly, you are already able to use a double type as a string for use as a tagname?

    If so then can you clarify what you actually need?

    Just to show you that you can add a double variable to a tag name, below is a screenshot that shows a Draw.Line() where I have constructed a tag name based on the string "Test" with the +CurrentBar and with +Close[0].ToString() (as a means to test a double value that is added to the tagname). On the chart, the indicator has drawn 3 lines. In the Drawing Objects window, I have selected one of the lines and you can see the field "Tag" that shows the tag name of the line is "Test357082.23" where 3570 is the current bar number and 82.23 is the price at the time of the bar close.

    Click image for larger version

Name:	TonyNT-11.PNG
Views:	82
Size:	88.0 KB
ID:	1175413
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      thank you for your reply!

      This will help me but I do not understand to get the 2nd part of my question with using the y-value of the line from a string. You have here the Low[0] in the code, this I understand and used already. But I dont understand how I can get the y-value instead of the Low[0] from one of my doubles as "fixed" string instead of Low[0], so that when its plotted it will not change anymore, because this double will be filled with another value from calculations later in time (all my doubles are calculated with new data during the day), so I thought the solution is when I assign the "current" double value to a string then this will not be updated later.

      Draw.Line(this,"upx1xDu" + CurrentBar, false, currentBars1-slopeleg2, upx1xD.ToString(), 0, upx1xD.ToString(), Brushes.Red, DashStyleHelper.Solid, Dwidth);}
      // gives me an error for upx1xD.ToString()

      Thank you!
      Tony
      Last edited by tonynt; 10-19-2021, 10:26 AM. Reason: add info

      Comment


        #4
        Hello Tony,

        The price and Y value are the same thing on a price chart.

        Sorry, I may not be understanding your question, but to answer your Ninjascript based question of a tag name you can see that by using .ToString() you can convert any numeric value to a string that can be a part of the tag name, if you wish. So if you have a double type variable named "exampleDouble" you can convert to text with exampleDouble.ToString();

        Reference: https://ninjatrader.com/support/help...ng_numbers.htm

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hello,

          thank you again for your reply. I posted above that this is what I´m trying to do with "...upx1xD.ToString()..."; but when compiling I get the error message "conversion from string to double is not possible" (my translation as it shows the message in german language).

          Why does it give me the error message for my "Draw.Line(this,"upx1xDu" + CurrentBar, false, currentBars1-slopeleg2, upx1xD.ToString(), 0, upx1xD.ToString(), Brushes.Red, DashStyleHelper.Solid, Dwidth);}

          My upx1xD.ToString() is like your snippet with exampleDouble.ToString();

          I have no compiling error with
          "Draw.Line(this,"upx1xDu" + CurrentBar, false, currentBars1-slopeleg2, upx1xD, 0, upx1xD, Brushes.Red, DashStyleHelper.Solid, Dwidth);}

          ??

          Thank you!
          Tony

          Last edited by tonynt; 10-19-2021, 10:44 AM. Reason: translation error

          Comment


            #6
            Hello tonynt,

            Thanks for your reply.

            "I have no compiling error with "Draw.Line(this,"upx1xDu" + CurrentBar, false, currentBars1-slopeleg2, upx1xD, 0, upx1xD, Brushes.Red, DashStyleHelper.Solid, Dwidth);}" I would not expect any error there either as you are creating a string of text and adding currentbar to it. That string of text is not the same as the double variable named upx1xDu.

            Here is a simple example, please replicate this on your end and advise if you have the same difficulty or if compiles and performs as mine did.

            Click image for larger version

Name:	Tonynt-12.PNG
Views:	55
Size:	98.2 KB
ID:	1175480
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hello,

              thank you again for your reply. I do not understand what you mean, sorry. Maybe my english.

              Yes, I understand this but in your Draw.Line code you have Low[0] as y-value. With this it works also on my end.

              This question is not about the string/tag/name. Its about the y-value
              My 2nd qustion from the beginning is how I can have the y-value as a string from a double (from a variable).

              Sorry for causing misunderstanding from explaining with my english.

              Thank you!
              Tony

              Comment


                #8
                Hello tonynt,

                Thanks for your reply.

                I have been answering based on trying to show you how to use .ToString() to convert a double value to a Text value for use in the Tag name. In the example that I showed in the previous post, please look closely at the code as I showed creating a double variable using your variable name and assigning it a double value and then using that variable in the Tag name.

                I can take that very same double variable and replace the Low[10] in both places in my example and it will compile. It would look like this:

                Draw.Line(this, "Test"+CurrentBar+upx1xDu.ToString(), 10, upx1xDu, 0, upx1xDu, Brushes.Red);

                The above shows using a double variable called upx1xDu in the tagname and in the y-axis values of the Draw.Line statement. When used as a double, you do not use the .ToString().



                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Hello,

                  thank you for your reply. I dont know whats causing the misunderstanding, probably my english. I tried to explain what my question is in the last post but it is neglected. so I assume I didnt translate and describe correctly. Sorry. I try again:
                  no question about tagname, this is clear now.
                  no question about using a double/variable for y-value, this is clear (as I work with for years with doubles from calculations)
                  no question about your example of Draw.Line, this is clear and the y-value there is from my post and I use doubles/variables for y-value

                  The only question - I tried do ask in last post - is how to assign a double to a string (maybe this is wrong translation from me, I mean to "fill" a string with the value of a double) and use that string in Draw.Line as y-value (and not using the double itself as y-value). The purpose is that this y-value is "fixed" as a number and not a double and so the line plotting is fixed and will not change later when the double is filled with a new value. I want to substitute the variable upx1xDu in the example above with a string built from this double. The y-value in a Draw.Object, here the Draw.Line, should be from a string and not a variable double. JJCale sings(sang) "if I´d had a 100 Dollars I´d buy myself a gun". This is what I have to do when now I could not describe it.

                  Thank you!
                  Tony
                  Last edited by tonynt; 10-20-2021, 01:13 AM. Reason: translation error

                  Comment


                    #10
                    Hello tonynt,

                    Thanks for your reply and patience to explain.

                    Example to create a string variable from a double: string myString = upx1xDu.ToString();

                    Note you cannot use a string variable for the Y-axis in the Draw methods, the y-axis parameter needs to be a numerical value and not a string.

                    There are C# methods you can use to convert a string to a double but these are not a ninjascript question so you should check other internet sources for "C# how to convert string to double."

                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello Paul,

                      thank you for your reply. OK, so I understand now why there was the error message when compiling I was asking for.

                      And I do already in my codes work with my string = x.ToSTring(); but in this case it is not a good solution as I described above as this occurs again and again and so I would have to define all my strings declaritive (my translation).

                      As I described I "simply" need to plot the line at a certain y-value that is a double as result from calculations (it was my idea as a workaround to resolve with string). How can I plot a line with the "value" of a double/variable so that the line is not updated when this double/variable is filled with a new value later/another day/... The double upx1xDu mgiht be 4510.75 today and I want to plot the line ("LineToday") with this. In maybe 5 days the double upx1xDu (which is one of 10 I´m using) is maybe 4525.50 and then another line should be plotted with this value. Now the "LineToday" will be also plotted with the new value 4525.50 once the double has a new value.

                      Thank you!
                      Tony

                      Comment


                        #12
                        Hello tonynt,

                        Thanks for your reply.

                        "How can I plot a line with the "value" of a double/variable so that the line is not updated when this double/variable is filled with a new value later/another day/... The double upx1xDu mgiht be 4510.75 today and I want to plot the line ("LineToday") with this. In maybe 5 days the double upx1xDu (which is one of 10 I´m using) is maybe 4525.50 and then another line should be plotted with this value. Now the "LineToday" will be also plotted with the new value 4525.50 once the double has a new value."

                        I understand the question.

                        This goes back to understanding that a line drawn will not be changed unless you use the same tag name. So once a line is drawn with a unique tag name it would not be changed or updated. If you look at the example in Post #2 I am using the Low[0] value which can and usually does change on every bar. There is more than one line drawn using the variable yet the lines are using different values because they used the value of the variable at that time of the bar close and by using a unique tag name each line is drawn once and remains at the y-axis it was drawn at.

                        If this does not answer your question, please consider providing a simplified working example that demonstrates the issue that I can clarify for you. It should be reduced to about the size of the example in post #2 and all other code removed that is not part of the focused demonstration.

                        Paul H.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Halmix, Today, 07:12 AM
                        0 responses
                        11 views
                        0 likes
                        Last Post Halmix
                        by Halmix
                         
                        Started by Bobin, Today, 06:39 AM
                        0 responses
                        13 views
                        0 likes
                        Last Post Bobin
                        by Bobin
                         
                        Started by KirkHammett, Today, 03:23 AM
                        0 responses
                        6 views
                        0 likes
                        Last Post KirkHammett  
                        Started by eleven, Yesterday, 10:06 PM
                        0 responses
                        40 views
                        0 likes
                        Last Post eleven
                        by eleven
                         
                        Started by ezrollin, Yesterday, 08:12 PM
                        7 responses
                        75 views
                        0 likes
                        Last Post bltdavid  
                        Working...
                        X