Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trading on level 2 values

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

    Chancehero,

    Who are you connected to? This should be displayed in the lower left corner of the control center
    Cal H.NinjaTrader Customer Service

    Comment


      patsystem,

      anyway,

      this oco **** is anoying, but talked with my broker and we think we have something figured out.

      next question, still in this disconnect - reconnect field,

      so I plae a order, the stop ans limit gets placed (oco), then
      I get disconnected,
      1) the link oco is broken forever, correct?
      2) when It reconnect,
      I still see that the position is long and the the stop and limit are still there.
      3) the limit gets filled.
      4) I have a rogue or non attached sell stop order hanging out.

      so how can I cancel this ? any treads dealing with canceling orders? after a reconnect? I dont really wantto do this mannually - preferably.

      thanks

      Comment


        Chancehero,

        With Patsystems, OCO is handled locally on the PC.

        What this means for you is that when you get disconnected NinjaTrader won't be able to send out the cancel order when one gets filled. However, when you get reconnected and both orders are still there then when one gets filled NinjaTrader will send a signal to cancel the other order.

        If you get disconnected and one of the orders gets filled during the disconnection and you get reconnected with one of the orders active, NinjaTrader will receive the signal that the order was filled and send the cancel signal for the other order.

        If both orders get filled while disconnected then you would be in a position in the opposite direction, since NinjaTrader could not send and receive signals from Patsystems.

        Let me know if this helps.
        Cal H.NinjaTrader Customer Service

        Comment


          this is exactly what I wanted to hear, will test this sometimes this week ! this is good to know ! hahah saving me so much work !

          I would quadruple thank you right now !
          Last edited by chancehero; 10-22-2013, 06:25 AM.

          Comment


            question:

            so I thought that I would get a partial fill, and then a filled signal, but im noticing that , im not, I might get two trades, that are partial fill, for the total value, and instead of the last trade begin called filled, its just partial... what the hell ?

            Comment


              Chancehero,

              NinjaTrader will report a Filled order when all the contracts for the order are filled. Say you had a ten contract order and partial filled 6. This would report a partial fill. When the rest are filled the order will return a Filled status

              This means that there is something in the code that is not causing this status to return and will need to be debugged. Either a order is getting cancelled or the values are not being printed properly.
              Cal H.NinjaTrader Customer Service

              Comment


                yeah, I think I found the problem:

                PHP Code:
                if ((stopOrder != null && stopOrder == execution.Order) || (targetOrder != null && targetOrder == execution.Order))
                            {
                                if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
                                {
                                    stopOrder = null;
                                    targetOrder = null;
                                }
                                if (execution.Order.OrderState == OrderState.Filled)
                                {
                                    //reset counters
                                    if(targetOrder == execution.Order && execution.Order.OrderState == OrderState.Filled)
                                    {
                                        log_file_trade_live_log.WriteLine( count_save +" , "+  DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff") + " profit target filled:  " + profit_price + " or :" +spread_profit + " ticks"); 
                                    }
                                        if(stopOrder == execution.Order && execution.Order.OrderState == OrderState.Filled)
                                    {
                                        log_file_trade_live_log.WriteLine( count_save +" , "+  DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff") + " stop target filled:  " + stop_price + " or :" +spread_loss + " ticks"); 
                                    }
                                    first_trend_level = true;
                                    enter_3 = null;
                                    trend_start = false;
                                    enter_2 = null;
                                    enter = null;
                                }
                            } 
                
                the last part, that will not take place, I got this in my log:

                28/10/2013 4:18:37 AM Order Order='XXXXX' Name='Stop target: situation 3' New state=PartFilled Instrument='ES 12-13' Action=Sell Limit price=1755.25 Stop price=1758.25 Quantity=10 Type=Stop Filled=6 Fill price=1758.25 Error=NoError Native error=''

                28/10/2013 4:18:37 AM Execution Execution='CME XXXXX :M:XXXXX XXXXX' Instrument='ES 12-13' Account='XXXXX' Exchange=Globex Price=1758.25 Quantity=6 Market position=Short Operation=Insert Order='XXXXX' Time='28/10/2013 4:18:37 AM'

                28/10/2013 4:18:37 AM Position Instrument='ES 12-13' Account='XXXXXX' Avg price=1759.5 Quantity=4 Market position=Long Operation=Update Currency=UsDollar

                28/10/2013 4:18:37 AM Order Order='XXXXX' Name='Stop target: situation 3' New state=Filled Instrument='ES 12-13' Action=Sell Limit price=1755.25 Stop price=1758.25 Quantity=10 Type=Stop Filled=10 Fill price=1758.25 Error=NoError Native error=''

                28/10/2013 4:18:37 AM Execution Execution='CME XXXXX XXXXX' Instrument='ES 12-13' Account='XXXXXX' Exchange=Globex Price=1758.25 Quantity=4 Market position=Short Operation=Insert Order='2816587' Time='28/10/2013 4:18:37 AM'

                and then it proceeds to tells me that im flat and that its cancelling the remaining profits targets, but after that, thats it. it not reseting the :

                PHP Code:
                first_trend_level = true;
                                    enter_3 = null;
                                    trend_start = false;
                                    enter_2 = null;
                                    enter = null; 
                
                wondering if you see it, just seems that its not properly reseting the enter_3 ,,, and so on... when im clearly getting a filled command.

                any tips?

                Comment


                  feel free to reply to my last post , thanks

                  Comment


                    Chancehero,

                    The only reason that these lines are not getting reset would be from them not getting called.
                    I recommend you try using print statements to surround the lines to see what is getting called and if the IF statement is in fact becoming true.
                    Cal H.NinjaTrader Customer Service

                    Comment


                      found the problem.

                      question
                      1) noticing that even if im in OCO, that sometimes, the stop loss will not get dully canceled, which is weird and crazy annoying.... ex: I buy 20 ES contracts, and the subsequent profit and stop loss are placed, then when the profit is filled (a bunch or orders resulting in the 20 contracts being filled), 2 stop loss will be left just hanging out, know of any threads discussing this problem? seems like there should be an easy solution...

                      2) im running a really REALLY simply NT strat to record lvl2 data , I record in two files execution and market depth updates,

                      PHP Code:
                      protected override void OnMarketDepth(MarketDepthEventArgs e) {
                          try{ 
                                // update the book
                                updateOrderBook(e);
                                // update date file.
                                
                                  // lvl2 book
                                  log_file_lvl2_book.WriteLine("{0},{1},{2},{3},{4},{5},{6}",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
                                  Instrument.FullName,
                                  (e.Operation == Operation.Insert ? "insert" : (e.Operation == Operation.Remove ? "remove" : "update")),
                                  (e.MarketDataType == MarketDataType.Ask ? "ask" : "bid"),
                                  e.Position,
                                  e.Volume,
                                  e.Price);
                              }
                              catch{
                                  // Outputs the error to the log
                            
                              
                                  
                                  throw;
                              } 
                      
                      it seems the error is never created wit hthe execution, so ill omit that part, but the market depth , specifically,
                      PHP Code:
                          updateOrderBook(e); 
                      
                      creates errors. this is the plain jane code that was on your site. - nothing more or less, but I get the error , that I have too less bars: i.e. I have 4 but need 5.. there is nothing to populate exect the book.....(which is NT own code....)

                      whats going on? i never had the issue using patsystem, but with a data feed from zen fire, and kineticks this error seems to get generated substantially - and its trashing my data collection work....

                      thanks,
                      Chancehero


                      P.S. ill be recoding an extensive error log and share my resutls, but if you know the issue, please let me know now.

                      Comment


                        Chancehero,

                        As far as the Stop and Profit targets OCO I'll need a copy the script that you are working with and Trace and Logs from when you can reproduce the scenario

                        Additionally, the not enough bars reference is that the script is trying to calculate when there is not enough data on the chart. Do you have a CurrentBar check in place? -

                        if(CurrentBar < 1)
                        return;
                        Cal H.NinjaTrader Customer Service

                        Comment


                          ill keep working on that weird ococ thing,

                          but for the data and that not enough bars, I placed, the return condition, and it still takes place.

                          it takes place specifically :
                          PHP Code:
                          private class LadderRow {
                                public  string  MarketMaker;          
                                public  double  Price;
                                public  long    Volume;
                          
                                public LadderRow(double myPrice, long myVolume, string myMarketMaker) {
                                  MarketMaker = myMarketMaker;
                                  Price       = myPrice;
                                  Volume      = myVolume;
                                }
                              }
                              private void updateOrderBook(MarketDepthEventArgs e) {
                                List<LadderRow> rows = null;
                                if (e.MarketDataType == MarketDataType.Ask) {
                                  rows = askRows;
                                  log_file_error.WriteLine("{0}, ask update",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
                                  if (firstAskEvent) {
                                   log_file_error.WriteLine("{0},ask first event",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
                                    if (e.Operation == Operation.Update) {
                                      lock (e.MarketDepth.Ask) {
                                        for (int idx = 0; idx < e.MarketDepth.Ask.Count; idx++)
                                          rows.Add(new LadderRow(e.MarketDepth.Ask[idx].Price, e.MarketDepth.Ask[idx].Volume, e.MarketDepth.Ask[idx].MarketMaker));
                                      }
                                    }
                                    firstAskEvent = false;
                                  }
                                }
                                else if (e.MarketDataType == MarketDataType.Bid) {
                                  rows = bidRows;
                                   log_file_error.WriteLine("{0},bid update",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
                                  if (firstBidEvent) {
                                      log_file_error.WriteLine("{0},bid first event",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
                                    if (e.Operation == Operation.Update) {
                                      lock (e.MarketDepth.Bid) {
                                        for (int idx = 0; idx < e.MarketDepth.Bid.Count; idx++)
                                          rows.Add(new LadderRow(e.MarketDepth.Bid[idx].Price, e.MarketDepth.Bid[idx].Volume, e.MarketDepth.Bid[idx].MarketMaker));
                                      }
                                    }
                                    firstBidEvent = false;
                                  }
                                }
                          
                                if (rows == null){
                                log_file_error.WriteLine("{0},rows = null,",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
                                  return;
                              }
                                if (e.Operation == Operation.Insert) {
                                    log_file_error.WriteLine("{0},I1 - inset command",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
                                  if (e.Position >= rows.Count){
                                  log_file_error.WriteLine("{0},I12 - we need to add a new row to the book",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
                                    rows.Add(new LadderRow(e.Price, e.Volume, e.MarketMaker));
                                    log_file_error.WriteLine("{0},I12c - row added",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
                                  }
                                  else{
                                  log_file_error.WriteLine("{0},I13 - we DONT need to add a new row",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
                                    rows.Insert(e.Position, new LadderRow(e.Price, e.Volume, e.MarketMaker));
                                    log_file_error.WriteLine("{0},I13c - we placed our new row value in ",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
                                  }
                                  }
                          
                                else if (e.Operation == Operation.Remove && e.Position < rows.Count){
                                    log_file_error.WriteLine("{0},I2 - remove command",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
                                 
                                  rows.RemoveAt(e.Position);
                                      log_file_error.WriteLine("{0},I2c - remove command completed at Position: ,{1}",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),e.Position);
                                 }
                                else if (e.Operation == Operation.Update) {
                                  log_file_error.WriteLine("{0},I3 - update command",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
                                 
                                  rows[e.Position].MarketMaker    = e.MarketMaker;
                                  rows[e.Position].Price          = e.Price;
                                  rows[e.Position].Volume         = e.Volume;
                          
                          =================>>>>> error takes place in one of those 3 lines above ! 
                          
                                  log_file_error.WriteLine("{0},I3c - update command completed",DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
                                }
                              
                              
                              } 
                          
                          error takes place at =====================>>>>>

                          it goes from I3 and then error, so it does not give me the I3c message.

                          included the .cs file, so you can see, this error is driving me crazy! l

                          any help would be appreciated
                          if we can make this work I wont delete this code and leave it for everyone.
                          Last edited by chancehero; 03-06-2014, 09:30 AM. Reason: dont want code floating around

                          Comment


                            Chancehero,

                            I tested out the code and received an error for the OnStartUp(), The device is not ready, this was because it was pointing to a D drive that I don't have. I adjusted accordingly for my machine. Received no other errors and compiled fine.

                            Can you send me the exact full error message that you were receiving?
                            Cal H.NinjaTrader Customer Service

                            Comment


                              03/03/2014 9:57:09 AM Strategy Error on calling 'OnMarketDepth' method for strategy 'data_v2/e4251f5e42fd4faaab19a5e96465fada': You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                              03/03/2014 9:57:09 AM Default market depth error in writing depth inputCL 06-15

                              these are the two errors received.

                              I also placed the files,that it recorded.

                              thanks again for any help.
                              crazy weird, and this only takes place once in a while, i.e. it only had this issue with one other product, and thats it for 2 days.... and then maybe thats it, and next time I initialize this thing again next week, it might be two other instruments or more...
                              Attached Files

                              Comment


                                sorry, if I was not clear, this thing compiles fine, its when it starts and actually runs...

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                598 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                343 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                103 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                557 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                555 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X