Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Profit Target Generates Unwanted Additional Orders...

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

    Profit Target Generates Unwanted Additional Orders...

    I am testing a strategy with market replay and notice some odd behavior. The following example occurred for 8/5/14 while testing the 09-14 ES contract, using 1-minute bars:

    --- 3 contracts were correctly entered with separate EnterLongLimit operations at 1921.50 when Bar[0] exceeded the high of Bar[1] (calculate on Bar Close = False);

    --- the first, second and third profit targets were all hit in succession, within the 1-minute time period of Bar[0], but each approx. 10 seconds apart from one another.

    --- However, after the targets were all hit, NT generated a limit order for the full position again. That is, an order was generated for 3 contracts at 1921.50 again even though the signal is now stale (since it was triggered, filled, and reached target).

    The algorithm is a simple comparison of bars and indicators, such as if (High[1] > High[2]), and so forth.

    I suppose that NT could still be comparing the prior bar as against the current bar (which is Bar[0]) and will continue to do so until the minute is closed and we finally move away from Bar[0].

    If that is the case, how do I stop NT from working multiple orders within the same bar?

    If that is not the case, is there anything else that could be causing this?

    Thanks in advance.

    #2
    Hello Scott_in_FL,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    You could add a check for the MarketPosition to ensure you are flat: http://www.ninjatrader.com/support/h...etposition.htm

    Comment


      #3
      We use MarketPosition = Flat and, for now, it seems that BarsSinceEntry() > 1 keeps the problem discussed in my original post from happening.

      However, now another issue has presented itself. It seems that using BarsSinceEntry() in each condition causes some interference and no trades are placed.

      I have narrowed it down and it appears that using BarsSinceEntry() works fine if it is in 1, 2 or 3 of the 4 conditions (any combination). But as soon as it is added to the fourth condition, the entire algorithm makes no trades. Any idea about what is causing this? Here is a snippet of the code:

      CalculateOnBarClose = false;

      EntriesPerDirection =
      3;
      EntryHandling = EntryHandling.AllEntries;
      }
      ///<summary>
      /// Called on each bar update event (incoming tick)
      ///</summary>
      protectedoverridevoid OnBarUpdate()
      {
      // Condition set 1 short position on red bar
      if (Position.MarketPosition == MarketPosition.Flat
      && BarsSinceEntry(
      ) > 1
      && check some other things

      {
      Enter Short1, Short2, and Short3
      }

      // Condition set 2 short position on green bar
      if (Position.MarketPosition == MarketPosition.Flat
      This is where we cannot place another BarsSinceEntry() object or the entire algorithm returns zero trades. But this problem exists in any of the conditions if the other three have this object.

      && (High[
      1] > High[2])
      && check some other things

      {
      Enter Short1, Short2, and Short3
      }

      // Condition set 3 long position on green bar
      // Condition set 4 long position red bar

      Condition sets 3 and 4 basically do the same thing as 1 and 2, but establish long trades. Again, the BarsSinceEntry() is only a problem if it is in all 4 conditions.



      Last edited by Scott_in_FL; 02-17-2015, 03:05 PM.

      Comment


        #4
        Hello Scott_in_FL,

        Thank you for your response.

        BarsSinceEntry() would the correct method to take here to avoid the entry again right when the targets fill. However, if it is set on each condition how would an entry ever be taken if it must first wait for an entry to take one?

        So we have to get into an initial trade. You could use a bool to allow the first trade condition and then set it to false and run the strategy as normal. For example:
        Code:
        if (Position.MarketPosition == MarketPosition.Flat
        && BarsSinceEntry() > 1
        && myBool
        && check some other things
        
        {
        Enter Short1, Short2, and Short3
        }
        
        // then....
        
        if (Position.MarketPosition == MarketPosition.Flat
        && BarsSinceEntry() > 1
        && check some other things
        
        {
        Enter Short1, Short2, and Short3
        }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Skifree, Yesterday, 06:06 PM
        2 responses
        14 views
        0 likes
        Last Post Skifree
        by Skifree
         
        Started by csksbot, Today, 11:11 AM
        0 responses
        1 view
        0 likes
        Last Post csksbot
        by csksbot
         
        Started by mtamaku, Today, 11:08 AM
        0 responses
        2 views
        0 likes
        Last Post mtamaku
        by mtamaku
         
        Started by franjcy, Today, 03:27 AM
        3 responses
        15 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by Ryan333, Today, 10:48 AM
        2 responses
        5 views
        0 likes
        Last Post Ryan333
        by Ryan333
         
        Working...
        X