Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issues - Overfill and Session time

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

    Issues - Overfill and Session time

    Greetings all,

    I am having several issues which hopefully someone can help me shed light.

    1. I have a strategy with various entry criteria.
    -Each execution criteria is in an if(Position.MarketPosition == MarketPosition.Flat) - in other words, it shouldn't enter long unless we are already flat.
    -During real live execution, however, the strategy will have multiple entries from the same signal
    -For example, today the strategy has given the entry single twice in the same second, leaving me with a position twice what I should have.
    -To prevent the strategy from overfill, I have all of the OnBarUpdate entry methods pasted inside of an OnExecution procedure so that if I get a flatten and reversal single at the same time, my strategy will not die.



    2. I am trying to get my strategy to ExitOnClose on a custom session.
    -My session starts Sunday at 5pm and ends Friday at 3pm.
    -There is a bug in Ninjatrader such that custom sessions do not calculate close correctly - in other words it flattens every day at 3pm throughout the entire week rather than on Friday
    -I have tried to workaround by having the following code execute, but since my session ends at 3pm, no market data is available at this time.

    protected override void OnMarketData(MarketDataEventArgs e)
    {
    //Flatten us at 3 on Friday
    if (Time[0].DayOfWeek == DayOfWeek.Friday && ToTime(Time[0]) >= 150000)
    {
    if (Position.MarketPosition == MarketPosition.Long)
    {
    ExitLong();
    }
    if (Position.MarketPosition == MarketPosition.Short)
    {
    ExitShort();
    }

    }
    }

    #2
    Follow up on problem 1:

    Here's what the strategy looks like:

    OnExecution
    {
    Criteria 1
    if flat, then enter/place stop
    Criteria 2
    if flat, then enter/place stop
    Criteria 3
    if flat, then enter/place stop
    }

    OnBarUpdate
    {
    Criteria 1
    if flat, then enter/place stop
    Criteria 2
    if flat, then enter/place stop
    Criteria 3
    if flat, then enter/place stop

    ExitCriteria
    }


    I organized it this way to prevent an OverFill. I was receiving an OverFill because my Exit Criteria can be my entry criteria in some circumstances. By requiring it to wait until the previous order had gone through, I was able to circumvent the OverFill problem...for the past week. But, last night I had a trade enter 3 times long all in the same second and it collapsed with an OverFill.
    Last edited by Moody1337; 11-07-2011, 11:57 AM.

    Comment


      #3
      Moody,

      Your market position won't be Long or Short until an order is filled. As such, if your strategy is generating a lot of signals it would be possible to be in two trades at once. You can try to override this by using a flag, OnOrderUpdate(), and OnExecution().

      OnExecution() : http://www.ninjatrader.com/support/h...nexecution.htm

      OnOrderUpdate() : http://www.ninjatrader.com/support/h...rderupdate.htm

      As far as your second question, the time to flatten is daily, not weekly. If you want to end trading at a particular time on a particular day, you can use a time filter like you just have. You could set the closing time a few seconds before the actual closing time to allow enough time for the orders to process.

      Using time filters : http://www.ninjatrader.com/support/f...ead.php?t=3226

      Please let me know if I may assist further.
      Adam P.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_AdamP View Post
        Moody,

        Your market position won't be Long or Short until an order is filled. As such, if your strategy is generating a lot of signals it would be possible to be in two trades at once. You can try to override this by using a flag, OnOrderUpdate(), and OnExecution().

        OnExecution() : http://www.ninjatrader.com/support/h...nexecution.htm

        OnOrderUpdate() : http://www.ninjatrader.com/support/h...rderupdate.htm

        As far as your second question, the time to flatten is daily, not weekly. If you want to end trading at a particular time on a particular day, you can use a time filter like you just have. You could set the closing time a few seconds before the actual closing time to allow enough time for the orders to process.

        Using time filters : http://www.ninjatrader.com/support/f...ead.php?t=3226

        Please let me know if I may assist further.

        Thanks for the reply Adam,

        For problem 1, this is exactly what I'm doing and from what I can tell, I am using it exactly as designed, however I am still getting multiple entries. In my previous post I showed how I used those two procedures. Please show me my oversight in this!

        Here is an image of my problem. I removed signal names, but in the situation in which it enters multiple positions, it is the same signal...in other words, the same signal executes multiple times per second despite the criteria to only enter if flat.





        For problem 2: my fallback is to set it to close a second before, however to me this is a "dirty" solution as that it is possible in that 1 second a new entry condition could be generated on the close of the current bar. I feel that there should be some hard-coded way of dealing with this rather than a potentially unreliable workaround, but for now I will set it equal to the 1 second prior.

        Comment


          #5
          Originally posted by NinjaTrader_AdamP View Post
          Moody,

          Your market position won't be Long or Short until an order is filled. As such, if your strategy is generating a lot of signals it would be possible to be in two trades at once. You can try to override this by using a flag, OnOrderUpdate(), and OnExecution().

          OnExecution() : http://www.ninjatrader.com/support/h...nexecution.htm

          OnOrderUpdate() : http://www.ninjatrader.com/support/h...rderupdate.htm

          As far as your second question, the time to flatten is daily, not weekly. If you want to end trading at a particular time on a particular day, you can use a time filter like you just have. You could set the closing time a few seconds before the actual closing time to allow enough time for the orders to process.

          Using time filters : http://www.ninjatrader.com/support/f...ead.php?t=3226

          Please let me know if I may assist further.
          I just read closer and I see that you recommended OnOrderUpdated - this is a procedure I am not using yet...I will look into it and see if I can use it...thanks!

          Comment


            #6
            Moody,

            Yes, please give that a try and let me know if you manage to get your strategy working.

            For problem 2: my fallback is to set it to close a second before, however to me this is a "dirty" solution as that it is possible in that 1 second a new entry condition could be generated on the close of the current bar. I feel that there should be some hard-coded way of dealing with this rather than a potentially unreliable workaround, but for now I will set it equal to the 1 second prior.
            You could try making your session longer by a minute if data is available. The issue is that if you want to give yourself enough time to close the order, you need to close it before the session ends, because this is the time typically when orders can't be placed since the exchange is closed. If you are setting your session to an earlier time than when the exchange closes, then you are essentially telling NinjaTrader that is when the exchange closes so it expects it can't place orders.

            Please let me know if I may assist further.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Hey Adam, thanks for the follow-up.

              I've looked more into problem 1 and I feel I am doing the right thing according to Ninjatrader's definitions of how these procedures work. It is obvious that I am not doing the correct thing due to multiple positions however - could you show me my lack of understanding of these procedures.

              Here's my reasoning of a step-through of a trade.


              Step-by-Step
              -A position is live
              -An entry signal / reversal occurs but we are not flat in OnBarUpdate so only the exit criteria executes
              -We exit our live position and cancel stop using ExitLong or ExitShort
              -OnExecution, the criteria is repeated again since we just flattened a position - this time we are flat so entry is valid
              -The entry occurs and we have a new trade
              -OnExecution is read again, but we are not flat, so no new/double/triple position is generated

              Here is the structure of my code one more time:

              OnExecution
              {
              Criteria 1
              if flat, then enter/place stop
              Criteria 2
              if flat, then enter/place stop
              Criteria 3
              if flat, then enter/place stop
              }

              OnBarUpdate
              {
              Criteria 1
              if flat, then enter/place stop
              Criteria 2
              if flat, then enter/place stop
              Criteria 3
              if flat, then enter/place stop

              ExitCriteria // Note - ExitLong and ExitShort is used here so it cancels existing stops
              }
              Last edited by Moody1337; 11-07-2011, 12:52 PM.

              Comment


                #8
                Moody,

                Perhaps the following post will help you.



                Please read post #2.

                Please let me know if I may assist you further.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_AdamP View Post
                  Moody,

                  Perhaps the following post will help you.



                  Please read post #2.

                  Please let me know if I may assist you further.
                  Brilliant, thank you for the help, I believe this has solved it...this was a piece of Ninjatrader functionality I needed!

                  Comment


                    #10
                    Moody,

                    You're welcome.

                    Please don't hesitate to contact us should you require additional assistance.
                    Adam P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by AaronKoRn, Today, 09:49 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post AaronKoRn  
                    Started by carnitron, Today, 08:42 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post carnitron  
                    Started by strategist007, Today, 07:51 PM
                    0 responses
                    10 views
                    0 likes
                    Last Post strategist007  
                    Started by StockTrader88, 03-06-2021, 08:58 AM
                    44 responses
                    3,980 views
                    3 likes
                    Last Post jhudas88  
                    Started by rbeckmann05, Today, 06:48 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post rbeckmann05  
                    Working...
                    X