Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple orders opened, seems to deny my conditions

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

    Multiple orders opened, seems to deny my conditions

    I am live with a strategy that uses renko-charts and secondary 'timeframes' on top (so renko and 2 seconds)

    I did not have the following problem during backtesting, only during live trading.

    I nested my entry conditions in OnBarUpdate, like so:

    Code:
    protected override void OnBarUpdate()
            {            
                {  if (BarsInProgress == 0)
                       if (Position.MarketPosition == MarketPosition.Flat
                    && LLA == null
                    && Laguerre(0.6).LaguerreOut[0] > 0.6
                    && Laguerre(0.6).LaguerreOut[0] > Laguerre(0.6).LaguerreOut[1] 
                          )
                    {
                    LLA = EnterLong(0, DefaultQuantity, "LLA");
                    DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0] + -65 * TickSize, Color.Lime);
                    }
                 }
             }
    As mentioned before, this works well during backtesting. However, when this strategy is live, it sometimes opens a second position a few bars later while the first one is still open and, even weirder, sometimes it opens 2 positions on the same bar, with a few seconds in between.

    How is this possible considering that
    • I clearly stipulate that one of the conditions is being flat
    • LLA gets a value from the moment a position is opened and I want LLA to be null in order to open a position ?? (the resetting of this LLA back to null is done elsewhere in my code, when being flat, so it should not be null until the first position is closed!)

    I spent hours debugging with print statements already, but cannot figure out why this is happening.



    First I thought that the time difference between submitting an order and the effective opening of it had to do something with it, but proved this to be wrong. I noticed orders being open for minutes already, and still a second one opened. Does not seem logical.


    Then I suspected there was a mistake with the nesting of my conditions (that I closed the curly brackets too late and they fell in the smaller, 2 seconds timeframe), but that does not seem to be the case either.


    Please help

    #2
    Hello Spinn,

    Thanks for your post.

    Do you have any other strategies running on the same instrument?

    Are you placing manual orders on the same instrument?

    What are the strategy entries per direction set to?

    What is the startegy entry handling set to?

    What Calculate mode are you running with?

    Do the DrawArrows show up with each entry or only certain ones that match your entry criterira?

    Please turn on TraceOrders and to see if that provides you better a better view to what is generating the orders: http://ninjatrader.com/support/helpG...raceorders.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul,

      • Only one strategy runs on that instrument. In fact: it's the only strategy running in NT.
      • I do NOT place manual orders
      • entries per direction is set to 1
      • strategy entry handling is set to Unique
      • I'm running with Calculate on Bar Close
      • Arrows always show up

      I did make some adjustments to the nesting and the situation somewhat improved now. I also added a third time frame (15 sec) because I suspected 2 sec was too short to let an order fill. So now I have 3 different timeframes: 15 sec for opening, 2 sec for the BE and trailing orders and renko to reset everything once flat. This seems to work better


      I will test more and get back to you next week !!

      Comment


        #4
        it's seem you not prevent to enter to a news position during the time your orders are in pending/accpeted/working stage.

        When you submit an order, it take time to be seded to server, be accpeted and go on working stage, and the market can spend other some more time for filling it if you order price are above/under current prce (depending trade direction), and eventualy can never be filled.

        So first for test this, try take order at On Market price, if it's not happen more, it's that, update your code for wait for yoru order are filled before placing another one.

        MarketPosition go for Long or Short only after you order are filled.

        Comment


          #5
          Originally posted by Spinn View Post


          Code:
          protected override void OnBarUpdate()
                  {            
                      {  if (BarsInProgress == 0)
                             if (Position.MarketPosition == MarketPosition.Flat
                          && LLA == null
                          && Laguerre(0.6).LaguerreOut[0] > 0.6
                          && Laguerre(0.6).LaguerreOut[0] > Laguerre(0.6).LaguerreOut[1] 
                                )
                          {
                          LLA = EnterLong(0, DefaultQuantity, "LLA");
                          DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0] + -65 * TickSize, Color.Lime);
                          }
                       }
          
          
                   }
          I think I saw something related in my going live - the fill is obviously not immediate unlike market replay.

          So where you have the print statement, use your own variable to say you are long, and check that in your condition rather than MarketPosition.

          Reset it at the end of the day or next morning (or both).

          Comment


            #6
            Generaly, in my code, i'm considering MarketPosition when i'm don't care the information come late, but only for Long and Short, because you can have MarketPosition:Flat during a order is in pending submission.

            So for check just after i'm send an order for see whats happen, i'm checking:

            LLA.OrderState:
            When the value are:

            OrderState.PendingSubmission, just wait, ity's not send to sevreur or server not repsonding yet
            OrderState.Rejected or OrderState.Unknown, you order are refused and never go on market.
            OrderState.Accepted, ok it's accepted, it's the state where StopLost order stay until trigerred
            OrderSate.Working: it's wait for filling, that mean it's on market (at limit price) and waiting to be filled (price reach the limit price condition)
            OrderState.Filled or PartFilled: you are On MArketPosition Short or long, IMarketPosiiton be updated soon
            OrderState.Cancelled you have cancelled the order before tit's filled.

            Comment


              #7
              Ok, very good points you both make, Twanaar and sledge. Thank you both for taking time to write down your take on my problem. Truly appreciated

              I will adjust my code accordingly and report back to you guys soon.
              Last edited by Spinn; 11-01-2016, 11:22 AM. Reason: typo

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by judysamnt7, 03-13-2023, 09:11 AM
              4 responses
              59 views
              0 likes
              Last Post DynamicTest  
              Started by ScottWalsh, Today, 06:52 PM
              4 responses
              36 views
              0 likes
              Last Post ScottWalsh  
              Started by olisav57, Today, 07:39 PM
              0 responses
              7 views
              0 likes
              Last Post olisav57  
              Started by trilliantrader, Today, 03:01 PM
              2 responses
              21 views
              0 likes
              Last Post helpwanted  
              Started by cre8able, Today, 07:24 PM
              0 responses
              10 views
              0 likes
              Last Post cre8able  
              Working...
              X