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

RemoveDrawObject

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

    RemoveDrawObject

    Hello,Support and All!

    Can "else {RemoveDrawObject}" method be used as a trigger for a strategy on COBC = false?

    For example:
    Code:
    else
               {	
    		RemoveDrawObject("Bingo" + CurrentBar);
    		sBingo.Set(1);
    	    }
    Thanks!

    #2
    Hello outsource,

    Thanks for writing in.

    I am not sure of the full context of your logic, or where the else statement is placed. If you are referring to having an else statement trigger an order when the else statement is attached to an if statement that also enters a position, I would not advise this.

    Logically, an else statement will occur every time the if statement is not true. This can cause many repeated entries. I would advise to use else if to control your entries so you can add further logic that can prevent unwanted repeated entries.

    CalculateOnBarClose simply changes the rate at which OnBarUpdate() gets called. It would not have a logical effect on your strategy, unless you require high precision to catch trends. When CalculateOnBarClose is false, OnBarUpdate will get called for every tick as opposed to when the primary data series' bar closes.

    Further information, examples, and tips on using CalculateOnBarClose can be found below:



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

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Hello outsource,

      Thanks for writing in.

      I am not sure of the full context of your logic, or where the else statement is placed. If you are referring to having an else statement trigger an order when the else statement is attached to an if statement that also enters a position, I would not advise this.

      Logically, an else statement will occur every time the if statement is not true. This can cause many repeated entries. I would advise to use else if to control your entries so you can add further logic that can prevent unwanted repeated entries.

      CalculateOnBarClose simply changes the rate at which OnBarUpdate() gets called. It would not have a logical effect on your strategy, unless you require high precision to catch trends. When CalculateOnBarClose is false, OnBarUpdate will get called for every tick as opposed to when the primary data series' bar closes.

      Further information, examples, and tips on using CalculateOnBarClose can be found below:



      Please let me know if I may be of further help.
      Hi,Jim!

      The full logic looks like this:

      Code:
      if(Bow > Wow|| Wow > Bow)
      					
      										 
      				{			
      					DrawText ("Hello" + CurrentBar, false, "BowOrWow".......bla...bla);
      				}
      	        
      	 			else
      				{	
      					RemoveDrawObject("Hello" + CurrentBar);
      					this.sBingo.Set(1);
      				}
      And sorry,i forgot to clarify,the logic is not within the strategy,it`s being called via an indicator.So why it wouldn`t work ,as you say?
      Last edited by outsource; 02-28-2017, 05:48 PM.

      Comment


        #4
        Hello outsource,

        Thanks for your reply.

        As it appears in your script, you wish to draw the text "BowOrWow" when a bar update occurs and remove the text "BowOrWow" when that condition is no longer true.

        Your if/else statements will work however RemoveDrawObject("Hello" + CurrentBar); will never clear the DrawText() drawing object because CurrentBar will never be the same.

        Consider the 1st bar, if Bow != Wow, we DrawText() for "BowOrWow" with the tag "Hello" + CurrentBar, or "Hello1"

        On the second bar, if Bow == Wow, we RemoveDrawObject() for "BowOrWow" with the tag "Hello" + CurrentBar, or "Hello2"

        Since there is no drawing object with the tag "Hello2" nothing gets removed.

        To work around this, you will want to create a variable to hold the bar number for when the DrawText() call is made. When you want to remove the drawing object, you will want to reference that variable instead of CurrentBar.

        Please let me know if you have any questions.
        JimNinjaTrader Customer Service

        Comment


          #5
          Could you guys please explain the diff between the two when moving the drawing objects:

          1)(CurrentBar + 1);
          2)(CurrentBar - 1).

          Thank you!

          Comment


            #6
            Originally posted by outsource View Post
            Could you guys please explain the diff between the two when moving the drawing objects:

            1)(CurrentBar + 1);
            2)(CurrentBar - 1).

            Thank you!
            #1 is one bar into the future, and hasn't happened yet.

            #2 is the previous bar to the left of the most recently closed bar.

            Think of it this way:
            Let's say you load a chart with 10 days of data, and the chart sets up exactly 10000 bars (of course, bars are built from historical data at first, then new bars are built in real-time from real-time data). My point is: each of the bars has a number, a unique "id" so to speak, associated with it -- these internal ids start at 0. The very first bar, scroll your chart all the way to the left, that very first bar is numbered 0, the next bar is 1, then 2, and so on.

            How many bars have been added to the chart? In our example, 10,000 bars, and the value stored in CurrentBar will be 9999, remember bar counting starts at zero, not one. The next bar being built, gets the next value of CurrentBar, in this case 10000.

            So, think carefully, there are 10,000 bars on the chart, numbered 0 to 9,999. The 10,001st bar is being built in realtime, and even before it closes we know this bar's number, which is CurrentBar+1, or 9999+1, which means as soon as this bar closes, NT will internally increment CurrentBar by 1, assigning value 10000 to the just closed bar. And now, there are 10,001 bars on the chart, numbered 0 to 10000, and the value of CurrentBar is 10000 -- and the next real-time bar being built will get the number CurrentBar+1, or 10001 -- the process repeats ad infinitum.

            So, CurrentBar+1 represents the total number of bars that have closed that are drawn on the chart. You probably can't see them all without scrolling to the left, but every single bar has a number, starting at 0. If the total number of bars drawn is 10,000 then CurrentBar will contain 9999 (aka, TotalBarsDrawnOnChart = CurrentBar + 1).

            CurrentBar+1 is the number that will be assigned to the current bar being built in real-time, aka the next bar, and as such, this bar hasn't closed yet.

            Technically, that next bar in progress doesn't have a number (or a timestamp, or a Close price) yet, since it hasn't closed. But, we do know for certain (formulaically speaking) what that bar's number will be -- and that is always CurrentBar+1.

            Now, think relative (like on a timeline, the x-axis on a chart is always timestamped), the bar that has just closed, aka the most recently closed bar, it's current id value is known to be CurrentBar (which is whatever that number happens to be).

            Remember, CurrentBar just contains a number, but it's always advancing, being incremented by 1 every time a bar closes. When a bar does close, the bar keeps its internal id number, in an internal variable, say BarId, which gets assigned to it after CurrentBar is incremented.

            The bar previous to that bar, that is, the relative position known as the "the bar previous to the most recently closed bar" always has an id value of CurrentBar-1.

            Now, for some extra enlightenment, why do you think most of the Draw APIs in NT accept parameters named like "BarsAgo", "StartBarsAgo", "EndBarsAgo", etc?

            Answer: because NT starts the draw action at CurrentBar-BarsAgo, so if you pass in 5 for BarsAgo, NT converts this to CurrentBar-5 to find which bar to start the draw operation.

            But for something like, RemoveDrawObject("Hello" + CurrentBar), the value being passed as the argument is just a string, like "Hello9999", which simply serves the form of being a unique string that can uniquely identify that draw object amongst all the other draw objects.

            Yep, CurrentBar is an internal variable, but has become a subservient ***** of a number that gets borrowed for all sorts of things (for example, to uniquely identify something as a string, aka a unique kind of tag, whose underlying purpose is to mean "X-happened-on-bar-Y"). It gets used and abused so much precisely because of its always-incrementing-once-per-bar property.
            Last edited by bltdavid; 03-13-2017, 01:34 AM.

            Comment


              #7
              Originally posted by bltdavid View Post
              #1 is one bar into the future, and hasn't happened yet.

              #2 is the previous bar to the left of the most recently closed bar.

              Think of it this way:
              Let's say you load a chart with 10 days of data, and the chart sets up exactly 10000 bars (of course, bars are built from historical data at first, then new bars are built in real-time from real-time data). My point is: each of the bars has a number, a unique "id" so to speak, associated with it -- these internal ids start at 0. The very first bar, scroll your chart all the way to the left, that very first bar is numbered 0, the next bar is 1, then 2, and so on.

              How many bars have been added to the chart? In our example, 10,000 bars, and the value stored in CurrentBar will be 9999, remember bar counting starts at zero, not one. The next bar being built, gets the next value of CurrentBar, in this case 10000.

              So, think carefully, there are 10,000 bars on the chart, numbered 0 to 9,999. The 10,001st bar is being built in realtime, and even before it closes we know this bar's number, which is CurrentBar+1, or 9999+1, which means as soon as this bar closes, NT will internally increment CurrentBar by 1, assigning value 10000 to the just closed bar. And now, there are 10,001 bars on the chart, numbered 0 to 10000, and the value of CurrentBar is 10000 -- and the next real-time bar being built will get the number CurrentBar+1, or 10001 -- the process repeats ad infinitum.

              So, CurrentBar+1 represents the total number of bars that have closed that are drawn on the chart. You probably can't see them all without scrolling to the left, but every single bar has a number, starting at 0. If the total number of bars drawn is 10,000 then CurrentBar will contain 9999 (aka, TotalBarsDrawnOnChart = CurrentBar + 1).

              CurrentBar+1 is the number that will be assigned to the current bar being built in real-time, aka the next bar, and as such, this bar hasn't closed yet.

              Technically, that next bar in progress doesn't have a number (or a timestamp, or a Close price) yet, since it hasn't closed. But, we do know for certain (formulaically speaking) what that bar's number will be -- and that is always CurrentBar+1.

              Now, think relative (like on a timeline, the x-axis on a chart is always timestamped), the bar that has just closed, aka the most recently closed bar, it's current id value is known to be CurrentBar (which is whatever that number happens to be).

              Remember, CurrentBar just contains a number, but it's always advancing, being incremented by 1 every time a bar closes. When a bar does close, the bar keeps its internal id number, in an internal variable, say BarId, which gets assigned to it after CurrentBar is incremented.

              The bar previous to that bar, that is, the relative position known as the "the bar previous to the most recently closed bar" always has an id value of CurrentBar-1.

              Now, for some extra enlightenment, why do you think most of the Draw APIs in NT accept parameters named like "BarsAgo", "StartBarsAgo", "EndBarsAgo", etc?

              Answer: because NT starts the draw action at CurrentBar-BarsAgo, so if you pass in 5 for BarsAgo, NT converts this to CurrentBar-5 to find which bar to start the draw operation.

              But for something like, RemoveDrawObject("Hello" + CurrentBar), the value being passed as the argument is just a string, like "Hello9999", which simply serves the form of being a unique string that can uniquely identify that draw object amongst all the other draw objects.

              Yep, CurrentBar is an internal variable, but has become a subservient ***** of a number that gets borrowed for all sorts of things (for example, to uniquely identify something as a string, aka a unique kind of tag, whose underlying purpose is to mean "X-happened-on-bar-Y"). It gets used and abused so much precisely because of its always-incrementing-once-per-bar property.
              Thank you, for such an explicit explanation,Sir!

              Need to internalize a bit,but so far i have problems with removing and retaining drawing objects on COBC = false.When it`s true, it`s ok and the objects are kept as expected.But when the objects are being drawn real time on COBC = false, on FirstTickOfBar there`s a constant shuffling going on,so i can`t find the reasons why.Could that be due to an indicators re-painting behavior, i`m not sure...

              Comment


                #8
                Hello outsource,

                I am glad that you have been able to get further guidance on the forums.

                So that we assist you further, could you provide screenshots of the behavior you are encountering and provide the sample code that exhibits this?

                To send a screenshot with Windows 7 or newer, we recommend using Window's Snipping Tool.

                Click here for instructions

                Alternatively, please take a screenshot with Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

                Click here for detailed instruction


                I look forward to your reply.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by outsource View Post
                  i have problems with removing and retaining drawing objects on COBC = false.
                  Remember, when COBC=false, your OnBarUpdate is getting called for ever tick while that real-time bar is being built. Every tick, ever damn one, but that whole time, CurrentBar hasn't changed -- it only increments after the bar closes.

                  In effect, when FirstTickOfBar is true, this is your clue that CurrentBar was just incremented -- and it's value is now different than the previous call.

                  Otherwise, when FirstTickOfBar is false, CurrentBar's value has not changed -- it's value is the same as the previous call.

                  If you use "Hello"+CurrentBar as your tag (this is fine) then the whole time while FirstTickOfBar is false (aka processing each intra-bar tick) that string is the same value -- because CurrentBar won't change until the bar closes.

                  You'll get flicker or flashing, which is the indecision of something being drawn on one tick, but removed on the next tick. This "indecisive" behavior is normal and expected, it is a natural consequence of COBC=false.

                  What you don't want are draw artifacts that are drawn one tick and then abandoned on the next tick (when the logic of the next tick should remove it, not let it linger).

                  Comment


                    #10
                    @bltdavid,@NinjaTrader_Jim,

                    Hello,guys!

                    Thank you for the futher support.I attached the indicator.The problem is that now it doesn`t remove markers(COBC = false) with the new bar.Please suggest where the changes should be made.

                    Thank you!

                    p.s. i simplified the conditions a bit.Now how does this resolve the arrow issue?
                    Attached Files
                    Last edited by outsource; 03-13-2017, 06:46 PM.

                    Comment


                      #11
                      Originally posted by outsource View Post
                      Please suggest where the changes should be made.
                      I spent 15 minutes looking at your code ... nothing stands out.

                      Just trying to get up to speed took me too long ... sorry.

                      Have you tried contacting a NinjaScript consultant for help?

                      Comment


                        #12
                        Originally posted by bltdavid View Post
                        I spent 15 minutes looking at your code ... nothing stands out.

                        Just trying to get up to speed took me too long ... sorry.

                        Have you tried contacting a NinjaScript consultant for help?
                        What do you mean nothing stood out?I don`t get it.

                        Comment


                          #13
                          Originally posted by outsource View Post
                          What do you mean nothing stood out?I don`t get it.
                          What is it that you don't get?

                          That's my nice way of saying I don't feel like doing the work to solve your problem.

                          I read your code, I tried to understand it, but your code is not very clear to me, then my lunch was ready, so I stopped.

                          I enjoy helping people, answering questions, etc, but I rarely fix code (for free) that is too difficult to read & understand inside of "X" minutes -- today I am busy so "X" happened to be about 15.

                          Comment


                            #14
                            Originally posted by bltdavid View Post
                            What is it that you don't get?

                            That's my nice way of saying I don't feel like doing the work to solve your problem.

                            I read your code, I tried to understand it, but your code is not very clear to me, then my lunch was ready, so I stopped.

                            I enjoy helping people, answering questions, etc, but I rarely fix code (for free) that is too difficult to read & understand inside of "X" minutes -- today I am busy so "X" happened to be about 15.
                            Could you please check the simplified version at the post #10?How do i remove the arrows at the bar[1]?That`s all i need,basically.

                            Comment


                              #15
                              Hello outsource,

                              I have taken a glance at your code.

                              Please take another look at my previous message, it describes how you need to create and remove unique drawing objects.

                              Originally posted by NinjaTrader_Jim View Post
                              Your if/else statements will work however RemoveDrawObject("Hello" + CurrentBar); will never clear the DrawText() drawing object because CurrentBar will never be the same.

                              Consider the 1st bar, if Bow != Wow, we DrawText() for "BowOrWow" with the tag "Hello" + CurrentBar, or "Hello1"

                              On the second bar, if Bow == Wow, we RemoveDrawObject() for "BowOrWow" with the tag "Hello" + CurrentBar, or "Hello2"

                              Since there is no drawing object with the tag "Hello2" nothing gets removed.

                              To work around this, you will want to create a variable to hold the bar number for when the DrawText() call is made. When you want to remove the drawing object, you will want to reference that variable instead of CurrentBar.
                              In addition to several formatting issues, I notice that you are still trying to remove drawing objects based off of the tag and some offset from CurrentBar. This is incorrect. You will want to follow the instructions above and create a variable that stores the location of that drawing object (the CurrentBar in which that drawing object gets created) and use that variable to reference that drawing object that you want to remove.

                              If you would like to look into hiring a NinjaScript Consultant for developing your indicator, I can have a member of our Business Development team reach out to you with a list of NinjaScript Consultants. Please send a message to platformsupport[at]ninjatrader[dot]com and attach the ticket number "1668367" along with the text "Attention Jim" if this is the case.

                              Please let me know if you have any further questions.
                              JimNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by funk10101, Today, 09:43 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post funk10101  
                              Started by pkefal, 04-11-2024, 07:39 AM
                              11 responses
                              36 views
                              0 likes
                              Last Post jeronymite  
                              Started by bill2023, Yesterday, 08:51 AM
                              8 responses
                              44 views
                              0 likes
                              Last Post bill2023  
                              Started by yertle, Today, 08:38 AM
                              6 responses
                              26 views
                              0 likes
                              Last Post ryjoga
                              by ryjoga
                               
                              Started by algospoke, Yesterday, 06:40 PM
                              2 responses
                              24 views
                              0 likes
                              Last Post algospoke  
                              Working...
                              X