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

Draw Text / private int / private string - question

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

    Draw Text / private int / private string - question

    I put together a simple indicator that draws the LinReg lines from up to 5 different time frames into any chart. The 5 timeframes can be freely chosen in the indicator menu.
    I then added a label to each line on the chart using a private string. The attached image shows my indicator menu, a chart and parts of the code to give an idea.

    Currently, if I change a timeframe I also need to change the corresponding label/private string. This is how the DrawText code line looks like:

    private int timeframea = 60;
    ...
    private string labela = "60";

    DrawText("atagup", true, labela, rightend, (LinReg(BarsArray[1],9))[0], 0, riseclr, new Font ("Arial", labelsize, FontStyle.Bold),StringAlignment.Near, Color.Empty, Color.Empty, 0);

    Rather than having to type twice each the time frame and then the label separately,
    is there perhaps a simpler way so that it accept the chosen timeframe also as the label?

    sandman
    Attached Files

    #2
    Hello sandman,

    Thanks for your post.

    If you are looking to create strings for your tags that are consistent with the a specific data series that is added to the NinjaScript, I may suggest then to create tags using ToString() on Bars properties in BarArray.

    For example: BarsArray[0].Period on 1 minute bars will equate to "1 Min" and on 2 second bars will equate to "2 seconds." These values could also be combined with the BarsArray's Instrument name as well. "BarsArray[0].Instrument.FullName"

    Intellisense can be used to identity available properties which you could use to create tags based on BarsArray and Bars objects.

    Intellisense - https://ninjatrader.com/support/help...tellisense.htm

    Please let us know if there is anything else we can do to help.
    JimNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Hello sandman,
      If you are looking to create strings for your tags that are consistent with the a specific data series that is added to the NinjaScript, I may suggest then to create tags using ToString() on Bars properties in BarArray.
      Jim.
      Yes, that sounds like what I am looking for. Where do I find more data on how to put this together? Samples? I tried HELP, searching for ToString() but that doesn't list anything.

      sandman

      Comment


        #4
        Hello sandman,

        I'm not sure a sample would be needed in this context. ToString() will return a string that can be used in place of labela in your example.

        You may add a print to observe what the string is so you may further develop your code.

        Print(BarsArray[0].Period.ToString());

        The main page of the Drawing Tools documentation shows how a unique string can be created with CurrentBar and used as the drawing tag. A similar approach would be taken to pass another string as a the tag parameter. For example:
        • DrawDot(CurrentBar.ToString() + "Buy", 0, High[0] + TickSize, Color.ForestGreen)
        • DrawDot(BarsArray[0].Period.ToString() + "Buy", 0, High[0] + TickSize, Color.ForestGreen)
        • DrawDot(BarsArray[0].Period.ToString(), 0, High[0] + TickSize, Color.ForestGreen)


        DrawingTools - https://ninjatrader.com/support/help...t7/drawing.htm

        Please let us know if you need further assistance.
        JimNinjaTrader Customer Service

        Comment


          #5
          Thanks. I can't help but say what someone else already expressed: the samples in the NT Help section are extremely minimalistic - especially for non-programmers like myself.

          After several trials I found the simple answer to my original question:

          Simply replace labela with BarsArray[1].Period.ToString().
          etc.

          sandman

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by michi08, 10-05-2018, 09:31 AM
          4 responses
          740 views
          0 likes
          Last Post Denver_Wayne  
          Started by sightcareclickhere, Today, 01:55 PM
          0 responses
          1 view
          0 likes
          Last Post sightcareclickhere  
          Started by Mindset, 05-06-2023, 09:03 PM
          9 responses
          258 views
          0 likes
          Last Post ender_wiggum  
          Started by Mizzouman1, Today, 07:35 AM
          4 responses
          18 views
          0 likes
          Last Post Mizzouman1  
          Started by philmg, Today, 01:17 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Working...
          X