Announcement

Collapse
No announcement yet.

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.

    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        650 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        370 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        577 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X