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

Can a loop increment a tag AND a variable?

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

    Can a loop increment a tag AND a variable?

    Howdy,

    I have a loop I want to create and wrap around the following piece of script:
    Code:
    			
                            double pointA1 = zeroLine - High[xIndex];
    			double pointB1 = zeroLine - Low[xIndex];
    			DrawLine("bar1", false, -2,zeroLine + pointA1, -2, zeroLine + pointB1, Color.Green, DashStyle.Solid, lineWidth);
    I need to be able to increment the variable NAMES "PointA1" and "PointB1." I also need to be able to increment the tag in the DrawLine() method as well, from "bar1" to "bar2" for example.

    I have attached a picture with arrows pointing at the vars and tags that need to be updated. The variables that are indexes themselves are no problem. Just the Var Name and Tag I need help with.

    Is this possible to do?

    Thanks,
    Forrest
    Attached Files

    #2
    Hi Forrest,

    I'm not sure if this would be possible exactly as you like. In C# it's not common to have variables as the variable name and would take some advanced techniques if it were even possible. What is the exact problem you're trying to solve? Maybe there's a different approach to take.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_RyanM View Post
      Hi Forrest,

      I'm not sure if this would be possible exactly as you like. In C# it's not common to have variables as the variable name and would take some advanced techniques if it were even possible. What is the exact problem you're trying to solve? Maybe there's a different approach to take.
      Well, the code sample I posted above, represents a bar projection into beyond the most CurrentBar on the chart. So as is now, just to test concept, I manually copied/pasted/incremented it 30 times. This will plot 30 bars. But I would like this to be variable, so that i can have a user input for how many bars I would like posted onto my chart.

      Now that you mention it, that variable with the name pointA1/pointB1, I can do away with that, so that would be fine. That variable contains the y-coordinates for that DrawLine(). But I can just put that value in the DrawLine() directly instead of using the var pointA1/pointB1... and increment with the loop.

      The problem would then just be the DrawLine() and the TAG. Given that each time I want to draw a new bar projection, it needs a NEW unique tag, otherwise it would only draw one bar projection. Can you think of a way to be able to somehow rename the TAG each time through the loop?

      Comment


        #4
        Just to add, I was thinking with that string TAG in the DrawLine() method, that you could concatonate a number to the end of it somehow, since it is a string?

        Comment


          #5
          OK, tag is workable in a loop. It's a string and you can add items together to form it. The tag below is formed from "bar" + the value of your loop counter.

          Code:
          for (int x = 1; x <=5; x++)
          {
          DrawLine("bar" + x, false, -2,zeroLine + pointA1, -2, zeroLine + pointB1, Color.Green, DashStyle.Solid, lineWidth);
          }
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_RyanM View Post
            OK, tag is workable in a loop. It's a string and you can add items together to form it. The tag below is formed from "bar" + the value of your loop counter.

            Code:
            for (int x = 1; x <=5; x++)
            {
            DrawLine("bar" + x, false, -2,zeroLine + pointA1, -2, zeroLine + pointB1, Color.Green, DashStyle.Solid, lineWidth);
            }
            Ah yes, that is what I was thinking. Lemme try this out!

            Forrest

            Comment


              #7
              Originally posted by forrestang View Post
              Ah yes, that is what I was thinking. Lemme try this out!

              Forrest
              Thanks Ryan, that worked for me.

              Comment


                #8
                Glad to hear it, Forrest. Thanks for reporting back.
                Ryan M.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by SantoshXX, Today, 03:09 AM
                0 responses
                11 views
                0 likes
                Last Post SantoshXX  
                Started by DanielTynera, Today, 01:14 AM
                0 responses
                2 views
                0 likes
                Last Post DanielTynera  
                Started by yertle, 04-18-2024, 08:38 AM
                9 responses
                41 views
                0 likes
                Last Post yertle
                by yertle
                 
                Started by techgetgame, Yesterday, 11:42 PM
                0 responses
                12 views
                0 likes
                Last Post techgetgame  
                Started by sephichapdson, Yesterday, 11:36 PM
                0 responses
                2 views
                0 likes
                Last Post sephichapdson  
                Working...
                X