Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unlogical RT trading behaviour with IB

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

    #16
    Yes this resolved my issue. I have learned something again....

    Would be helpful, if backtesting would show the same behaviour and produce those double exit orders as well...Anyway, Thx!!

    Comment


      #17
      Hello,

      OK glad this resolved the issue.

      What your most likely facing is a race condition.

      Heres why.

      You need at least one OnBarUpdate() to occur after you exit a position for the new position to be represented.

      So what you where most likely having happen is that the

      ExitLong() was called in the same OnBarUpdate()

      This Exited for 8 Contracts.

      Then in this same OnBarUpdate() you then also called EnterShort(). Which since one OnBarUpdate() hasnt passed and all the position variables are still not updated. EnterShort thinks your in a long position still even though ExitLong() has submitted its orders to the live servers and is still awaiting the position to be flat.

      Therefor when you called EnterShort() It was also sending in the Exit order to sell 8 and then sending in order to then go short 4 contracts.

      But since this takes time in a live situation this is the reason this is different vs sim vs live.

      This is the reason for OnOrderUpdate(). This way you can wait for an exit long order to fill before submitting and EnterShort for example. If this was inside OnOrderUpdate() you would have been fine. However since this was inside OnBarUpdate the bar Updated before the order did and you ended with a double order.

      Let me know if I can be of further assistance.

      Comment


        #18
        I am once back again with a question concerning the RT behaviour of my strategy.
        The reason I post it here is that it happens only when OnBarUpdate is called in realtime (historical == false) and when a position is on.

        The following error happens in OnBarUpdate: "Index was out of bounds.... " I have done quite a lot of searching in the forum, when this kind of error occurs and I think I have understood the problem. It happens when bars are referenced, which are at the moment of the call of OnBarUpdate() not available.

        However in my piece of code - where the problem occurs (Print "2" is reached, while Print "3" is not reached) - I do not see that error:

        Print("2");


        // EXIT BLOCK


        // LONG Exits
        if (Position.MarketPosition == MarketPosition.Long && Signal == 0) ExitLong();
        if (Position.MarketPosition == MarketPosition.Long) ExitLongStop(ExitStopPrice);


        // SHORT Exit

        if (Position.MarketPosition == MarketPosition.Short && Signal == 0) ExitShort();
        if (Position.MarketPosition == MarketPosition.Short) ExitShortStop(ExitStopPrice);


        // Check, whether position was stopped out
        if ((Signal == 1) && (YD_Position == 1) && (Position.MarketPosition != MarketPosition.Long)) LONG_StoppedOut = true;
        if ((Signal == -1) && (YD_Position == -1) && (Position.MarketPosition != MarketPosition.Short)) SHORT_StoppedOut = true;


        Print(
        "3");

        Since I have no clue I definitely need your support once again, sorry for that!!


        Thx, Peter
        Last edited by unter821; 02-10-2011, 03:17 PM.

        Comment


          #19
          Peter,

          What was the complete error message you saw? It should provide more information to figure out where exactly in your code you are accessing an invalid index value.

          Best bet to isolate this would be to use try-catch blocks around your code to figure out where exactly it is having issues. Put these all around your code segments so you can isolate which segment is causing the problem and slowly drill down to the exact line causing the problem. http://www.ninjatrader.com/support/f...ead.php?t=9825
          Josh P.NinjaTrader Customer Service

          Comment


            #20
            Josh,

            The following error message is displayed: Error on calling 'OnBarUpdate' method for strategy 'MacroStrategy/40676dafabf540b6bc9fbebfc96d7b44': Der Index war außerhalb des Arraybereichs (=Index was out of bounds)

            I have found out, that it happens in this code line:

            if (Position.MarketPosition == MarketPosition.Long) ExitLongStop(ExitStopPrice);

            I am using two different entries each with a unique signalname (but only one is active at one time). Could it be, that I have to use the parameter "fromEntrySignal" in the exit. I have actually no clue.....
            Last edited by unter821; 02-11-2011, 03:56 AM.

            Comment


              #21
              Peter, thanks for the reply - you should be able to use either overload, with no tagging to an entry it would apply to the full position then - is the error still coming when you try the below?

              if (Position.MarketPosition == MarketPosition.Long) ExitLongStop(ExitStopPrice, "your entry signal name here');
              BertrandNinjaTrader Customer Service

              Comment


                #22
                Bertrand,

                I change the code, as you proposed, however the error is still coming.

                With todays start of US Interest Rates Session 14:20 and US Energy Session 15:00 (our time) error was the same as yesterday.

                Comment


                  #23
                  Hello,

                  Are you sure this is the location of the error? As I would continue to look into this as I dont see why this would cause this error witht he information provided you should be fine. How did you narrow it down to here?

                  Please add in a few try() catch() blocks to your code as josh suggested, I would add 3.

                  One before this code section, another with the If Statement in it and another after that as a minimum.

                  Then run a test in Markey Replay for example if you need to and let me know what block fails.

                  Let me know if I can be of further assistance.



                  Comment


                    #24
                    Hello,

                    I did narrow it down with Print statements and I arrived exactly in that line. And I did that for several instruments, always the same line.

                    But anyway, I will implement the try() catch() blocks as you suggest and hopefully we can narrow it down that way

                    Best, Peter

                    Comment


                      #25
                      Hello,

                      By using try catch block my findings were confirmed: The error happens exactly in the specified code of line ExitShortStop or ExitLongStop in OnBarUpdate(). I am now a little more clever in that the error happens inside PlaceOrder()

                      What does Placeorder() exactly do in this context? Could it be an index problem with bars?

                      Interestingly it does not happen for every instrument, so my task now is to find out the differences...


                      Error protocoll:

                      FDAX
                      FESX
                      ExitShortStop Error
                      11.02.2011 22:00:00 System.IndexOutOfRangeException: Der Index war außerhalb des Arraybereichs (= Index out of bounds)
                      bei NinjaTrader.Strategy.StrategyBase.PlaceOrder(Int32 selectedBarsInProgress, Boolean liveUntilCancelled, OrderAction action, OrderType orderType, Int32 quantity, Double limitPrice, Double stopPrice, String signalName, String fromEntrySignal, String oco, Boolean simStop)
                      bei NinjaTrader.Strategy.StrategyBase.ExitShortStop(Do uble stopPrice)
                      bei NinjaTrader.Strategy.MacroStrategy.OnBarUpdate()
                      FSMI
                      FGBS
                      ExitLongStop Error
                      11.02.2011 22:00:00 System.IndexOutOfRangeException: Der Index war außerhalb des Arraybereichs.
                      bei NinjaTrader.Strategy.StrategyBase.PlaceOrder(Int32 selectedBarsInProgress, Boolean liveUntilCancelled, OrderAction action, OrderType orderType, Int32 quantity, Double limitPrice, Double stopPrice, String signalName, String fromEntrySignal, String oco, Boolean simStop)
                      bei NinjaTrader.Strategy.StrategyBase.ExitLongStop(Dou ble stopPrice)
                      bei NinjaTrader.Strategy.MacroStrategy.OnBarUpdate()
                      FGBL
                      ExitLongStop Error
                      11.02.2011 22:00:00 System.IndexOutOfRangeException: Der Index war außerhalb des Arraybereichs.
                      bei NinjaTrader.Strategy.StrategyBase.PlaceOrder(Int32 selectedBarsInProgress, Boolean liveUntilCancelled, OrderAction action, OrderType orderType, Int32 quantity, Double limitPrice, Double stopPrice, String signalName, String fromEntrySignal, String oco, Boolean simStop)
                      bei NinjaTrader.Strategy.StrategyBase.ExitLongStop(Dou ble stopPrice)
                      bei NinjaTrader.Strategy.MacroStrategy.OnBarUpdate()
                      FGBM

                      Comment


                        #26
                        Hello,

                        Is this a multi series strategy? Or are you starting it on mltiple instruments seperately?

                        I look forward to assisting you further.

                        Comment


                          #27
                          I am starting it on multiple instruments separately. There exits a thread with a similar problem, where I made a post today. Maybe that helps. Could you check, how they could solve this.

                          Thx
                          Last edited by unter821; 02-14-2011, 07:26 AM.

                          Comment


                            #28
                            What thread?

                            Can you please link to it.

                            Comment


                              #29

                              Comment


                                #30
                                Hello,

                                Thanks.

                                Can you please check to make sure you can pull up a chart and get live data for the instruments this is occuring on?

                                For example FESX


                                I look forward to assisting you further.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Barry Milan, Today, 10:35 PM
                                1 response
                                7 views
                                0 likes
                                Last Post NinjaTrader_Manfred  
                                Started by WeyldFalcon, 12-10-2020, 06:48 PM
                                14 responses
                                1,428 views
                                0 likes
                                Last Post Handclap0241  
                                Started by DJ888, Yesterday, 06:09 PM
                                2 responses
                                9 views
                                0 likes
                                Last Post DJ888
                                by DJ888
                                 
                                Started by jeronymite, 04-12-2024, 04:26 PM
                                3 responses
                                40 views
                                0 likes
                                Last Post jeronymite  
                                Started by bill2023, Today, 08:51 AM
                                2 responses
                                16 views
                                0 likes
                                Last Post bill2023  
                                Working...
                                X