Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help Requested Re Variable Persistence

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

    Help Requested Re Variable Persistence

    Hi ,

    Please excuse me if this is a simple question. I have searched the forum but have not found any answers related to what I am looking for. If anyone would be kind enough to either suggest an answer or direct me to where I might be able to find an answer, I would greatly appreciate it. Thank you very much.

    I have an indicator that uses DrawLine to drawlines. I want to change the tag of each line so that I get the historical lines to remain on the chart. Currently I have a variable, int lineID, which I convert to a string to create a unique tag; i.e Convert.ToString(lineID).
    I am not sure this will work because I have to initialize the lineID variable, int lineID = 0;, and therefore I don't know how to persist it so that it is not reset to zero.

    #2
    Zeos6,

    You can just run a counter variable as your tag.

    In Variables region
    Code:
    private int counter = 0;
    In OnBarUpdate()
    Code:
    DrawLine(counter.ToString(),..some other parameters..);
    counter++;
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thank you very much. I really appreciate it.

      One more question if I may...
      I have the following line

      DrawLine("r"+counter.ToString, ....

      and I am getting an error message that the + operand cannot be applied to operands of type "string" and "method group"

      I thought the + was overloaded in C# to allow concatenation of strings.

      Thank you.


      Originally posted by NinjaTrader_Josh View Post
      Zeos6,

      You can just run a counter variable as your tag.

      In Variables region
      Code:
      private int counter = 0;
      In OnBarUpdate()
      Code:
      DrawLine(counter.ToString(),..some other parameters..);
      counter++;

      Comment


        #4
        ToString requires parenthesis at the end of them. It is ToString().
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thank you very much. I feel so dense. I completely missed that.
          I truly appreciate your help but one final question....I apologize in advance for taking up your time and inconveniencing you. Thank you very much for all your help.

          I am trying to draw two lines:

          DrawLine("r"+counter.ToString(), ...
          DrawLine("f"+counter.ToString(), ...

          If I have only one DrawLine("r"+counter.ToString(),... the line is drawn.
          If I use both DrawLine statements, as shown above, nothing gets plotted.
          I am confused. Can you only use one DrawLine at a time?


          Originally posted by NinjaTrader_Josh View Post
          ToString requires parenthesis at the end of them. It is ToString().

          Comment


            #6
            No problem at all. That is what we are here for.

            No, you can use as many DrawLine()s as you want. What I suggest is you to check your Log tab for runtime errors. You might have drawn it to an invalid bar index thus causing errors which results in nothing being drawn.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Thank you.

              Originally posted by NinjaTrader_Josh View Post
              No problem at all. That is what we are here for.

              No, you can use as many DrawLine()s as you want. What I suggest is you to check your Log tab for runtime errors. You might have drawn it to an invalid bar index thus causing errors which results in nothing being drawn.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              569 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              330 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              548 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              548 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X