Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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:

        Hello All, Moving forward this will be maintained in the help guide reference samples and no longer maintained on the forum. Creating Chart WPF (UI) Modifications from an Indicator - https://ninjatrader.com/support/help...ui)-modifi.htm (https://ninjatrader.com/support/helpGuides/nt8/creating-chart-wpf-(ui)-modifi.htm) I've


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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Perr0Grande, Today, 08:16 PM
        0 responses
        2 views
        0 likes
        Last Post Perr0Grande  
        Started by elderan, Today, 08:03 PM
        0 responses
        4 views
        0 likes
        Last Post elderan
        by elderan
         
        Started by algospoke, Today, 06:40 PM
        0 responses
        10 views
        0 likes
        Last Post algospoke  
        Started by maybeimnotrader, Today, 05:46 PM
        0 responses
        11 views
        0 likes
        Last Post maybeimnotrader  
        Started by quantismo, Today, 05:13 PM
        0 responses
        7 views
        0 likes
        Last Post quantismo  
        Working...
        X