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

LabeledHorizontalLine value update problem via INotifyPropertieChange

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

    LabeledHorizontalLine value update problem via INotifyPropertieChange

    Hi, I have made an attempt to update the price of the "LabeledHorizontalLine" from NinjaTrader_Jim (https://ninjatraderecosystem.com/use...-drawing-tool/), via "INotifyPropertieChange". This goes so far perfectly, until one calls the menu of the line and confirms with "OK", then the "INotifyPropertieChange" event is no longer executed, can someone give me a tip? I have also made a short video, so you can see it better, what I mean: http://www.youtube.com/watch?v=67tA69wJsFM

    Note: Put the file "LabeledLines.cs" into the "DrawingTools" and the file "INotifyPropertieChangeTest.cs" into the "Indicators" directory.
    Attached Files
    sidlercom80
    NinjaTrader Ecosystem Vendor - Sidi Trading

    #2
    Hello sidlercom80,

    As a tip, to export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...-us/export.htm


    Below I am providing a link to an example of implementing a property changed event in a drawing tool.


    Note, the code used here not be documented and would be advanced C# not fully supported by the NinjaScript Engineering Support team.
    There can be limitations using advanced C# concepts in NinjaScript, so your mileage may vary.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB, thank you for your answer, unfortunately this does not help me. Exactly your suggestion with the link you have posted above, I already use. I have now packed the "LabeledLines.cs" from NinjaTrader_Jim and the "SamplePropertyChangedIndicator.cs" in a .zip for testing. I have changed both files accordingly, as I want to use them. The problem, as already described at the beginning, is that when the menu of the line is opened and confirmed with "OK", the property changed event no longer works. In your example (link) only Drawing Tools that are drawn by hand are used. I have the line drawn via indicator, so I suspect that the problem is somewhere there, but where?

      Code:
      protected override void OnBarUpdate()
      {[INDENT]labeledHorizontalLine = DrawLL.LabeledHorizontalLine(this, "TestLine", 3880, Brushes.Red);[/INDENT][INDENT]if (labeledHorizontalLine == null)[/INDENT][INDENT]return;[/INDENT][INDENT]labeledHorizontalLine.IsLocked = false;[/INDENT][INDENT]labeledHorizontalLine.PropertyChanged += PropertyChangedInIndicator;[/INDENT]
       
       }
      Click image for larger version  Name:	Screenshot_1.jpg Views:	0 Size:	83.8 KB ID:	1207867

      i have made another short video showing the problem: http://www.youtube.com/watch?v=Q4jQAv4LBhU
      Last edited by sidlercom80; 07-08-2022, 03:49 AM.
      sidlercom80
      NinjaTrader Ecosystem Vendor - Sidi Trading

      Comment


        #4
        Hello sidlercom80,

        Clicking OK would only trigger the event if a property was changed that has the DoPropertyChanged() called in the setter.

        What property are you changing and expecting an event for? Do you have DoPropertyChanged() called in the setter for that property?

        In the SamplePropertyChangedDrawingTool the OnMouseDown() sets the DrawingStateSpy property which triggers DoPropertyChanged() in the setter for the public DrawingStateSpy. This triggers the property changed event, which propagates to the indicator which is subscribed to the event.
        So on mouse down, if the drawing tools DrawingState is changed, the DrawingStateSpy property is changed to the new DrawingState, and this causes the setter to call DoPropertyChanged() for that property.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi ChelseaB, I have only transferred the "SamplePropertyChangedDrawingTool.cs" into the "LabeledLines.cs" and adapted the "SamplePropertyChandedIndicator.cs" accordingly. I have these two files here as . zip to import. As I said, when I open the "Drawing Objects" menu and click on "OK", or change a value and press "Apply", the line no longer responds to the PropertyChanded event.
          Attached Files
          Last edited by sidlercom80; 07-11-2022, 12:23 AM.
          sidlercom80
          NinjaTrader Ecosystem Vendor - Sidi Trading

          Comment


            #6
            Hello sidlercom80,

            This would be expected. Clicking OK or Apply is not a property change.

            The example script only triggers property changed events for the DrawingStateSpy and IsSelectedSpy properties when these change, as a demonstration.

            If you want a trigger when a different property changes, add the DoPropertyChanged() call to the setter for that property.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi ChelseaB, yes I understand that. I don't understand what you mean, and I think you didn't look at my last example "SamplePropertyChanged_Test.zip", can that be ;-) If I close the window after clicking "OK or APPLY", I expect the PropertyChanged event to work exactly the same as before opening and closing the window. When the line is clicked (is selected), the PropertyChangedEvent for "IsSelectedSpy" should be executed, which it doesn't do anymore.
              sidlercom80
              NinjaTrader Ecosystem Vendor - Sidi Trading

              Comment


                #8
                Hello sidlercom80,

                To confirm, this does not affect the original example, and only affects your custom script?

                It would not be expected for the DrawingStateSpy or IsSelectedSpy properties to trigger the PropertyChanged event when clicking OK or Apply because these properties will not have changed.

                These properties will change when the drawing state changes (meaning going to editing mode or back) and when the drawing object is clicked on and the selection anchors appear. Unfortunately, this will not happen when clicking OK or Apply. You change a different property in the Drawing Objects window and when that property changes you can trigger the PropertyChanged event when clicking OK or Apply.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi _ChelseaB, That is clear to me
                  It would not be expected for the DrawingStateSpy or IsSelectedSpy properties to trigger the PropertyChanged event when clicking OK or Apply because these properties will not have changed.
                  I found why it doesn't work in my script. I didn't include the "ChartObjects.CollectionChanged" event because I thought if the line is drawn via indicator and not by hand, I don't need it.
                  Code:
                  protected override void OnBarUpdate()
                  {[INDENT]if (State != State.Realtime)[/INDENT][INDENT]return;
                  [/INDENT][INDENT]if (!isCreated)
                  {[/INDENT][INDENT=2]labeledHorizontalLine = DrawLL.LabeledHorizontalLine(this, "TestLine", 4300, Brushes.Red);
                  labeledHorizontalLine.IsLocked = false;
                  labeledHorizontalLine.PropertyChanged += PropertyChangedInIndicator;
                  isCreated = true;[/INDENT][INDENT]}
                  
                  Print(labeledHorizontalLine.StartAnchor.Price);[/INDENT]
                   }
                  I don't understand why the line has to be reassigned and a new "PropertyChanged" created
                  just because the drawingtool menu window is closed. The line was not deleted or changed before and should just be handled as before, the drawingtool menu was opened without doing anything.


                  My question is, why do I need the "ChartObjects.CollectionChanged" event, if i neither add nor remove a line, but just open and close the drawingtool menu. Why is the price not updated afterwards (like in this example)? The line is still there.
                  Attached Files
                  sidlercom80
                  NinjaTrader Ecosystem Vendor - Sidi Trading

                  Comment


                    #10
                    Hello sidlercom80,

                    You are asking why you have to add an event handler method to an objects event to trigger the method when the event occurs?
                    Without an event handler method assigned, no method would run when the event triggers.

                    Where you mention: "I don't understand why the line has to be reassigned and a new "PropertyChanged" created", are you asking why the PropertyChanged event has to be created in the drawing object script code?
                    Without the PropertyChanged event, it would not be possible to trigger a method when a property changes as there would be no event for it.

                    Where you mention: "why do I need the "ChartObjects.CollectionChanged" event, if i neither add nor remove a line, but just open and close the drawingtool menu."
                    Are you referring to this code?
                    Code:
                    // I opted to use ChartObjects.CollectionChanged here to detect new drawing objects
                    // + subscribe to them in the HandleChartObjectsChanged method
                    // rather than do this in the performance killer i.e., OnRender()
                    foreach (ChartScale cs in ChartControl.ChartPanels.SelectMany(cp => cp.Scales))
                    cs.ChartObjects.CollectionChanged += HandleChartObjectsChanged;
                    This code adds an event handler when the ChartObjects collection changes, and runs through the chart objects to add (or remove) the PropertyChanged event handler method to each objects PropertyChanged event.

                    If the object is not drawn by a script and was manually drawn, the event handler could just be added in State.Historical.

                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi ChelseaB,

                      I've picked up the sample code from this thread and adapted it a little to check if the PropertyChanged event is called properly when using global drawn lines/objects.

                      So I've setup two ES 09-2022 charts (side by side).
                      - The left chart with the sample indicator from attached zip - this draws a test line @3950 on the chart.
                      - The right chart (without any indicator on it) also shows that @3950 test line now (because of global drawing).

                      Now open the output window please:
                      - Whenever the test line from the right chart is moved the PropertyChanged event ("AnchorPriceSpy") is not fired at first. The event will only be triggered again when the line is selected/moved again but now the old price (from the move before) is returned (see Output window for that).
                      Attached Files
                      Last edited by Heart; 07-27-2022, 10:33 AM.

                      Comment


                        #12
                        Hello Heart,

                        I am not able to reproduce this behavior.

                        Below is a link to a video of testing it.


                        From the video, it shows the modified price the moment the mouse is up.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi NinjaTrader_ChelseaB , Heart is right, I can recreate this exactly as he wrote it. ChelseaB you have not read his message well enough, please read them again carefully. He has written that two charts are open, in the left chart is the indicator and in the right chart is no indicator. This is crucial! Only one chart is not a problem.
                          sidlercom80
                          NinjaTrader Ecosystem Vendor - Sidi Trading

                          Comment


                            #14
                            Hello sidlercom80,

                            I am only testing the drawing object added by the indicator to the chart the indicator is applied to (and not ones on other charts) because this is the object that has the property changed handler applied to it.

                            Drawing objects generated for other charts because of the global property, would be clones and would not be the drawing object that has the property changed handler applied to it.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hello ChelseaB,
                              Drawing objects generated for other charts because of the global property, would be clones and would not be the drawing object that has the property changed handler applied to it.
                              I know that.

                              If the line in the chart without indicator is shifted, the line in the chart with indicator is also shifted. Thus, the propertie changed event is triggered and should also transmit the price correctly, which it does not.
                              sidlercom80
                              NinjaTrader Ecosystem Vendor - Sidi Trading

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cre8able, 04-17-2024, 04:16 PM
                              7 responses
                              61 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by Aviram Y, 08-09-2023, 09:04 AM
                              11 responses
                              299 views
                              0 likes
                              Last Post arjandezeeuw  
                              Started by Christopher Leggit, 02-15-2024, 09:00 AM
                              3 responses
                              45 views
                              0 likes
                              Last Post rdtdale
                              by rdtdale
                               
                              Started by DavidHP, Today, 07:56 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post DavidHP
                              by DavidHP
                               
                              Started by jpapa, Today, 07:22 AM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X