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

Place Order for Next Bar

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

    Place Order for Next Bar

    My strategy runs off a Range (4) chart with a .25 TickSize. The strategy involves placing Buy/Sell Stop orders one tick above/below the signal bars high/low.

    My problem:

    In fast markets the strategy will often get an invalid order message because the market has moved too fast.

    What I would like to do:

    Before the current bar, closes, if the strategy has a valid signal, I would like to place a pending order 1 tick above/below the bars predicted high/low to get in the trade on the next bar. Placing the order on the current bar for the next bar should avoid invalid orders in a fast market? If the new bar never hits the price, the order should be cancelled.

    For example using a long entry, the buy stop order price is calculated from the bars current low + (5*TickSize) because the bar will close no higher than the current low + 4 ticks.

    Because I don't know all the ins and outs of how NT places orders, I'm not sure if this is possible or if my 'solution' is a real solution or not.

    Thanks in advance.

    #2
    Hello Trader_Mark,

    Thanks for opening the thread.

    Before the current bar, closes, if the strategy has a valid signal, I would like to place a pending order 1 tick above/below the bars predicted high/low to get in the trade on the next bar. Placing the order on the current bar for the next bar should avoid invalid orders in a fast market? If the new bar never hits the price, the order should be cancelled.
    Placing an order safely 1 tick above the market price is difficult to manage when considering slippage. Your idea to "predict" where the market might be and place an order at that price is a good shot to try and get the order in before the market disallows the submission.

    As we cannot predict when the last tick of a bar will come in, you will have to come up with your own reliable way to submit your order during the development of the current bar.

    Some ideas would include...
    • Running the strategy with Calculate.OnEachTick for intra-bar events and modifying the logic to have Calculate.OnBarClose events happen on IsFirstTickOfBar.
    • Using a custom timer event to trigger your order submission after some time passes after the last bar close.
    • Implement an additional data series for intra-bar granularity


    Here are some resources to review that can help you develop these ideas.

    Calculate - https://ninjatrader.com/support/help.../calculate.htm

    IsFirstTickOfBar - https://ninjatrader.com/support/help...ttickofbar.htm

    Custom Timer Event sample - http://ninjatrader.com/support/forum...ead.php?t=5965

    Multi Series NinjaScript documentation - https://ninjatrader.com/support/help...nstruments.htm

    Intra-bar granularity example - http://ninjatrader.com/support/forum...ead.php?t=6652

    Please let me know if I may be of further assistance.
    Last edited by NinjaTrader_Jim; 08-24-2017, 07:08 AM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thank you, I will check out those links.

      If we could consider for a moment that 1) Calculate.OnBarClose is specified and 2) the signal bar is the bar where all conditions are true for an order to be placed and it is the far right bar, bar[0].

      When the bar closes a new bar will be formed and I guess the order is placed. When placing the order and specifying the price, since we are still inside OnBarUpdate(), does referencing bar[0] in the order, such as Low[0] reference the signal bar Low or the new bar Low?

      Code:
      protected override void OnBarUpdate()
              {
                     .....<snip>.....
                     // Set 1
                      if ((amaSuperTrendU111.Trend[1] == -1 && amaSuperTrendU111.Trend[0] == 1) // trend change, down to up, possible this bar
                          && (Low[0] + (4*TickSize) > amaSuperTrendU111.ReversePrice) // the high/close of this bar could cross the supertrend stop line
                          
                          && (StochasticsFast1.D[0] > 20)
                          && ((StochasticsFast2.D[0] > StochasticsFast1.D[0]) || (StochasticsFast1.D[0] > 80))
                          )
                      {
                          EnterLongStopMarket(Convert.ToInt32(DefaultQuantity), Low[0] + (5*TickSize), @"StrategyLong");
                      }

      Comment


        #4
        Hello Trader_Mark,

        When using Calculate.OnBarClose, referencing a price object with a barsago of 0 would represent the bar that just completed and has been 'closed.'

        When using Calculate.OnEachTick, referencing a price object with a barsago of 0 would represent the current developing bar.

        I forgot to provide additional information on doing this with a Multi Series NinjaScript. The idea would be to implement an additional data series with finer granularity and to do certain actions on the BarsInProgress of that data series. I would suggest to review the "True Event Driven OnBarUpdate() Method" section of the Multi Time Frame and Instruments section of the help guide for implementation.

        True Event Driven OnBarUpdate() Method: https://ninjatrader.com/support/help...arupdateMethod

        I have also updated my previous message with links to the Multi Time Frame and Instruments section of the help guide and with a sample that adds an additional data series. The sample is used to describe submitting orders to a secondary data series, but is also useful for seeing a working implementation of a Multi Series script.

        If you have any additional questions on the provided material, please don't hesitate to ask.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Jon17, Today, 04:33 PM
        0 responses
        1 view
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        4 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Started by alifarahani, Today, 09:40 AM
        6 responses
        40 views
        0 likes
        Last Post alifarahani  
        Started by Waxavi, Today, 02:10 AM
        1 response
        19 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Working...
        X