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

Double entry/exit in multi instrument strategy

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

    Double entry/exit in multi instrument strategy

    Hi,

    I have a working strategy using multiple instruments, however, I seem to have gotten a problem with it. When I attach a SetProfitTarget(), the strategy will post a double entry and exit every time it hits the profit target on the same bar. If I set the profit target high enough for it to not get hit at all then the strategy will run as normal. If I set it to a single tick then I will get a double entry and exit on every signal that triggers it.

    This problem seems to only happen when I use a multi instrument strategy, it doesn't happen on a single instrument strategy.

    Anyone have any ideas on how I can fix this problem?

    #2
    Hello Stoop,

    Thank you for your post.

    Can you post screenshots of the difference with the double entries and the single entry that you are seeing?

    To send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file.

    For detailed instructions please visit the following link

    http://take-a-screenshot.org/
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Hi Cal,

      Thanks for your reply, I have attached a screenshot of two entries, one with the profit target hit and one without it hitting the profit target.
      It's run on the NQ and ES instruments.
      Attached Files

      Comment


        #4
        Hello Stoop,

        Thank you for your response.

        Can you provide the code used that produces the double entry?

        Comment


          #5
          Hi PatrickH,

          I created an example code that is producing the same results:

          Code:
          #region Using declarations
          using System;
          using System.ComponentModel;
          using System.Diagnostics;
          using System.Drawing;
          using System.Drawing.Drawing2D;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Data;
          using NinjaTrader.Indicator;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Strategy;
          #endregion
          
          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
             /// <summary>
             /// </summary>
             [Description("")]
             public class example : Strategy
             {
                 #region Variables
          
          // User defined variables (add any user defined variables below)
                 #endregion
          
                 /// <summary>
                 /// This method is used to configure the strategy and is called once before any strategy method is called.
                 /// </summary>
                 protected override void Initialize()
          {	
          
          	CalculateOnBarClose = false;
          
          	TraceOrders      = true;
          	Add("ES 06-14", PeriodType.Day, 1);
          	SetProfitTarget(CalculationMode.Ticks, 15);
          }
          
          
                 /// <summary>
                 /// Called on each bar update event (incoming tick)
                 /// </summary>
                 protected override void OnBarUpdate()
                 {
          
                    if ((Closes[1][0] - 10) > Opens[1][0]){EnterLong(0,1,"");}
          
                    if (Closes[1][0] < Opens[1][0]){ExitLong(0,"","");}
          		
                 } // OnBarUpdate
          
             }
          }

          Comment


            #6
            Hello Stoop,

            Thank you for your patience.

            Please add a BarsInProgress check for 1 in your code to prevent the entries twice due to the OnBarUpdate() being called twice (once for ES and once for NQ):
            Code:
            			if(BarsInProgress == 1)
            			{
            			if ((Closes[1][0] - 10) > Opens[1][0]){EnterLong(0,1,"");}
            			if (Closes[1][0] < Opens[1][0]){ExitLong(0,"","");}
            			}

            Comment


              #7
              That made it work, thank you very much! Really great support you guys have here.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by BarzTrading, Today, 07:25 AM
              2 responses
              23 views
              1 like
              Last Post BarzTrading  
              Started by devatechnologies, 04-14-2024, 02:58 PM
              3 responses
              20 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by tkaboris, Today, 08:01 AM
              0 responses
              4 views
              0 likes
              Last Post tkaboris  
              Started by EB Worx, 04-04-2023, 02:34 AM
              7 responses
              163 views
              0 likes
              Last Post VFI26
              by VFI26
               
              Started by Mizzouman1, Today, 07:35 AM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Working...
              X