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
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Thomas79, Today, 02:03 PM
    0 responses
    6 views
    0 likes
    Last Post Thomas79  
    Started by Mirasol, Today, 11:32 AM
    2 responses
    19 views
    0 likes
    Last Post Mirasol
    by Mirasol
     
    Started by Scalper1969, 10-09-2024, 10:37 AM
    13 responses
    46 views
    0 likes
    Last Post Scalper1969  
    Started by MikM45, 10-12-2024, 01:12 PM
    1 response
    18 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by CDXTrader, Today, 01:46 PM
    0 responses
    8 views
    0 likes
    Last Post CDXTrader  
    Working...
    X