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 mmckinnm, Today, 01:34 PM
        0 responses
        2 views
        0 likes
        Last Post mmckinnm  
        Started by f.saeidi, Today, 01:32 PM
        0 responses
        2 views
        0 likes
        Last Post f.saeidi  
        Started by traderqz, Today, 12:06 AM
        9 responses
        16 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by kevinenergy, 02-17-2023, 12:42 PM
        117 responses
        2,766 views
        1 like
        Last Post jculp
        by jculp
         
        Started by Mongo, Today, 11:05 AM
        5 responses
        15 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X