Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Market Replay doesn't close position

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

    Market Replay doesn't close position

    I am using the same code I used for backtesting, and place a OCO bracket around each order.
    I am experiencing a odd behavior on Market Replay where it doesn't close a position all of the time?

    #2
    bbucha_stk, are you sure your strategy and account positons line up in Market Replay testing, so the needed sync is present?

    Have you run the strategy with TraceOrders = true in the Initialize() and then checked the debug to the output window? Do you see any ignored / cancelled / expired orders then referenced?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      1) I will add TraceOrders = true in the Initialize()
      2) Not sure what you mean by "and then checked the debug to the output window?"
      Will the traceorders create a output window?
      3)Not sure what you mean here...are you sure your strategy and account positons line up in Market Replay testing, so the needed sync is present?

      I am connected to Market replay and have a number of days that I am running in sequence non stop from lets say Jab 1 to Jan 18.
      Some of the days I find it acts odd where it does not close a position.
      So not sure what the "Needed Sync " means


      Comment


        #4
        Hello,

        TraceOrders() will output to the Output window. So you will need to have one open to see the output of it.

        In your other forum thread you mentioned that you will be running this overnight. Please run these tests overnight and let me know if you run into issue diagnosing whats occuring.

        Then post the sections of the output window logs so that we can help you read through what occured.

        Comment


          #5
          You will notice at 6:03 a short entry on 6E at 1.3508. The strategy target is 8 ticks. At 6:11 it hits way more than 8 ticks should of closed.
          The following is the output window:
          1/19/2011 06:03:00 Entered internal PlaceOrder() method at 1/19/2011 06:03:00: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Short' FromEntrySignal=''
          1/19/2011 06:03:00ShortBoom: Plan B
          1/19/2011 06:03:00 Cancelled expired order: BarsInProgress=0: Order='1a66e76da52844deaa62a319a65a906d/Replay101' Name='Stop loss' State=Accepted Instrument='6E 03-11' Action=BuyToCover Limit price=0 Stop price=1.352 Quantity=1 Strategy='BobBoomaRang' Type=Stop Tif=Gtc Oco='af03675035c34fd5870ece2e5e709508-137' Filled=0 Fill price=0 Token='1a66e76da52844deaa62a319a65a906d' Gtd='12/1/2099 00:00:00'

          1/19/2011 06:07:56 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Price Value=1.3506 Currency=0 Simulated=False
          1/19/2011 06:07:56 Stop Loss Short 1.3506
          Just keeps printing the following except time change of course.
          1/19/2011 06:13:12 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Price Value=1.3506 Currency=0 Simulated=False
          1/19/2011 06:13:12 Stop Loss Short 1.3506
          Attached Files

          Comment


            #6
            Are you sure the signal names are matching up? Is the FromEntrySignal parameter corresponding to the 'Short" signal name you assigned?
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Is the following the isue:
              A) My short entry was
              EnterShort(DefaultQuantity,
              "Short");
              B) If the price moves 6 ticks I move my stop from 12 ticks to 2 ticks as is the following:

              elseif (Position.MarketPosition == MarketPosition.Short)
              {
              // Once the price is greater than entry price+6 ticks, set stop loss
              if (Low[0] < Position.AvgPrice - 6*TickSize)
              {
              SetStopLoss(CalculationMode.Price, Position.AvgPrice -
              2*TickSize);
              //SetStopLoss(CalculationMode.Price, Position.AvgPrice );
              Print(Time[0] + " Stop Loss Short "+ (Position.AvgPrice- 2*TickSize));
              }
              }

              Comment


                #8
                Hello,

                You need to call

                SetStopLoss(CalculationMode.Price, Position.AvgPrice - 2*TickSize);

                Before you use EnterShort()


                SetStopLoss()
                EnterShort()


                Then after this you can call SetStopLoss() to change the stop loss value if it needed.

                Please see this guide if you havnt seen it already:






                Comment


                  #9
                  I already do the following:
                  Initialize()
                  //OCO setup
                  SetProfitTarget("", CalculationMode.Ticks, profitTick);
                  SetStopLoss(
                  "", CalculationMode.Ticks, stopLossTick, false);

                  OnBarUpdate()
                  // Resets the stop loss to the original value when all positions are closed
                  if (Position.MarketPosition == MarketPosition.Flat)
                  {
                  SetStopLoss(CalculationMode.Ticks, stopLossTick);
                  }
                  But as I said onBarUpdate if the ticks get to 6 I dynamically move the stop

                  Comment


                    #10
                    Looks like I already do as your sample.....
                    Do you think the dynamic stop/loss change needs the SetStopLoss with the 4 parameters including the entry name?

                    Comment


                      #11
                      Attn Brett I emailed you the code.
                      In advance thanks

                      Comment


                        #12
                        Hello,

                        Emailed you back the small change I made. Looks like you where specifying a name of "" or blank for the setstoploss. I could see how this could create issue as the setstoploss is not matched to the entry as the EnterLong() name is not "".

                        Let me know if I can be of further assistance.

                        Comment


                          #13
                          Hi Bad news I made the change and it still happens. Like I said its reproducible...
                          1) Its the 6E at 6:03 am on Jan 19 I run the Market Replay at full speed
                          2) The code I sent has the default settings 4 Renko
                          3) It does a Short and never closes it.

                          Comment


                            #14
                            Observation: I reran and at 6:03 (1.3508)it entered the short as expected At 6:08.13 it hit my target of 8 ticks profit (1.3500)but as we know it did not close the position as it should of.
                            A few minutes later I paused Market Replay and went to the Control->Positions tab and manually closed the position. Then fired up the play button from where it was paused and the screen now had the exact closing position as expected (1.3500)
                            I did this at slow speed and reproduced the condition. I can have it happen on different days as well it is very reproducible.
                            In advance thanks and HELP as I can not do market replay testing as this happens on other days as well.
                            Brett has the code for review.

                            Comment


                              #15
                              Hello,

                              Best is at this point if I just log into your PC to see what your exactly doing on this. I'm heading out for the day. Please email me at my personal email on Monday and we will setup a time for me to call you. Please let me know what times will work for you.

                              I look forward to assisting you further.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by kujista, Today, 06:23 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post kujista
                              by kujista
                               
                              Started by traderqz, Yesterday, 04:32 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by f.saeidi, Today, 05:56 AM
                              1 response
                              4 views
                              0 likes
                              Last Post Jltarrau  
                              Started by Jltarrau, Today, 05:57 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post Jltarrau  
                              Started by Stanfillirenfro, Yesterday, 09:19 AM
                              7 responses
                              53 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X