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

Order does not get sent to IB TWS from Strategies but works for Order and Chart

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

    Order does not get sent to IB TWS from Strategies but works for Order and Chart

    I'm connecting NT7 to IB TWS. I'm able to submit manual orders using Order or Chart. I'm getting quotes and real time data. When I run my strategy, the order is not submitting. I'm using a Paper Account.
    Code:
     protected override void OnBarUpdate()
            {
                if (CurrentBar < 1)
                    return;
    
                EnterLong(100);
                Print("Time = " + Times[1][0] + ", 1. Close = " + Closes[0][0] + " , Yesterday High = " + Highs[0][1]);    ​
            }
    Am I missing something ? I can see the output, therefore, I know the code is executing.

    Thanks.

    #2
    Hello mechinvestor,

    What account is selected in the Strategies window for the strategy instance in the Configured area in the Account drop-down?

    Is this the account you are placing manual orders to?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I have attached the screenshot below. The account settings are matching.

      Thanks.

      Click image for larger version  Name:	8-11-2023 9-09-42 AM.png Views:	0 Size:	25.4 KB ID:	1264227Click image for larger version  Name:	8-11-2023 9-05-36 AM.png Views:	0 Size:	22.2 KB ID:	1264228Click image for larger version  Name:	8-11-2023 9-08-22 AM.png Views:	0 Size:	52.8 KB ID:	1264229

      Comment


        #4
        Hello mechinvestor,

        Have you enabled the strategy?

        This is set to run on daily bars. Is CalculateOnBarClose set to false?

        Are you expecting 1 trade at the start of each session?

        Has the strategy been running overnight?

        Did the conditions to place an order evaluate as true?

        Use prints and enable TraceOrders to understand behavior.

        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi,

          I enable the strategy to see the output, that is how I know it's not working. I'm trying to see how to place an order using NT7 and IB TWS paper account. Yes, I'm using daily bars and I set CalculateOnBarClose to be false. Therefore, the OnBarUpdate get called on each tick data.

          I'm expecting 1 trade to execute on the start of the session. No, this strategy has not run overnight. There are no condition to place the order. I can see the Print statement in the Output windows.

          I enabled the TraceOrder flag and I am getting debugging information provided below.
          Code:
          8/9/2023 7:36:00 AM Entered internal PlaceOrder() method at 8/9/2023 7:36:00 AM: BarsInProgress=1 Action=Buy OrderType=Market Quantity=100 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
          8/9/2023 7:36:00 AM Ignored PlaceOrder() method at 8/9/2023 7:36:00 AM: Action=Buy OrderType=Market Quantity=100 LimitPrice=0 StopPrice=0 SignalName='Buy' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
          Time = 8/9/2023 7:36:00 AM, 1. Close = 135.77 , Yesterday High = 140.12​
          It looks like as soon as an order is placed, it's being ignored. Did I not set it up correctly ? I set the EntriesPerDirection to 5 and still no order in IB TWS.

          Do you have a simple script that send an order to TWS that works ? I want to make sure that setup is right.

          Thanks.

          Comment


            #6
            Hello mechinvestor,

            The message is stating that there is already an open position. The order method was called, but was ignored.

            Is the strategy name yellow, showing there is a historical position open?

            Try printing the Position.MarketPosition and Position.Quantity as well as EntriesPerDirection one line above the entry method.

            Included with NinjaTrader is the SampleMACrossover strategy which will work on TWS.

            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi,

              Looks like the strategy is sending the order and it thinks it got executed but I don't see anything inside IB TWS. You can tell from the output message.
              Code:
              **NT** Enabling NinjaScript strategy 'CloseGreaterThanYesterdayHighExit/0dd4632863124dd39de514d93cc7d51c' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=UniqueEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=60 CancelEntryOrdersOnDisable=True CancelExitOrdersOnDisable=True CalculateOnBarClose=False MaxRestarts=600 in 5 minutes
              Time = 8/9/2023 6:31:00 AM, Flat 0
              8/9/2023 6:31:00 AM Entered internal PlaceOrder() method at 8/9/2023 6:31:00 AM: BarsInProgress=1 Action=Buy OrderType=Market Quantity=100 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
              Time = 8/9/2023 6:31:00 AM, 1. Close = 135.77 , Yesterday High = 140.12
              Time = 8/9/2023 6:32:00 AM, Long 100​
              I added this code to print out the market position and quantity.
              Code:
              Print("Time = " + Times[1][0] + ", " + Position.MarketPosition.ToString() + " " + Position.Quantity.ToString());
              Therefore, it's something with NT7 sending the order to IB TWS using Strategy API.

              Thanks.

              Comment


                #8
                Hello mechinvestor,

                Have you added a secondary series to the script with Add()?

                I was not able to confirm, is the strategy name on the Strategies tab of the Control Center yellow, showing there is a historical position open?

                Is this order that was submitted and filled placed in historical or realtime?

                Can you include in the print the value of Historical?

                Code:
                Print(string.Format("{0} | Historical: {1}, MarketPosition: {2}, Quantity: {3}, BarsInProgress: {4} - {5} {6} {7}", Time[0], Historical, Position.MarketPosition, Position.Quantity, BarsInProgress, Instrument.FullName, BarsPeriod.Value, BarsPeriod.Id));
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi,

                  I removed the Add 1 minute bar from the Strategy. I also added the Print statement you gave. Here is the output.

                  Code:
                  **NT** Enabling NinjaScript strategy 'CloseGreaterThanYesterdayHighExit/0dd4632863124dd39de514d93cc7d51c' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=UniqueEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=60 CancelEntryOrdersOnDisable=True CancelExitOrdersOnDisable=True CalculateOnBarClose=False MaxRestarts=600 in 5 minutes
                  8/8/2023 1:00:00 PM | Historical: True, MarketPosition: Flat, Quantity: 0, BarsInProgress: 0 - ENPH 1 Day
                  Time = 8/8/2023 1:00:00 PM, Flat 0
                  8/8/2023 1:00:00 PM Entered internal PlaceOrder() method at 8/8/2023 1:00:00 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=100 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                  Time = 8/8/2023 1:00:00 PM, 1. Close = 135.77 , Yesterday High = 140.12
                  8/9/2023 1:00:00 PM | Historical: True, MarketPosition: Long, Quantity: 100, BarsInProgress: 0 - ENPH 1 Day
                  Time = 8/9/2023 1:00:00 PM, Long 100
                  8/9/2023 1:00:00 PM Entered internal PlaceOrder() method at 8/9/2023 1:00:00 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=100 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                  8/9/2023 1:00:00 PM Ignored PlaceOrder() method at 8/9/2023 1:00:00 PM: Action=Buy OrderType=Market Quantity=100 LimitPrice=0 StopPrice=0 SignalName='Buy' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
                  Time = 8/9/2023 1:00:00 PM, 1. Close = 138.46 , Yesterday High = 135.95
                  8/10/2023 1:00:00 PM | Historical: True, MarketPosition: Long, Quantity: 100, BarsInProgress: 0 - ENPH 1 Day
                  Time = 8/10/2023 1:00:00 PM, Long 100​

                  Comment


                    #10
                    Hello mechinvestor,

                    'Historical: True'
                    These are orders being submitted in historical data. Historical orders are not submitted in real-time to any account. These are virtual.

                    Is the strategy name on the Strategies tab of the Control Center yellow?

                    You have a historical position open. If the strategy is wait until flat, then its waiting for the historical virtual position to be exited before it starts placing real-time orders.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by fx.practic, 10-15-2013, 12:53 AM
                    5 responses
                    5,404 views
                    0 likes
                    Last Post Bidder
                    by Bidder
                     
                    Started by Shai Samuel, 07-02-2022, 02:46 PM
                    4 responses
                    95 views
                    0 likes
                    Last Post Bidder
                    by Bidder
                     
                    Started by DJ888, Yesterday, 10:57 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by MacDad, 02-25-2024, 11:48 PM
                    7 responses
                    159 views
                    0 likes
                    Last Post loganjarosz123  
                    Started by Belfortbucks, Yesterday, 09:29 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post Belfortbucks  
                    Working...
                    X