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 within a For Loop

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

    Draw.Text within a For Loop

    Hi NT,

    Using: Calculate.OnBarClose
    I have 10 consecutive down bars (i could label them 1-10 using Draw.Text and a counter value).
    I add the CurrentBar value to a List object, so my list will have 10 entries of CurrentBar.

    On the 10th bar close, id like to say something like:
    Look back over the 10 bars and count each instance where we closed lower than the prior low.
    I would like to restrospectively add Draw.Text to those historical bars, where that condition is true.
    Here is an example of the logic I am using to try and achieve this:

    Code:
    If we had 10 down bars
    {
    	for ( int i = 0; i < ListSetupBuy.Count; i ++ ) 
    	{
    		if(Close[9-i] < Low[(9-i)+2])			// condition X
    		{
    			counter++;
    			someSeries[8-i] = counter;
    			Draw.Text(....)
    			Draw.Dot(this, "C1" + CurrentBar, true, 0, Low[8-i], Brushes.Orange);	
    		}	
    	}
    }

    I am using a draw.dot just as an easy example to illustrate a point.
    Id actually want to use draw.text to number the bars where condition X is true with the counter value.

    This seems to make sense (to me), but is not yeilding the desired results.
    I only see the draw.dot output on the last bar (10th), which is the current bar.

    Is it possible to add annotations to a bunch of bars historically once a condition is triggered on the current bar?
    I thought a for loop > condition > draw method could acheive this, but with no luck thus far.

    Thanks in advance
    AK

    #2
    Hello akvevo,

    Thank you for the post.

    I believe this is caused by the Tag you are using. On the CurrentBar where the loop is executed, that will not change so the Tag being used is not unique. You should instead use the "i" variable in there somewhere:

    Code:
    for ( int i = 0; i < ListSetupBuy.Count; i ++ ) 
    	{
    		if(Close[9-i] < Low[(9-i)+2])			// condition X
    		{
    			counter++;
    			someSeries[8-i] = counter;
    			Draw.Text(....)
    			Draw.Dot(this, [B]"C1" + i[/B], true, 0, Low[8-i], Brushes.Orange);	
    		}	
    	}
    Could you try that change and see if that is the solution?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      But i am using i

      Code:
       "C1" + i

      Comment


        #4
        Hello akvevo,

        I don't see that you are, the sample I provided I have added the syntax where it is bold.

        Here is a quote of what you had originally provided with the tag bolded:
        I do not see "C1" + i in your sample.

        Code:
        If we had 10 down bars
        {
        	for ( int i = 0; i < ListSetupBuy.Count; i ++ ) 
        	{
        		if(Close[9-i] < Low[(9-i)+2])			// condition X
        		{
        			counter++;
        			someSeries[8-i] = counter;
        			Draw.Text(....)
        			Draw.Dot(this,[B] "C1" + CurrentBar[/B], true, 0, Low[8-i], Brushes.Orange);	
        		}	
        	}
        }
        In your sample, you are using "C1" + CurrentBar which will be the same value through the size of the loop. I had suggested changing that to "C1" + i so it will be unique through the iterations of the loop.

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          My bad, apologies, you are correct
          I'll try and revert

          Comment


            #6
            This didn't yield the desired results, this also got rid the only dot I had on bar 10

            Comment


              #7
              Hello,

              Thank you for the reply.

              Yes, there could be other problems surrounding the syntax you have used. As for the initial concern, using a non-unique tag like "C1" + CurrentBar would make only 1 drawing object for the count of the loop so that was certainly part of the problem regarding 1 object on bar 10.

              What is the new outcome you are seeing now, are you seeing more than 1 dot or not dots at all? Are you seeing any errors in the log or output windows?

              If you are not seeing any dots, are you certain that your condition is becoming true in the test where the item is being used now?

              As you are using a Loop, I would also suggest that you also use Prints to confirm the values being used with the drawing objects. If you are not seeing any objects, it may be that part of your condition is not becoming true, or some other syntax related to drawing the dots is not happening as expected.

              We have a short guide on how to debug NinjaScript files here: https://ninjatrader.com/support/foru...49&postcount=2

              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Thanks Jesse,

                Agreed, "C1" + CurrentBar didnt help.

                The new outcome is "no dots" anywhere (the one i had on bar 10 when I used the bad tag before is gone too).

                No error messages in Log or Output window.

                Yes, I am certain my condition in is true (i verified by placing the condition outside the for loop and can see dots).

                I am taking a look into how "Prints" can assist me here, although I thought using draw.dot tried to do the same thing

                Comment


                  #9
                  Hello,

                  Thank you for the reply.

                  Yes, in this case, it sounds like this has to do with the loop.

                  Prints will be more helpful here as you can see values of the objects you are using. You could use prints to check the count of items you are looping over, the i variable and any other portions of the logic. The reason this is better than the drawing object is that there is basically no way to fail at using a print, drawing objects have other stipulations that control them such as the Tags which may get in the way.

                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Jesse,

                    "Prints" indentified there was nothing wrong with the loop/logic at all.
                    The issue, as you pointed out, was due to the tag name.

                    I had to use "Time[i]" to truly have a unique tag, "i" wasnt enough:

                    Code:
                    Draw.Dot(this, "YO" + Time[i], true, 8-i, Low[8-i], Brushes.Aqua);

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by TradeForge, Today, 02:09 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post TradeForge  
                    Started by Waxavi, Today, 02:00 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post Waxavi
                    by Waxavi
                     
                    Started by elirion, Today, 01:36 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post elirion
                    by elirion
                     
                    Started by gentlebenthebear, Today, 01:30 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post gentlebenthebear  
                    Started by samish18, Yesterday, 08:31 AM
                    2 responses
                    9 views
                    0 likes
                    Last Post elirion
                    by elirion
                     
                    Working...
                    X