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

Object disappearing when updated

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

    Object disappearing when updated

    I have been trying to figure out how to update an object simply.

    I am instantiating the object once the CurrentBar data has been processed as follows:

    Code:
    protected override void OnBarUpdate()
            {
                if( CurrentBar < Count - 2) {return;}
                if(!once) 
                {
                    once=true; 
                    spot=DrawDot("spot",false,Time[0],High[0],Color.Blue);
                    Print("INITIAL  spot.Y: "+spot.Y.ToString()+"   spot.Time: "+spot.Time.ToString()+"   spot.Color: "+spot.Color.ToString());
                }
            }
    In another section of code, I capture and calculate the price and time of a mouse click...which I won't post as it is unsupported code, and irrelevant anyway (since it is working correctly). Anyway....I use this time and price data to update the position of the Dot object with the following code:
    Code:
    private void PMLBD(object s, System.Windows.Forms.MouseEventArgs e)
            {
                ptM.X=e.X; ptM.Y=e.Y;
                double price = GetValueByY(ptM.Y);//where I am capturing the price
                DateTime time = GetTimeByX(ptM.X);//where I am capturing the time
                
                Print("spot.Y: "+spot.Y.ToString()+"   spot.Time: "+spot.Time.ToString()+"   spot.Color: "+spot.Color.ToString());
                spot.Y=Instrument.MasterInstrument.Round2TickSize(price);
                spot.Time=time;
                Print("price: "+price.ToString()+"   time: "+time.ToString());
                Print("");
                
                ChartControl.Refresh();
            }
    It is showing the price and time to be updating correctly. The problem is....the Dot disappears once it is updated...and never reappears. I thought maybe it was becoming transparent, but the output is saying the color is remaining the same. Why is this not working?

    #2
    Hello Antny,

    Thank you for the note.

    This code seems like it should be working. Can you please try to isolate the issue by first only changing the Y value, and if that works, try adding the date time adjustment? Perhaps you could change the dots parameters such that they do not depend on variables. You can do something like this when the
    mouse is clicked:

    Code:
                            
                            //Put this code in the mouse click method. 
                            //private bool flip; at class level
                            if(!flip)
    			{
    				dot = DrawDot("tag1", true, 0, High[0] + TickSize*2, Color.Red);
    				flip = true;
    			}
    			else
    			{
    				dot.Y = Low[0] - TickSize*2; //= DrawDot("tag1", true, 0, Low[0] - TickSize*2, Color.Red);
    				flip = false;
    			}
    It sounds like the dot is being drawn on some portion of the chart that is not visible, or the chart is not updating properly.

    I look forward to hearing of your results.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_ChrisL, I added the code you recommended and it works perfectly fine. I then substituted my price variable for your "Low[0]-TickSize*2" code...and it worked as expected. Following this, i commented out the price change, and made the change to the time...and the disappearing began again. I am still checking the time to make sure it is correct (and it is). Any ideas?

      EDIT: Additionally, I tried this with my original code and had the exact same response. The problem occurs only when the time is adjusted.

      2nd EDIT: I tried substituting my time variable into the DrawDot() method in your flip code, and it worked exactly as expected. So, it is definitely providing the correct time.
      Last edited by Antny; 05-02-2018, 02:13 PM.

      Comment


        #4
        Hello Antny,

        Thanks for the reply.

        We recommend you should redraw the object with all of the parameters adjusted instead of modifying the current draw object. I will continue to test this and add a feature request to have this changed if this is the expected behavior of simply changing the DateTime value of the drawing object.

        EX:
        ...
        once=true;
        spot=DrawDot("spot",false,Time[0],High[0],Color.Blue);
        ...

        private void PMLBD(object s, System.Windows.Forms.MouseEventArgs e)
        {
        ...
        //spot.Y=Instrument.MasterInstrument.Round2TickSize( price);
        //spot.Time=time;
        spot=DrawDot("spot",false,TimeVar, yVar,Color.Blue);
        ...
        }

        Please let us know if we may be of any further assistance.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          NinjaTrader_ChrisL, For my test code, that is no big deal. For the project I am in the middle of...not so much. That will require me to rewrite about 5000 lines of code. So ...yeah...that is an option. But, before I start that painful process...about how long would it be before this bug is fixed?

          Comment


            #6
            Hello Antny,

            Thanks for the reply.

            We recommend calling the draw method again if you need to update a drawing object. I will submit a feature request to have this feature added in NinjaScript and follow up with a feature tracking ID.

            Thanks in advance for your patience on this item.
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by funk10101, Today, 09:43 PM
            0 responses
            6 views
            0 likes
            Last Post funk10101  
            Started by pkefal, 04-11-2024, 07:39 AM
            11 responses
            37 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