• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entering a position OnButtonClick

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

    Entering a position OnButtonClick

    Hello,


    I have figured out how to create buttons, and can get them to work to enter and exit positions OnBarUpdate, but the result of this is that I click the button and then the strategy waits until the end of the bar to actually go long or short. How do I have the order placed right when I click the button? Can Iput the code in the OnButtonClick section like this? It doesn't seem to be working.

    private void OnButtonClick(object sender, RoutedEventArgs rea)
    {

    if (shortButtonClicked)

    {
    EnterShort(Contracts, @"bearcrashOrder");
    }

    }

    If i move this to the OnBarUpdate section it works, it just waits to EnterShort until the end of the bar if the button is in the clicked state. I want it to enter short as soon as I click the shortButton.

    Thanks!


    #2
    Here is my whole OnButtonClick:

    private void OnButtonClick(object sender, RoutedEventArgs rea)
    {
    //Button Management

    System.Windows.Controls.Button button = sender as System.Windows.Controls.Button;
    if (button == longButton && button.Name == "LongButton" && button.Content == "LONG")
    {
    button.Content = "Exit L";
    button.Name = "ExitLongButton";
    longButtonClicked = true;
    return;
    }

    if (button == shortButton && button.Name == "ShortButton" && button.Content == "SHORT")
    {
    button.Content = "Exit S";
    button.Name = "ExitShortButton";
    shortButtonClicked = true;
    return;
    }

    if (button == longButton && button.Name == "ExitLongButton" && button.Content == "Exit L")
    {
    button.Content = "LONG";
    button.Name = "LongButton";
    longButtonClicked = false;
    return;
    }

    if (button == shortButton && button.Name == "ExitShortButton" && button.Content == "Exit S")
    {
    button.Content = "SHORT";
    button.Name = "ShortButton";
    shortButtonClicked = false;
    return;
    }

    // Entry

    if (shortButtonClicked)

    {

    EnterShort(Contracts, @"bearcrashOrder");

    }

    }

    Comment


      #3
      OMG i figured it out myself and i'm SO excited for buttons! In hind sight, obviously had to put the entry orders under the area where a specific button is being referenced.

      Comment


        #4
        Hi RobotSyndicate, thanks for your post.

        If you ever need a reference for buttons, this post from our colleague is a great reference to add to your notes:

        https://ninjatrader.com/support/foru...considerations

        Please let me know if you have any questions.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rontronimous, Today, 06:12 PM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Started by Vinhasa, Today, 03:15 PM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by 1001111, Today, 03:03 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Tyler  
        Started by Seedbird, Today, 03:06 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_BrendanC  
        Started by mtamaku, Today, 02:46 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Kate  
        Working...
        X