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

DrawText Not Working inside 'foreach' loop

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

    DrawText Not Working inside 'foreach' loop

    I have the following code (where kvp.Key is a number 1 to 41, and kvp.Values are double formatted price levels (like 1130.25).

    The following code executes the DrawHorizontalLine correctly but not the DrawText statements-unless I move it outside the foreach loop --for example you will note the exact same "DrawText" statement above the foreach loop statement-it works fine....while if I comment it out and use just the one inside the foreach loop-it doesn't work.

    Any reason the DrawText won't work inside a foreachloop while the drawhorizontalline does?

    (I only pasted the code down to the 2nd DrawText statement-the rest of the forloop works as expected....)

    -------code here: -----------------------------
    // the following works as -is, I comment it out to test the other location
    DrawText("mytag", true, "XXXX" , 0,1130 ,0, Color.Black, largeFont, StringAlignment.Far, Color.Yellow, Color.Yellow, 5);

    foreach( KeyValuePair<int, double> kvp in levels )
    {

    if(showLS==true)
    {
    if(kvp.Key >= 1 && kvp.Key <= 9)
    {
    prefix = "L";
    lnum = kvp.Key;
    label = prefix + lnum;
    DrawHorizontalLine("MyHorizontalLine"+kvp.Key, kvp.Value, Color.Blue,DashStyle.Solid,LS_Size);
    DrawText("mytag", true, "XXXX" , 0,1130 ,0, Color.Black, largeFont, StringAlignment.Far, Color.Yellow, Color.Yellow, 5);
    }
    Jim-Boulder
    NinjaTrader Ecosystem Vendor - Elephant Tracks

    #2
    Jim,

    In your draw text, you need to add the kvp.Ket to the "mytag" just as you do for the DrawHorizontalLine. Each drawing object must have a unique tag, otherwise you will only see the last one.
    mrlogik
    NinjaTrader Ecosystem Vendor - Purelogik Trading

    Comment


      #3
      thanks for the reply--I actually had what you suggested at first but it didn't work either-so then I tested using just static values and got the results I described in my question. I am not getting any text to display inside the foreach loop-and I've tried every combination--plus went to the most simplistic version of the drawtext statement to see if I could get anything to work...nothing I tried works...

      In my example I am using static values for the label and the "y scale" value-just to eliminate as many variables while I am debugging this...

      I can't figure out what the program flow would have to do with it...
      Jim-Boulder
      NinjaTrader Ecosystem Vendor - Elephant Tracks

      Comment


        #4
        Hi Jim-Boulder,

        If you provide script of enough code snippet that works (has appropriate variable declarations etc) I'd be happy to test this on my end.
        TimNinjaTrader Customer Service

        Comment


          #5
          can you provide an email to do that?
          Jim-Boulder
          NinjaTrader Ecosystem Vendor - Elephant Tracks

          Comment


            #6
            Hi Jim-Boulder,

            Yes, please send a note to "Support at ninjatrader dot com" with "ATTN: TIM" in the subject line.

            Also, please reference this post: http://www.ninjatrader.com/support/f...ad.php?t=32062
            TimNinjaTrader Customer Service

            Comment


              #7
              Thanks Tim for your help....

              After all the work-I had to abandon the use of DrawLines because the user could easily (but accidentally) move the line-which nullifies the entire reason for the indicator as these are daily key levels that are used for long or shorts.

              I assume there is not away to lock them in NT 6.5..right?

              So I'm going back to using Plots--how can I do this so that it reads the external file once and sets the values for each plot line once? Since the plot values are actually not changing from one bar to the next-there's no reason to 'update' their values each iteration..

              Is there some way to accomplish a read values from the file once and set the values for each plot just once, but have the plot show up across the entire chart (and not just for the first bar in the series)?

              The end goal is to reduce the resource consumption from this indicator...
              Jim-Boulder
              NinjaTrader Ecosystem Vendor - Elephant Tracks

              Comment


                #8
                Unfortunately you cannot lock objects in 6.5. There is also no way to not set a plot value on every bar and have it paint for all of them. You will have to set the plot value or else it will have no value on the bars you do not set it on.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Josh....

                  Is it possible (an a resource saver) to within the onbarupdate to have one section of code that runs only on CurrentBar = 0 (the file read and assign values to an array) and then a 2nd section that is run on CurrentBar >= 0? (this would assign the values for the plots)

                  and do something like this?
                  set plot values on bar=0, then do the following for CurrentBar > 0:

                  simply assign the same value for each bar's plot value? (assume "myPlot1" is tied to Values[1])

                  myPlot1.Set(Values[1][1]):
                  Jim-Boulder
                  NinjaTrader Ecosystem Vendor - Elephant Tracks

                  Comment


                    #10
                    A Simplier Question

                    Josh/Support Team

                    Let me clarify exactly what I am seeking:

                    I want to read the external files values just once...and do the remainder of the indicators process (setting plot values, etc.) on each bar....

                    How to do that?
                    Jim-Boulder
                    NinjaTrader Ecosystem Vendor - Elephant Tracks

                    Comment


                      #11
                      Jim-Boulder, your suggestion of doing all the work when CurrentBar == 0 is the best way to do what you seek. You could do something like this:
                      Code:
                      OnBarUpdate()
                      {
                         if (CurrentBar == 0)
                         {
                            // do one time stuff, like read data from a file
                         }
                         
                         // rest of your strategy stuff here. you could use an else statement, but that would mean the rest wouldn't be executed on the first bar
                      }
                      AustinNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Shansen, 08-30-2019, 10:18 PM
                      24 responses
                      938 views
                      0 likes
                      Last Post spwizard  
                      Started by Max238, Today, 01:28 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post Max238
                      by Max238
                       
                      Started by rocketman7, Today, 01:00 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post rocketman7  
                      Started by wzgy0920, 04-20-2024, 06:09 PM
                      2 responses
                      27 views
                      0 likes
                      Last Post wzgy0920  
                      Started by wzgy0920, 02-22-2024, 01:11 AM
                      5 responses
                      32 views
                      0 likes
                      Last Post wzgy0920  
                      Working...
                      X