• 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

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.
    https://ninjatrader.com/support/help...etstoploss.htm
    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 Austiner87, Today, 08:16 AM
          0 responses
          4 views
          0 likes
          Last Post Austiner87  
          Started by 7robert, Today, 07:27 AM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_PatrickG  
          Started by GLFX005, Today, 07:18 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by Erhard, Today, 04:24 AM
          4 responses
          22 views
          0 likes
          Last Post Erhard
          by Erhard
           
          Started by brunoviveiros, Today, 04:26 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X