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 Brevo, Today, 01:45 AM
        0 responses
        3 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        3 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        238 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        384 views
        1 like
        Last Post Gavini
        by Gavini
         
        Started by oviejo, Today, 12:28 AM
        0 responses
        6 views
        0 likes
        Last Post oviejo
        by oviejo
         
        Working...
        X