Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

StopLimit Backtesting

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

    #16
    Thank's Dave! That makes sense to me. I will try...

    Have a nice weekend

    Frank

    Comment


      #17
      Hi Dave,

      I tried your suggestions with success. The StopLimit and StopLoss Braket Order are placed as they should in Strategy Analyser Backtesting even it is a nightmare for me doing this all by hand...
      But - I can't get it running in RealTime. In a Live Connection I don't get any Order Messages back.

      After the first StopLimit order is is submitted:

      longOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.StopLimit, quantity, PriorDayOHLC().PriorHigh[0]+TickSize*1,PriorDayOHLC().PriorHigh[0],"", "Long");


      No Order State is returned by something like this:

      protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice,
      OrderState orderState, DateTime time, ErrorCode error, string nativeError)
      {
      if ((longOrder != null && longOrder == order) )
      Print ("order.OrderState: "+order.OrderState);
      }

      I tried in Simulated Data Feed, and IAB Simulated Trading but no order state. In Backtesting it works. Is there anything I have to configure for Realtime?

      After starting the strategy in Realtime I get this at the console:

      Enabling NinjaScript strategy 'AvalonII/46278034' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnClose=False SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=True Calculate=On price change IsUnmanaged=True MaxRestarts=4 in 5 minutes
      NinjaScript strategy 'AvalonII/46278034' submitting order

      I see the order: "Status Accepted" but no response in my strategie...

      Any ideas?

      Frank

      Comment


        #18
        Hello,

        That would be unexpected, just based on the snippets you've shared. Is there any chance you can share the current state of your code with me, so that I test further on my end?
        Dave I.NinjaTrader Product Management

        Comment


          #19
          Hi Dave,

          please find attached. In the console window, you will see the historical trades but not the last StopLimit Order after enabling the strategy...

          Frank
          Attached Files

          Comment


            #20
            Hello,

            Everything appears to be working on my end, although there was one hiccup I had to overcome. When I applied the strategy to ES 09-15, it took a trade on 6/18 right before the market moved sharply upward, and it placed the stop loss at a point that the ES price simply had not crossed again since the 18th. By switching to the simulated data feed and pushing the price down to the stop loss point, I saw the stop loss get filled, and the strategy continued to take trades.

            I recommend doing a bit more debugging to tell you the exact price that your entry and exit orders are being placed (in addition to the print you already have to show the entry fill price). This way, you can see whether the market ever truly hit your stop loss price. If, after doing this, you can spot a specific situation in which the market clearly hit the stop loss price showing in your prints, without being filled, then please let me know. If that happens, I'll be able to set up the exact scenario on my end and see what may be going wrong.
            Dave I.NinjaTrader Product Management

            Comment


              #21
              Hi Dave,
              thank's for your quick answer. I'm not sure if I was able to tell you what I'm looking for.
              See attached pic. Order_Output. There you see may be better what my question is about. I started the strategie with Sim Feed. See Pic. Chart.
              On the Order_Output pic you see that there is an accepted StopLimit Order (like it should) but in the output Window there is no Order Status about this Accepted Order, Why? I would expect to see it in the Output Window as the historical Trades before.

              Frank
              Attached Files

              Comment


                #22
                Hello,

                It looked to me like you were only printing order information when an order was filled, so you should not see any prints when an order has been placed and accepted but not yet filled. I recommend adding additional prints at the points at which you are submitting orders, like so:

                Code:
                if( Position.MarketPosition !=MarketPosition.Long && longEntryPlaced == false && PriorDayOHLC().PriorHigh[0]>High[0] && PriorDayOHLC().PriorHigh[0]>1 &&PriorDayOHLC().PriorLow[0]>1 )
                {
                longEntryPlaced = true;
                
                Print("placing long stop limit. Stop: " + PriorDayOHLC().PriorHigh[0] + ", Limit: " +    PriorDayOHLC().PriorHigh[0]+TickSize*1);
                
                longOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.StopLimit, 1, PriorDayOHLC().PriorHigh[0]+TickSize*1,PriorDayOHLC().PriorHigh[0],"", "Long");
                				
                			}
                Or, you could filter for the order state OrderState.Accepted, rather than Filled, to trigger your prints within OnOrderUpdate().
                Dave I.NinjaTrader Product Management

                Comment


                  #23
                  Hi Dave,

                  this is from the code I send you:

                  if ((longOrder != null && longOrder == order) )
                  {
                  longEntryPlaced = true;
                  Print (Time[0] +" Long Order: "+order.OrderState+" at: "+order.LimitPrice);
                  .....
                  Should this not bring up a Printout "Accepted" like shown in the Order State Column?

                  Your suggestion would bring me a Printout before sending to the broker. I would like to see the status from the broker.

                  Frank
                  Attached Files

                  Comment


                    #24
                    Hello,

                    I see what's going on now. Because we are now accessing the order object directly, rather than using the IOrder interface as we did in NinjaTrader 7, your longOrder variable will remain null until the call to SubmitOrderUnmanaged() has successfully returned.

                    In NinjaTrader 8, it is best to assign Order variables like longOrder within OnOrderUpdate(), rather than OnBarUpdate(), to ensure that the assignment happens as soon as it can. We have an example of this in our Code Breaking Changes page in the help guide, under the heading Strategies, Orders, and Accounts:

                    http://ninjatrader.com/support/helpG...hangesOverview

                    After making this change on my end, I'm now able to see your Print cycle through all of the order states.
                    Dave I.NinjaTrader Product Management

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by i019945nj, 12-14-2023, 06:41 AM
                    5 responses
                    64 views
                    0 likes
                    Last Post i019945nj  
                    Started by ruudawakening, Today, 12:58 AM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by thread, Yesterday, 11:58 PM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by stafe, Yesterday, 08:34 PM
                    1 response
                    16 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by jclose, Yesterday, 09:37 PM
                    1 response
                    11 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Working...
                    X