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 Irukandji, Today, 04:58 AM
          0 responses
          0 views
          0 likes
          Last Post Irukandji  
          Started by fitspressoburnfat, Today, 04:25 AM
          0 responses
          2 views
          0 likes
          Last Post fitspressoburnfat  
          Started by Skifree, Today, 03:41 AM
          1 response
          4 views
          0 likes
          Last Post Skifree
          by Skifree
           
          Started by usazencort, Today, 01:16 AM
          0 responses
          1 view
          0 likes
          Last Post usazencort  
          Started by kaywai, 09-01-2023, 08:44 PM
          5 responses
          604 views
          0 likes
          Last Post NinjaTrader_Jason  
          Working...
          X