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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    49 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    69 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    36 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    96 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    59 views
    0 likes
    Last Post PaulMohn  
    Working...
    X