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

Unmanaged Stop market order

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

    Unmanaged Stop market order

    ​When I submit a stop market order using the unmanaged approach I get this. What am i doing wrong?

    Code:
    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, 1,Low[1],0, oco2, "Stop limit entry");
    Click image for larger version

Name:	image.png
Views:	91
Size:	11.5 KB
ID:	1224675
    Attached Files

    #2
    Hello r3n3v,

    Are you submitting the order over and over every time OnBarUpdate() updates?

    Are you requiring the Position.MarketPosition to be MarketPosition.Flat in the condition that submits this order?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I'm using the following for that within the OnBarUpdate

      Code:
      if (CrossAbove(Close,emaFast,1))
                      {        
                  // Submit OCO entry limit orders if we currently don't have an entry order open
                  if (longEntry == null && shortEntry == null && !entrySubmitted && CurrentBar > BarsRequiredToTrade
                      && Position.MarketPosition == MarketPosition.Flat)​
      Attached Files

      Comment


        #4
        Hello r3n3v,

        Is this condition evaluating as true multiple times?

        Are you running this with Calculate.OnBarClose?

        Can you provide TraceOrders and Print() output to show us what is happening?

        Enable TraceOrders.

        Print within the conditions action block above where the order is submitted, the time of the bar and Condition true.

        Print the order object in OnOrderUpdate().

        Below is a link to a forum post that demonstrates using Print() to understand behavior.


        Save the output to a text file and attach this to your next post.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Ok I've attqched it below.
          Attached Files

          Comment


            #6
            Hello r3n3v,

            Print within the conditions action block above where the order is submitted, the time of the bar and Condition true.

            Print(string.Format("{0} | condition true", Time[0]));

            If you have added this print and the print is not appearing, then it would not be this condition submitting the order. Where else has SubmitOrderUnmanaged() been written into the script?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Added next log
              Attached Files

              Comment


                #8
                Hello r3n3v,

                Are you adding a print one line above the call to SubmitOrderUnmanaged()?

                It kind of looks like the order is being submitting first and the print is called after this.
                But it does also appear the print is appearing after every order, indicating the condition is evaluating as true multiple times.

                We can also see that the orders are being cancelled and are not being filled. So the Position.MarketPosition is not changing as the position has not changed.

                This would also imply that the longEntry variable is null, the shortEntry variable is null, entrySubmitted is true, and CurrentBar is greater than BarsRequiredToTrade.

                To understand why the condition is evaluating as true, one line above the conditions that submit the order, print all values in the conditions. Include the time of the bar and a label for each value and comparison operator.

                See the video 'NT8 NinjaScript Editor 401' which demonstrates using prints to understand behavior.


                When testing if something is null, you can put the comparison in the values.

                Print(string.Format("{0} | longEntry == null: {1}", Time[0], (longEntry == null) ));

                Then provide the output.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Ok I changed that to be before my entry. I notice that stop price goes to zero.

                  Code:
                  bool Crossed = CrossAbove(Close, emaFast,1);
                  Print(string.Format("{0} | condition true : Ema Crossed!", Time[0], Crossed));
                  SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, 1,Low[1],0, "", "Short limit entry");​
                  Code:
                  11/13/2022 5:25:00 PM | condition true : Ema Crossed!
                  11/13/2022 5:25:00 PM Strategy 'vrUnmanaged/276456271': Entered internal SubmitOrderUnmanaged() method at 11/13/2022 5:25:00 PM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=11788.00 StopPrice=0 SignalName='Short limit entry'
                  orderId='NT-00002-802' account='Playback101' name='Short limit entry' orderState=Submitted instrument='NQ 12-22' orderAction=Sell orderType='Stop Market' limitPrice=11788 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-11-13 17:25:00' gtd='2099-12-01' statementDate='2022-11-22'
                  orderId='NT-00002-802' account='Playback101' name='Short limit entry' orderState=Accepted instrument='NQ 12-22' orderAction=Sell orderType='Stop Market' limitPrice=11788 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-11-13 17:25:00' gtd='2099-12-01' statementDate='2022-11-22'
                  orderId='NT-00002-802' account='Playback101' name='Short limit entry' orderState=Working instrument='NQ 12-22' orderAction=Sell orderType='Stop Market' limitPrice=11788 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-11-13 17:25:00' gtd='2099-12-01' statementDate='2022-11-22'
                  11/14/2022 4:00:00 PM Strategy 'vrUnmanaged/276456271': Cancelled order due to end of session handling: BarsInProgress=0, orderId='NT-00002-802' account='Playback101' name='Short limit entry' orderState=Working instrument='NQ 12-22' orderAction=Sell orderType='Stop Market' limitPrice=11788 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-11-13 17:25:00' gtd='2099-12-01' statementDate='2022-11-22'
                  orderId='NT-00002-802' account='Playback101' name='Short limit entry' orderState=CancelPending instrument='NQ 12-22' orderAction=Sell orderType='Stop Market' limitPrice=11788 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-11-13 17:25:00' gtd='2099-12-01' statementDate='2022-11-22'
                  orderId='NT-00002-802' account='Playback101' name='Short limit entry' orderState=CancelSubmitted instrument='NQ 12-22' orderAction=Sell orderType='Stop Market' limitPrice=11788 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-11-13 17:25:00' gtd='2099-12-01' statementDate='2022-11-22'
                  orderId='NT-00002-802' account='Playback101' name='Short limit entry' orderState=Cancelled instrument='NQ 12-22' orderAction=Sell orderType='Stop Market' limitPrice=11788 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-11-13 17:25:00' gtd='2099-12-01' statementDate='2022-11-22'
                  11/14/2022 5:30:00 PM | condition true : Ema Crossed!
                  11/14/2022 5:30:00 PM Strategy 'vrUnmanaged/276456271': Entered internal SubmitOrderUnmanaged() method at 11/14/2022 5:30:00 PM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=11774.00 StopPrice=0 SignalName='Short limit entry'
                  orderId='NT-00003-802' account='Playback101' name='Short limit entry' orderState=Submitted instrument='NQ 12-22' orderAction=Sell orderType='Stop Market' limitPrice=11774 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-11-14 17:30:00' gtd='2099-12-01' statementDate='2022-11-22'
                  orderId='NT-00003-802' account='Playback101' name='Short limit entry' orderState=Accepted instrument='NQ 12-22' orderAction=Sell orderType='Stop Market' limitPrice=11774 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-11-14 17:30:00' gtd='2099-12-01' statementDate='2022-11-22'
                  orderId='NT-00003-802' account='Playback101' name='Short limit entry' orderState=Working instrument='NQ 12-22' orderAction=Sell orderType='Stop Market' limitPrice=11774 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-11-14 17:30:00' gtd='2099-12-01' statementDate='2022-11-22'
                  Enabling NinjaScript strategy 'vrUnmanaged/276456271' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=2 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=True MaxRestarts=4 in 5 minutes
                  NinjaScript strategy 'vrUnmanaged/276456271' submitting order
                  
                  ​
                  Last edited by r3n3v; 11-22-2022, 12:12 PM.

                  Comment


                    #10
                    Hello r3n3v,

                    Your conditions are evaluating as true.

                    If you only want one entry order allowed at a time, you could use a bool. When an entry is submitted, set the bool to true. In OnOrderUpdate() detect the order by order.Name. When the entry order fills, set the bool back to false. Require the bool to be false in the conditions that submit the entry.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Ok but one question:

                      I notice all those orders are placed at 0. Why is that? I'm confused why stopprice is 0.

                      LimitPrice=11788.00 StopPrice=0 show up on the logs.

                      Code:
                      13/2022 5:25:00 PM Strategy 'vrUnmanaged/276456271': Entered internal SubmitOrderUnmanaged() method at 11/13/2022 5:25:00 PM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=11788.00 StopPrice=0 SignalName='Short limit entry'
                      orderId='NT-00002-802' account='Playback101' name='Short limit entry' orderState=Submitted instrument='NQ 12-22' orderAction=Sell orderType='Stop Market' limitPrice=11788 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2022-11-13 17:25:00' gtd='2099-12-01' statementDate='2022-11-22'
                      ord​

                      Comment


                        #12
                        Hello r3n3v,

                        This would be due to a 0 being supplied as the stop price.

                        SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, 1,Low[1],0, "", "Short limit entry");​
                        SubmitOrderUnmanaged(int selectedBarsInProgress, OrderAction orderAction, OrderType orderType, int quantity, double limitPrice, double stopPrice, string oco, string signalName)


                        Further, as you have chosen OrderType.StopMarket, supplying Low[1] as the limit price is going to be ignored. Stop market orders do not use a limit price.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          ok great thanks!

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by futtrader, 04-21-2024, 01:50 AM
                          4 responses
                          41 views
                          0 likes
                          Last Post futtrader  
                          Started by Option Whisperer, Today, 09:55 AM
                          1 response
                          11 views
                          0 likes
                          Last Post bltdavid  
                          Started by port119, Today, 02:43 PM
                          0 responses
                          1 view
                          0 likes
                          Last Post port119
                          by port119
                           
                          Started by Philippe56140, Today, 02:35 PM
                          0 responses
                          3 views
                          0 likes
                          Last Post Philippe56140  
                          Started by 00nevest, Today, 02:27 PM
                          0 responses
                          2 views
                          0 likes
                          Last Post 00nevest  
                          Working...
                          X