Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Best Practices for Chart Buttons Click Events

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

    Best Practices for Chart Buttons Click Events

    Hi,

    I refer to the sample code for drawing buttons on the chart:
    https://ninjatraderecosystem.com/use...jE3MjQxNTUwNTk.

    Basically, the buttons are drawn within:
    PHP Code:
                else if (State == State.Historical) 
    

    which runs a separate method:
    PHP Code:
            private void OnButtonClick 
    

    , which triggers a boolean longButtonClicked to true if the buy button is clicked.

    In OnBarUpdate, every bar update checks for the conditions whereby longButtonClicked is true, and bar conditions relating to High[0], High[1] and Low[1] are met. If so, a long position is entered.



    Say for my situation, I run Caculate.OnPriceChange, and I do not wish to check for any bar conditions. When I click on the Buy button, I want the long position to be entered as soon as possible.

    Do I still need to route the logic through OnBarUpdate?


    If I just enter long from:

    PHP Code:
            private void OnButtonClick 
    

    and bypassing OnBarUpdate altogether, would it cause any problems?

    What is the best practice?


    Appreciate your assistance.

    #2
    Hello Rainmakersg,

    In thatt use case you can just put the order entry code directly into the button event handler. The only item to consider would be if you need prices for orders like for a limit price, if so you need to put that code inside of a TriggerCustomEvent



    private void OnButtonClick()
    ​{
    TriggerCustomEvent(o =>
    {
    //your code here
    }, null);​
    }

    https://ninjatrader.com/support/help...tsub=TriggerCu stomEvent

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    576 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    334 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    553 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    551 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X