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

Class properties not correct in clicked button?

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

    Class properties not correct in clicked button?

    I have an indicator that has a buy and sell button in it's panel.
    The buttons are created there using ChartControl.Dispatcher.InvokeAsync((Action), no problems there.

    If I click on one of the buttons and I print the High[0], Low[0] and a custom property Offset, it shows complete wrong values.
    The custom Offset is always 0, and the High[0] and Low[0] are waaaayyy off (like 3290 instead of 3306,25 for ES).

    If I print the same properties in OnBarUpdate they're correct.
    What can be the issue here?

    #2
    Hello wjadevries,

    Thank you for your post.

    When you are using a custom event outside of a data processing event you should use TriggerCustomEvent() to update the bars index to the current bar being updated. By doing this, we ensure that all internal indexers are up-to-date prior to processing logic triggered by your custom event.

    Please review the examples in the help guide link below to see how TriggerCustomEvent() is used.

    TriggerCustomEvent() - https://ninjatrader.com/support/help...ustomevent.htm

    Please let us know if we may assist further.

    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      This helps for the Bars (High/Low/Open/Close), but doesn't help for my custom property 'AutoTradeOffset'.
      Since the button_click event handler is probably already in a different thread, it looks like firing TriggerCustomEvent(longButtonClicked,0,AutoTradeOf fset); does still pass 0 for the AutoTradeOffset (eventhough it is 2).

      My code is now:

      protected void longButton_Click(object sender, RoutedEventArgs rea)
      {
      TriggerCustomEvent(longButtonClicked,0,AutoTradeOf fset);
      }

      protected void longButtonClicked(object offset)
      {
      Print(string.Format("High: {0} Low: {1} Offset:{2}", High[0], Low[0], (int)(AutoTradeOffset)/4));
      //high and low are now correct.
      //AutoTradeOffset isn't
      }

      Where the longButton_Click is the event handler for the button in the panel.

      Any idea how to make sure that all indicator properties (thus also my custom 'AutoTradeOffset' property) are available in the longButtonClicked function?

      Comment


        #4
        Sorry, my mistake!
        It did work, thanks a lot!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by popecapllc, 08-09-2023, 07:42 PM
        8 responses
        1,354 views
        0 likes
        Last Post Johng22
        by Johng22
         
        Started by ETFVoyageur, 04-30-2024, 02:04 PM
        11 responses
        101 views
        0 likes
        Last Post ETFVoyageur  
        Started by bubblegum, 03-18-2024, 10:41 AM
        3 responses
        46 views
        0 likes
        Last Post vjsworld  
        Started by JamesK1, Today, 02:48 PM
        1 response
        13 views
        0 likes
        Last Post JamesK1
        by JamesK1
         
        Started by llanqui, Today, 03:51 PM
        0 responses
        13 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Working...
        X