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

Placing limit orders from OnStateChanged

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

    Placing limit orders from OnStateChanged

    hello,

    i have a strategy in which I would like to configure the stop, target and order just one time. This is because I only want to fire off one order ever during the running of the strategy. Since on OnBarUpdate runs frequently, it doesn’t seem to be The right place to launch my one limit order.

    here is some pseudo code for what I want to do:

    if (state == State.Configure) {
    SetStopLoss(xxxx);
    SetProfitTarget(xxxxx);
    EnterLimitLong(xxxxxx);
    }

    that way my order is fired off when the strategy starts and waits to be filled, after which the stop and target orders manage the order. Am I doing this right?

    thanks
    john

    #2
    Hello John,

    Yes, this would be correct. Set methods cannot be unset for a signal name. Once set they remain set. This means placing these in State.Configure (or State.DataLoaded) would be acceptable to only set these once.

    Below is a public link to the help guide which includes a code example.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      But is that also the right place to put my limit Order? I want only one execution of this limit order. It either hits or it doesn’t, so I don’t know if putting it in OnBarUpdate is the right place.

      Comment


        #4
        Hello John,

        No, your entry orders should be placed in OnBarUpdate when the conditions to place the order are true.

        Below is a link to a forum post with helpful information about getting started with NinjaScript.
        https://ninjatrader.com/support/foru...040#post786040

        And a link to the help guide on EnterLongLimit().
        https://ninjatrader.com/support/help...rlonglimit.htm

        If you want you make your condition placing the order on the first bar of historical data (which would be a historical order not a real-time order).
        if (CurrentBar == 1)

        Or you could place the order on the first real-time bar using a bool to ensure the order is only triggered once.

        private bool orderTriggered = false;

        protected override void OnBarUpdate()
        {
        if (orderTriggered == false && State == State.Realtime)
        {
        // call order method
        orderTriggered = true;
        }
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Excellent, thank you

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by rbeckmann05, Today, 06:48 PM
          0 responses
          1 view
          0 likes
          Last Post rbeckmann05  
          Started by rhyminkevin, Today, 04:58 PM
          4 responses
          52 views
          0 likes
          Last Post dp8282
          by dp8282
           
          Started by iceman2018, Today, 05:07 PM
          0 responses
          5 views
          0 likes
          Last Post iceman2018  
          Started by lightsun47, Today, 03:51 PM
          0 responses
          7 views
          0 likes
          Last Post lightsun47  
          Started by 00nevest, Today, 02:27 PM
          1 response
          14 views
          0 likes
          Last Post 00nevest  
          Working...
          X