Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy in NT8 with 1 minute granularity on the 15 minute graph don't work correctly

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

    Strategy in NT8 with 1 minute granularity on the 15 minute graph don't work correctly

    Hello,

    I have same a strategy in NT7 and in NT8.

    The strategy run on the 15 minutes graph, but I use 1 minute granularity for correct execution in back test in inside candles.

    See picture NinjaTrader8.png.

    Strategy bought contract at 577.0, and strategy set SL to 573.7.
    When you switch to minute graph, you see,
    that price minimum is in the 573.2 (under SL), and SL wasn't executed
    (please see NinjaTrader8.1.png).

    In NinjaTrader7.png is the same situation in NinjaTrader7.

    In strategy.zip is strategy.
    Attached Files
    Last edited by svopex; 10-11-2015, 02:34 PM.

    #2
    Hello svopex,

    I would need prints to see what happened with this exit order.

    From what I understand this is a 15 minute chart with a 1 minute added series.

    If running historically or with Calculate on bar close set to false, the exit should have filled using the 1 minute data, is this correct?

    I'd like to know if your code placed the order and if the order was accepted and then later cancelled.

    In the script, add a print to OnOrderUpdate so that we can watch the order flow to see if and when the order is placed and if and when the order is cancelled.
    Print(order.Name+" | "+order.ToString());
    http://ninjatrader.com/support/helpG...rderupdate.htm

    I also think you should add a print to OnBarUpdate. When the price reaches the price that should have filled the order, print the time so that we can compare this.

    if (BarsInProgress == 1 && Low[0] <= 573.7)
    {
    Print(Time[0]+" | "+price available to fill - "+Low[0]);
    }

    Then add the output from the output window to your next post.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      1.
      I must use CalculateOnBarClose=false (respective in NT8 this.Calculate=Calculate.OnEachTick)?
      In NT7 i have settings for this situation CalculateOnBarClose=true and everything works ok.

      I test it with "this.Calculate=Calculate.OnEachTick" too and problem still caused.

      2.
      I add additional logs messages by you helps.
      This is critical area from the log:

      !STOP_ORDER_c7991bddc65b4078abbdbfd1756db8ee | orderId='NT-01175-34' account='Sim101' name='STOP_ORDER_c7991bddc65b4078abbdbfd1756db8ee' orderState=Accepted instrument='TF 12-15' orderAction=Buy orderType='Stop Market' limitPrice=0 stopPrice=571.6 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 id=-1 gtd='2099-12-01'

      !STOP_ORDER_c7991bddc65b4078abbdbfd1756db8ee | orderId='NT-01175-34' account='Sim101' name='STOP_ORDER_c7991bddc65b4078abbdbfd1756db8ee' orderState=Working instrument='TF 12-15' orderAction=Buy orderType='Stop Market' limitPrice=0 stopPrice=571.6 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 id=-1 gtd='2099-12-01'

      5/26/2010 4:15:00 PM | price available to fill - 557.9

      !STOP_ORDER_c7991bddc65b4078abbdbfd1756db8ee | orderId='NT-01175-34' account='Sim101' name='STOP_ORDER_c7991bddc65b4078abbdbfd1756db8ee' orderState=Filled instrument='TF 12-15' orderAction=Buy orderType='Stop Market' limitPrice=0 stopPrice=571.6 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=577 id=-1 gtd='2099-12-01'

      !1577 | 3.3

      Strategy 'TomNesBossOriginal/56132818': A Sell stop order placed at '5/26/2010 4:15:00 PM' has been ignored since the stop price is less than or equal to the close price of the current bar. This is an invalid order and subsequent orders may also be ignored. Please fix your strategy.

      !2577 | 3.3

      5/27/2010 9:52:00 AM | price available to fill - 573.3

      5/27/2010 9:53:00 AM | price available to fill - 573.7

      5/27/2010 9:54:00 AM | price available to fill - 573.7
      SL not placed, ok, but why?

      This line in strategy:
      orderSL = this.SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.StopMarket, 1, 0, Instrument.MasterInstrument.RoundToTickSize(orderE ntry.AverageFillPrice - SL), "", SvopexTools.GetOrderName("STOPLOSS_ORDER"));
      Show this message:
      Strategy 'TomNesBossOriginal/56132818': A Sell stop order placed at '5/26/2010 4:15:00 PM' has been ignored since the stop price is less than or equal to the close price of the current bar. This is an invalid order and subsequent orders may also be ignored. Please fix your strategy.
      Why I cannot place sell stop market order under the close price of the current bar?

      "OrderType.Stop" in NT7 is the same as "OrderType.StopMarket" in NT8?

      Thanks for answer Petr
      Last edited by svopex; 10-12-2015, 10:55 AM.

      Comment


        #4
        Hi svopex,

        So the price at 4:15:00 PM is 557.9.

        At what price are you trying to submit this order? Is this price below 557.9? (Possibly the error message says less than or equal to but may have a typo and should actually say that the order price is actually above the current price.)

        I have made a test script that places an entry buy order and then a sell stop market below the current price. Does this test script can an error on your end?
        Does this test script place the stop market order ok?
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello,
          I use your example for test.
          This test works ok.
          I make your test more difficult and there is results:

          If strategy (in strategy.txt) run with uncommented VARIANT 2 line, sell stop market not executed and NT8 show message
          "Strategy 'SellStopMarketTest/56226344': A Sell stop order placed at '5/26/2010 4:15:00 PM' has been ignored since the stop price is less than or equal to the close price of the current bar. This is an invalid order and subsequent orders may also be ignored. Please fix your strategy.".
          (variant_2.png).

          If strategy (in strategy.txt) run with uncommented VARIANT 1 line, everything work ok.
          (variant_1.png).

          By my opinion Buy StopMarket order causes crash NEXT Sell StopMarket order.
          If I use Buy Market order, NEXT Sell StopMarket order is ok.

          I use CQG connection, TF, 15 minutes, 1.1.2010 - 1.1.2015, trading_hours.png.
          Attached Files
          Last edited by svopex; 10-13-2015, 12:54 PM.

          Comment


            #6
            Hello svopex,

            What is the price of the stop that is being rejected. What is the current price at that exact time the order is being submitted? (not after, but one line before the submission of the order)

            Please add prints to your code and post the results of the print from the output window.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello,

              situation has shown at prices.png from attachment...

              Answers to you question:
              What is the price of the stop that is being rejected? 573.7
              What is the current price at that exact time the order is being submitted? Time[0] = 4:15pm, Close[0] = 558.4 but actual price on the stock is 577.1 and real time is 9:45am by traiding_hours.png. There is gap!

              All prices:
              Close[0] 4:15pm is 558.4.
              FIRST ORDER - Buy StopMarket Stop price = 564.9.
              FIRST ORDER filled at = 577.1 (when i use market or when i use buy stopmarket too)
              SECOND ORDER - Sell StopMarket price = 573.7.
              Actual price on the stock = 577.1.

              OnBarUpdate of 4:15pm candle run next day at 9:45am (see trading_hours.png).

              FIRST ORDER:
              orderEntry = SubmitOrderUnmanaged(1, OrderAction.Buy, OrderType.StopMarket, 1, 0, Instrument.MasterInstrument.RoundToTickSize(564.9)) filled at 577.1.

              SECOND ORDER:
              orderSL = this.SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.StopMarket, 1, 0, Instrument.MasterInstrument.RoundToTickSize(573.7), "", "STOPLOSS_ORDER");
              show error message.

              If I change FIRST ORDER to "buy market" from "buy stop market", SECOND ORDER go to state=working, everything is ok... FIRST ORDER filed too.

              Result of SECOND ORDER depend on the type of first order (market or stop market).

              Petr
              Attached Files
              Last edited by svopex; 10-14-2015, 01:06 PM.

              Comment


                #8
                Hello svopex,

                Do you have prints from the output window that you can include?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi svopex,

                  I ask because I have made a few changes to the prints and have the following output in the output window:

                  5/26/2010 4:15:00 PM Strategy 'SellStopMarketTest/56382015': Entered internal SubmitOrderUnmanaged() method at 5/26/2010 4:15:00 PM: BarsInProgress=1 Action=Buy OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=565.4 SignalName=''
                  5/26/2010 4:15:00 PM | orderId='NT-00000-23' account='Sim101' name='Buy' orderState=Working instrument='TF 12-15' orderAction=Buy orderType='Stop Market' limitPrice=0 stopPrice=565.4 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 id=-1 gtd='2099-12-01'|565.4
                  GetCurrentBid(): = 563.8 > newPrice: 562.1
                  5/27/2010 12:21:00 AM Strategy 'SellStopMarketTest/56382015': Entered internal SubmitOrderUnmanaged() method at 5/27/2010 12:21:00 AM: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=562.1 SignalName='STOPLOSS_ORDER'
                  5/27/2010 4:00:00 PM Strategy 'SellStopMarketTest/56382015': Entered internal SubmitOrderUnmanaged() method at 5/27/2010 4:00:00 PM: BarsInProgress=1 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=''
                  orderId='NT-00002-23' account='Sim101' name='Sell' orderState=Filled instrument='TF 12-15' orderAction=Sell orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=590.2 id=-1 gtd='2099-12-01'
                  orderId='NT-00001-23' account='Sim101' name='STOPLOSS_ORDER' orderState=Filled instrument='TF 12-15' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=562.1 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=562.1 id=-1 gtd='2099-12-01'
                  Enabling NinjaScript strategy 'SellStopMarketTest/56382015' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=False SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=True Calculate=On each tick IsUnmanaged=True MaxRestarts=4 in 5 minutes
                  This is letting me know that the order STOPLOSS_ORDER was accepted when placed. Also placed was an order named Sell. The Sell order exited the order. The STOPLOSS_ORDER filled after this causing the strategy to enter a short position.

                  A rejection did not occur. A screenshot of the chart is attached.

                  I am showing the output from the output window directly so you can match these with the prints in the file and understand what happened. From what I can see the order was not rejected. If the order is being rejected, it is likely not below the price properly.

                  In your output please enable TraceOrders = true; as this will show when (at what time) an order is rejected and why in the flow of the prints around it for a better picture of what is going on.
                  Attached Files
                  Last edited by NinjaTrader_ChelseaB; 10-15-2015, 08:12 AM.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello,

                    all information is in attachment.

                    I see to your graph and you have gap in another position.
                    I use New Yourk timezone - UTC-5. And i have set trading hours from atachment (trading_hours.png).
                    You must use it. By my opinion the problem maybe arises due the gap
                    (that Close[0] price <> actual price on the stock)...

                    If you can, I prepare this situation on the my virtual machine and you can see it here via RDC (https://www.youtube.com/watch?v=RJxgWPV0vi0).

                    5/26/2010 4:15:00 PM Strategy 'SellStopMarketTestModified/56392768': Entered internal SubmitOrderUnmanaged() method at 5/26/2010 4:15:00 PM: BarsInProgress=1 Action=Buy OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=565.4 SignalName=''

                    5/26/2010 4:15:00 PM | orderId='NT-00000-21' account='Sim101' name='Buy' orderState=Working instrument='TF 12-15' orderAction=Buy orderType='Stop Market' limitPrice=0 stopPrice=565.4 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 id=-1 gtd='2099-12-01'|565.4

                    GetCurrentBid(): = 558.4 > newPrice: 573.7

                    5/26/2010 4:15:00 PM Strategy 'SellStopMarketTestModified/56392768': Entered internal SubmitOrderUnmanaged() method at 5/26/2010 4:15:00 PM: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=573.7 SignalName='STOPLOSS_ORDER'

                    Strategy 'SellStopMarketTestModified/56392768': A Sell stop order placed at '5/26/2010 4:15:00 PM' has been ignored since the stop price is less than or equal to the close price of the current bar. This is an invalid order and subsequent orders may also be ignored. Please fix your strategy.

                    5/26/2010 4:15:00 PM Strategy 'SellStopMarketTestModified/56392768': Ignored SubmitOrderUnmanaged() method at 5/26/2010 4:15:00 PM: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=573.7 SignalName='STOPLOSS_ORDER' FromEntrySignal='' Reason='Invalid order price, please see log tab'

                    5/27/2010 4:00:00 PM Strategy 'SellStopMarketTestModified/56392768': Entered internal SubmitOrderUnmanaged() method at 5/27/2010 4:00:00 PM: BarsInProgress=1 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=''
                    orderId='NT-00001-21' account='Sim101' name='Sell' orderState=Filled instrument='TF 12-15' orderAction=Sell orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=590.2 id=-1 gtd='2099-12-01'

                    Enabling NinjaScript strategy 'SellStopMarketTestModified/56392768' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries
                    EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=False SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On each tick IsUnmanaged=True MaxRestarts=4 in 5 minutes
                    Petr
                    Attached Files
                    Last edited by svopex; 10-15-2015, 11:04 AM.

                    Comment


                      #11
                      Hi svopex,

                      With the output from the prints you have posted we can see the issue.

                      GetCurrentBid(): = 558.4 > newPrice: 573.7

                      You are placing a sell stop order above the market price. When the current market price is 558.4, your stop order must be below this price. 573.7 is an invalid price.

                      Try changing your calculation to ensure that your new sell stop price is below the current market bid price.

                      Submitting a sell stop order above the current bid (market price) will always cause the order to be rejected with an error. There is no way around this. You must choose a price that is less than the current bid.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello,

                        ok, thank for clarification of the problem, but it's problem for me.

                        Please see graph in attachment.

                        First order filled on 577.1 when candle open.
                        And I want to create stoploss under this order, at 573.7 (577.1 - 3.3).

                        I have question.
                        When first order filled at 577.1, how I create stoploss (as sell stop order) 3.3 point under this filled order?
                        I can create stoploss order under 558.4, but it's 577.1 - 558.4 = 18.7 points!

                        In NinjaTrader version 7 it works without any problem.
                        I found this problem when I compared the same strategy in NinjaTrader 7 and NinjaTrader 8. NT7/NT8 equity was not the same.

                        Thank for answer Petr
                        Attached Files
                        Last edited by svopex; 10-15-2015, 01:55 PM.

                        Comment


                          #13
                          Hello svopex,

                          If you want to compare the behavior between NinjaTrader 7 and NinjaTrader 8 you would need to make sure that every single bar of data is exactly the same.

                          Then I would add prints to the code to ensure that every variable is being set the same, has the same value when used in a condition, and that all actions are happening at the same time.

                          However, without attempting to compare, we can just find why this strategy is not behaving correctly.
                          When the order is about to be placed it uses this:
                          Instrument.MasterInstrument.RoundToTickSize(orderE ntry.AverageFillPrice - SL);

                          However, there is no check to see if this price is below the current bid. Meaning that this could be an invalid price.

                          To subtract 3.3 points from the entry price I would use:
                          newPrice = order.AverageFillPrice - Instrument.MasterInstrument.RoundToTickSize(SL / TickSize));
                          This would calculate 3.3 points to a number of ticks and then round to the closest tick then subtract this from your price.


                          Either way, prints are the best way to find out why your strategy is behaving the way it is behaving. Using a print you were able to determine why the order was being rejected. Its being rejected because it is being placed on the wrong side of the market. The print shows us the current market price and the price you are about to use for the order. This allows you to do the comparison yourself and understand if the order is at a valid price.


                          If you feel that the new calculated price is not 3.3 points below the entry price, print the average fill price and print the new calculated price next to it and see if the calculation was done correctly.
                          In other words you should be able to visually see the entry point, the calculated price, and the submission of the stop order all within the output window.

                          If you print the time (so that we know the prints are coming out at the same time), average fill price, and the new calculated price, is your calculated price 3.3 points below the average fill price?
                          Is this calculated price below the current bid?
                          May I see your prints so that I may also compare?
                          Last edited by NinjaTrader_ChelseaB; 10-16-2015, 08:53 AM.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            I send log for you:
                            Disabling NinjaScript strategy 'SellStopMarketTestModified/56392769'
                            ==========================================
                            FIRST ORDER
                            ==========================================
                            GetCurrentBid(): = 558.4 < firstOrderPrice: 565.4
                            Time[0] = 5/26/2010 4:15:00 PM
                            Close[0] = 558.4
                            firstOrderPrice565.4
                            5/26/2010 4:15:00 PM Strategy 'SellStopMarketTestModified/56392769': Entered internal SubmitOrderUnmanaged() method at 5/26/2010 4:15:00 PM: BarsInProgress=1 Action=Buy OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=565.4 SignalName='FIRST_ORDER'
                            ==========================================
                            ==========================================
                            STOPLOSSORDER
                            ==========================================
                            GetCurrentBid(): = 558.4 > stopLossOrderPrice: 573.7
                            Time[0] = 5/26/2010 4:15:00 PM
                            Close[0] = 558.4
                            TickSize = 0.1
                            SL = 33
                            orderEntry.AverageFillPrice = 577
                            SL * TickSize = 3.3
                            Instrument.MasterInstrument.RoundToTickSize(SL * TickSize) = 3.3
                            stopLossOrderPrice = orderEntry.AverageFillPrice - Instrument.MasterInstrument.RoundToTickSize(SL / TickSize) = 573.7
                            5/26/2010 4:15:00 PM Strategy 'SellStopMarketTestModified/56392769': Entered internal SubmitOrderUnmanaged() method at 5/26/2010 4:15:00 PM: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=573.7 SignalName='STOPLOSS_ORDER'
                            Strategy 'SellStopMarketTestModified/56392769': A Sell stop order placed at '5/26/2010 4:15:00 PM' has been ignored since the stop price is less than or equal to the close price of the current bar. This is an invalid order and subsequent orders may also be ignored. Please fix your strategy.
                            5/26/2010 4:15:00 PM Strategy 'SellStopMarketTestModified/56392769': Ignored SubmitOrderUnmanaged() method at 5/26/2010 4:15:00 PM: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=573.7 SignalName='STOPLOSS_ORDER' FromEntrySignal='' Reason='Invalid order price, please see log tab'
                            ==========================================
                            5/27/2010 4:00:00 PM Strategy 'SellStopMarketTestModified/56392769': Entered internal SubmitOrderUnmanaged() method at 5/27/2010 4:00:00 PM: BarsInProgress=1 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=''
                            orderId='NT-00001-34' account='Sim101' name='Sell' orderState=Filled instrument='TF 12-15' orderAction=Sell orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=590.2 id=-1 gtd='2099-12-01'
                            Enabling NinjaScript strategy 'SellStopMarketTestModified/56392769' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=False SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On each tick IsUnmanaged=True MaxRestarts=4 in 5 minutes
                            But calculation is SL (in ticks = 33) * TickSize (= 0.1) = 33 * 0.1 = 3.3 point...
                            Attached Files

                            Comment


                              #15
                              Hello,

                              I prepare for you testing space on my virtual PC.

                              There is launched NinjaTraders TeamViewer.

                              Login credentials I send for you to e-mail platformsupport@...

                              Petr

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by zstheorist, Today, 07:52 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post zstheorist  
                              Started by pmachiraju, 11-01-2023, 04:46 AM
                              8 responses
                              149 views
                              0 likes
                              Last Post rehmans
                              by rehmans
                               
                              Started by mattbsea, Today, 05:44 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post mattbsea  
                              Started by RideMe, 04-07-2024, 04:54 PM
                              6 responses
                              33 views
                              0 likes
                              Last Post RideMe
                              by RideMe
                               
                              Started by tkaboris, Today, 05:13 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post tkaboris  
                              Working...
                              X