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

Order execution question

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

    Order execution question

    Hi, the code below is copied from Help Guide. Is it true for every bar update that satisfies the condition "Close[0] > SMA(20)[0]", a long market order will be submitted?

    protectedoverridevoidOnBarUpdate()
    {
    // Entry condition
    if(Close[0]>SMA(20)[0])
    EnterLong();
    }


    What about the follow code, Is it true for every bar update that satisfies the condition "Close[0] > SMA(20)[0]", a long market order with name LongSignal will be submitted?
    protectedoverridevoidOnBarUpdate()
    {
    // Entry condition
    if(Close[0]>SMA(20)[0])
    EnterLong("LongSIgnal");
    }


    #2
    Hello CougarMountain,

    Thanks for your post and welcome to the NinjaTrader forums!

    Yes, you are reading those examples correctly.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply, please review the code below. Let us assume the current bar's low is always higher that prior bar's low for all the bars, so the follow code will move up the price of the same limit order, or will it create a new limit order for every execution?

      protected override void OnBarUpdate()
      {
      // Entry condition
      if(Close[0]>SMA(20)[0])
      double limitPrice = Low[0] - 5.0;
      EnterLongLimit(0, true,1, limitPrice, "Limit Long" );
      }

      Comment


        #4
        Hi CougarMountain,
        It will create a new limit order for every execution. You can try this out as follows:
        Allow more than entry entry per direction (Strategy Analyzer - Order handling) and run a backtest.
        If you would like to take a deeper look, consider to add a Print statement to your code as shown in the attached, open an OutputWindow (New - NinjaScript Output), then run the backtest again.
        NT-Roland

        Comment


          #5
          Hello CougarMountain,

          Thanks for your post.

          I'm not sure if you intended this but the "if" statement is missing the encapsulation braces "{ }" that would contain both this statement double limitPrice = Low[0] - 5.0; as well as this statement EnterLongLimit(0, true,1, limitPrice, "Limit Long" ); That means that the statement EnterLongLimit(0, true,1, limitPrice, "Limit Long" ); would be executed on every OnBarUpdate(), regardless of the if statement.

          In the managed approach, if a limit order is not filled on the bar that it is placed, then the order is automatically canceled, however you are using the "advanced" order method which keeps the order alive until it is canceled by you (or filled). To answer your question, " Let us assume the current bar's low is always higher that prior bar's low for all the bars, so the follow code will move up the price of the same limit order, or will it create a new limit order for every execution?" In the cases where the order is not filled, as you are using the same entry name, the order is effectively replaced on the next issue of the order at the new limit level (Low[0] - 5 (btw -5 would be five points, if you wanted it to be 5 ticks you would use -5 * TickSize).

          To help illustrate "the order is effectively replaced on the next issue of the order at the new limit level" I've run a strategy with your conditions (added the braces) and also added a Draw.dot() to show on the chart what bars the condition if(Close[0]>SMA(20)[0]) is true on. Next I manually draw a ruler line from the entry back to the 1st red dot before the entry, at the low of the bar. The entries correspond to the last bar of the entry condition when price met the entry value of Low[0] - 5.0. If you look at the "Y value" in each box, you can see it is 5 (5 points below the low of the bar where it last closed above the SMA(20). If the limit order was not replaced when unfilled, you would have had a great many more entries showing on the chart.




          Click image for larger version

Name:	CougarMountain-1.PNG
Views:	349
Size:	157.5 KB
ID:	1075178




          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by AttiM, 02-14-2024, 05:20 PM
          12 responses
          213 views
          0 likes
          Last Post DrakeiJosh  
          Started by cre8able, 02-11-2023, 05:43 PM
          3 responses
          237 views
          0 likes
          Last Post rhubear
          by rhubear
           
          Started by frslvr, 04-11-2024, 07:26 AM
          8 responses
          116 views
          1 like
          Last Post NinjaTrader_BrandonH  
          Started by stafe, 04-15-2024, 08:34 PM
          10 responses
          47 views
          0 likes
          Last Post stafe
          by stafe
           
          Started by rocketman7, Today, 09:41 AM
          3 responses
          11 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X