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

Numbering Sequence Draw.Text

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

    Numbering Sequence Draw.Text

    Hi NT Ninja Script experts,

    Looking for some assistance if possible for something I am trying to achieve with a custom indicator. In a nutshell... I am trying to add a number (text) below bar, just a sequence of numbers if a condition is true. Like so:

    Code:
    if something is true
    {
    if (close[0] < close[2])
    {
    //label the bar with numbers from 1-20
    }
    }
    As you can see from the condition above, its quite possible for the 1-20 sequence to not be consecutive.

    I know I can use Draw,Text to add these labels:

    Code:
    ...
    if (close[0] < close[2])
    {
    Draw.Text(this, "tag.C.B1" + CurrentBar, true, "1", 0, Low[0] - (((ATR(14))[0])*1.75), 20, Brushes.Red, new SimpleFont("Arial", 12),TextAlignment.Center,Brushes.Transparent, Brushes.Transparent, 0);
    }
    That's is great for numbering the first bar, but I cant use this to number second bar with "2", but the sequence may not be consecutive and I the next bar may not meet the condition, so i may end up waiting for a few bars until "2" is fulfilled.

    I thought about using a counter (int counter = 0) and incrementing it every-time the condition is true.... but the Draw.Text needs a 'string' for the number "1", I cant simply enter the 'counter' variable, instead of "1".

    Any ideas on a possible solution ?
    Thanks in advance

    AK

    #2
    Hello akveveo,

    Thanks for your inquiry.

    I would advise to use the counter like you mentioned, and then to attach it to the string.

    For example, we make unique strings for drawing tags like: "tag"+CurrentBar.

    You could create any string and then append a number to it.

    "Some Text " + 1
    -or-
    "Some Text " + Number
    -or-
    "" + SomeNumber

    If I'm missing something with your question could you maybe provide an illustration that describes what you are trying to do?

    Please let me know if I may be of further help.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks Jim,

      Thanks for your reply.
      What do you mean by "attach it to the string" ?
      You mean "1" can be replaced with "string" + number ? and that would work as one of the arguments for the Draw.Text ?

      I've attached an illustration

      AK
      Attached Files

      Comment


        #4
        Hello akvevo,

        Thanks for the additional detail.

        By attach to string, I mean to append/add the number to the end of the string with the "+" operator.

        For example:

        Code:
        Draw.Text(this,[B] "tag.C.B1" + CurrentBar[/B], true, "1", 0, Low[0] - (((ATR(14))[0])*1.75), 20, Brushes.Red, new SimpleFont("Arial", 12),TextAlignment.Center,Brushes.Transparent, Brushes.Transparent, 0);
        The bold section takes the string "tag.C.B1" and appends the value of CurrentBar to the end of it. So the sting that passes through the tag argument is "tag.C.B11", "tag.C.B12", "tag.C.B13", etc.

        If we have an empty string "" we can append a number to it like ""+1, or ""+Variable. You can also convert a variable to a string by calling the ToString() property method. I'll provide a demonstration below.

        Code:
        int variable = 1;
        string myString = variable.ToString();
        I may also suggest to review the Manipulating String Object sample we have on our forums for further information on manipulating strings: https://ninjatrader.com/support/foru...ad.php?t=19174

        If you have any questions, please don't hesitate to write back.
        JimNinjaTrader Customer Service

        Comment


          #5
          Thanks Jim

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by martin70, 03-24-2023, 04:58 AM
          14 responses
          105 views
          0 likes
          Last Post martin70  
          Started by TraderBCL, Today, 04:38 AM
          0 responses
          2 views
          0 likes
          Last Post TraderBCL  
          Started by Radano, 06-10-2021, 01:40 AM
          19 responses
          606 views
          0 likes
          Last Post Radano
          by Radano
           
          Started by KenneGaray, Today, 03:48 AM
          0 responses
          4 views
          0 likes
          Last Post KenneGaray  
          Started by thanajo, 05-04-2021, 02:11 AM
          4 responses
          470 views
          0 likes
          Last Post tradingnasdaqprueba  
          Working...
          X