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

NinjaScript Logic to Enter Market Order On Next Bar Open/Close, etc.

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

    NinjaScript Logic to Enter Market Order On Next Bar Open/Close, etc.

    Version: NT 8.0.23.2
    Chart type used: Tick chart
    NinjaScript OnBarUpdate() interval: Calculate On Each Tick

    Using NinjaScript, is there any way to submit a market order that executes on the open of the upcoming/next bar? For example:

    Say I have a strategy that calculates on each tick and generates an intra-bar 'buy' or 'sell' condition that executes a market order "EnterLong() or EnterShort()" -- In live testing, this will execute an order immediately upon meeting the buy or sell condition. Ideally, I want to be able to precisely control when the strategy enters an order while still assessing the data on a tick-by-tick basis (similar to the MultiCharts function 'OrderCreator.MarketNextBar'). I've attempted to code around it with a tick counter and a boolean for the buy/sell condition that essentially holds the script in a loop until the bar -- which triggered the condition -- is finished; then Enter (Market Order) long/short... However, there's got to be a better, easier way to do this.

    Please advise, or create a feature request to add additional market entry functions to allow "quant/algo" traders to finely tune their entry times (i.e. EnterLongNextBarOpen(), EnterLongNextBarClose(), EnterLongThisBarClose() -- same for short side of course).

    Thanks!

    #2
    Hello afcmaff,

    Thanks for your post.

    Please review the bool IsFirstTickOfBar as a possible solution: https://ninjatrader.com/support/help...ttickofbar.htm

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi NinjaTrader_PaulH, Thanks for your quick response.

      I've used IsFirstTickOfBar several times... this can certainly be utilized in a workaround for determining if a new bar has started; however, that's not what I'm referring to, and using that function increases entry-risk. Right now, I have to implement a boolean placeholder to determine the signal direction (long/short), in combination with a tick counter to determine the number of ticks remaining in a bar from the moment a signal is generated -- i.e. current intra-bar signal triggered -> once this bar is expired, enter a market order.

      IsFirstTickOfBar can be used, but it is purely conditional and not directive... meaning if 'IsFirstTickOfBar' is assessed during the tick-by-tick signal logic, it will almost always return false. The signal logic and the entry function are basically mutually exclusive in a sense -- Example:

      if(Position.MarketPosition == MarketPosition.Flat)
      {
      if(<entry logic>){varEntry = true;}
      if(varEntry){
      if(tickCounter = 1 <-- this could also be "IsFirstTickOfBar"){EnterLong();}
      }
      }
      }

      In the rare case that a signal is generated on the first tick of a bar, and the IsFirstTickOfBar is assessed, then the order will be entered immediately; whereas, I want to enter on the open of the following bar. I guess what I'm asking for is an order-entry function that queues up a market order on the first tick of the 'next' bar from which the signal was created, without disrupting the OnBarUpdate() "Calculate.OnEachTick" functionality. Does that make sense?

      Thanks again.

      Comment


        #4
        Hello afcmaff,

        Thanks for your reply.

        I guess I was thinking more along the lines that your entry condition occurs where/when it occurs but instead of an entry order you simply set a bool true and then combined with IsFirstTickOfBar to then place the order, at the first tick of the bar, for example:

        if (your entry conditions true && doitonce)
        {
        doitonce = false; // only do this once per bar to prevent multiple intrabar orders
        placeOrder = true; // set the condition for the entry on the next bar
        }

        if (IsFirstTickOfBar && placeOrder)
        {
        // order entry here
        placeOrder = false;
        doitonce = true;
        }

        Does that sound more like what you are after?
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          NinjaTrader_PaulH,

          Yes, that is correct. It's an okay workaround, but has it's issues... and of course, the logic should be only applied to State.Realtime since historical fills already do this by default when back-testing (order fill occurs on the open of the following bar since tick resolution isn't accounted for with the historical bar formation algorithm).

          It would be best if there were a simple solution that could securely implement the workaround into a single function that would be able to operate on a tick-by-tick resolution and still be able to place orders on an OHLC basis (specifically Enter at... 'Open next bar', 'Close this bar', and 'Close next bar').

          Thanks.

          Comment


            #6
            Hello afcmaff,

            Thanks for your reply.

            I will write up a feature request as you originally suggested just so we get that in the feature request system. Please note that having a feature request does not mean the feature will or will not be implemented.

            I will update this thread when I have the feature request information (may take some time).
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hello afcmaff,

              The feature request is identified as SFT-5205, "Additional NinjaScript order entry methods". This forum thread and all posts are included with the feature request.

              Feature Request Disclaimer
              We receive many requests and cannot reasonably implement all requested features or changes. Interest is tracked internally and if enough interest is tracked, it would be weighed against how feasible it would be to make those changes to consider implementing.
              When new features are implemented, they will be listed in the Release Notes page of the Help Guide. The ID number will be different than the internal feature request tracking ID, but the description of the feature will let you know if that feature has been implemented.
              Release Notes - https://ninjatrader.com/support/help...ease_notes.htm
              Paul H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by AaronKoRn, Today, 09:49 PM
              0 responses
              11 views
              0 likes
              Last Post AaronKoRn  
              Started by carnitron, Today, 08:42 PM
              0 responses
              10 views
              0 likes
              Last Post carnitron  
              Started by strategist007, Today, 07:51 PM
              0 responses
              11 views
              0 likes
              Last Post strategist007  
              Started by StockTrader88, 03-06-2021, 08:58 AM
              44 responses
              3,980 views
              3 likes
              Last Post jhudas88  
              Started by rbeckmann05, Today, 06:48 PM
              0 responses
              9 views
              0 likes
              Last Post rbeckmann05  
              Working...
              X