Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exceeded entry signals limit based on EntryHandling and EntriesPerDirection ...

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

    Exceeded entry signals limit based on EntryHandling and EntriesPerDirection ...

    Hello,

    Please find the code below:

    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 S01test : Strategy
        {
            #region Variables
    
    		// Dane instrumentu
    		private string				inst = "";
    		private int					ctf = 0;
    		
    		// Parametry
    		private W01v01				w;
    		private int					o_entry = 20;
    		private int					o_sl = 20;
    		private int					kierunek = 1;
    		private int					ryzyko = 50000;
    		private double				kurs = 1;
    		
    		// Zlecenia				
    		private IOrder				O_Long_0 = null;
    		private IOrder				O_Long_1 = null;
    
    		
    		// Backtest
    		private bool				bt = false;
    		
            #endregion
    
            /// <summary>
            /// </summary>
            protected override void Initialize()
            {
                if (bt)
    			{
    				Add("$EURJPY", BarsPeriod.Id, BarsPeriod.Value); 
    			}	
    						
    			CalculateOnBarClose = true;
    			TraceOrders = true;
            }
    
            /// <summary>
            /// </summary>
            protected override void OnBarUpdate()
            {
    			if (bt && BarsInProgress == 0)
    			{												
    				return;
    			}
    			
    			if (CurrentBar < BarsRequired)
    			{												
    				return;
    			}
    			
    			
    			inst = Instrument.MasterInstrument.Name;
    			ctf = BarsPeriod.Value;
    			w = W01v01(kierunek, o_entry, o_sl);
    			
    			
    			// M03 Start | W piatek po 21:00 nic nie robimy (tylko dane Live)
    			if (!Historical && Time[0].DayOfWeek == DayOfWeek.Friday && ToTime(Time[0]) > 210000)
    			{
    				Print(Time[0]+ " | " + DayOfWeek.Friday);
    				return;
    			}
    			// M03 End | W piatek po 21:00 nic nie robimy
    			
    			
    			// LONG
    			
    			
    			if (kierunek == 1 && w.DC.ContainsValue(0) && w.DC[0] == 0)
    			{							
    				if (BarsInProgress == 0)	{M01L(BarsInProgress, ref O_Long_0);}
    				if (BarsInProgress == 1)	{M01L(BarsInProgress, ref O_Long_1);}
    			}
    					
    			if (kierunek == 1 && Position.MarketPosition == MarketPosition.Long &&
    				DonchianChannel(o_sl).Lower[0] > DonchianChannel(o_sl).Lower[1])
    			{
    				M02L(BarsInProgress);
    			}
    			
            }
    
    		#region M01 LONG | USTAWIENIE ZLECENIA DONCHIAN	
    		
    		void M01L(int bip, ref IOrder O_L)
    		{
    			double	entry = DonchianChannel(o_entry).Upper[0] + 3 * TickSize;
    			double	sl = DonchianChannel(o_sl).Lower[0] - 1 * TickSize;
    			int		psize = (int) ((ryzyko / (entry - sl)) * kurs);
    			
    			//Wymogi FXCM -> wielkosc pozycji = min. 1000 i dalej wielokrotnosc 1000
    			if (psize >= 800)
    			{
    				int		psize_fxcm = (int)(Math.Round((double)psize/1000, 0) * 1000);
    			
    				O_L = EnterLongStop(bip, true, psize_fxcm, entry, "Long_"+bip);
    				SetStopLoss("Long_"+bip, CalculationMode.Price, sl, false);
    			
    				Print(Time[0]+ " | " +inst+ " | " +ctf+ " | Zlecenie LONG | PSize = " +psize+ "/" +psize_fxcm);
    			}
    			if (psize < 800)
    			{
    				Print(Time[0]+ " | " +inst+ " | " +ctf+ " | Brak zlecenia LONG - za male PSize (" +psize+ ")");
    			}
    		}
    		
    		#endregion
    		
    		#region M02 LONG | PROWADZENIE POZYCJI DONCHIAN
    		
    		void M02L(int bip)
    		{
    			double	ts = DonchianChannel(o_sl).Lower[0] - 1 * TickSize;
    				
    			SetStopLoss("Long_"+bip, CalculationMode.Price, ts, false);
    		}
    		
    		#endregion
    
        }
    }
    I do the following:
    A1. I run the above code on $EURJPY with bt = false
    A2. I get trade parameters as given in the attachment 1

    B1. I run the above code on $EURJPY with bt = true
    B2. I get trade parameters as given in the attachment 2

    Please note I get different entry price.
    In B case, my entry price do not get updated. The reson is: 'Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'.

    I use Entry handling = UniqueEntries and Entriesperdirection = 1.

    Why is this happening? My understandig is that it should be the same in both situations.
    Can you help me what am I doing wrong here?

    Just in case I have also sent you mail to support with trace and logs files along with link to this thread.
    Attached Files
    Last edited by kucharek; 05-25-2015, 02:51 AM.

    #2
    Hello kucharek,

    Thank you for your post.

    Isolate the cause here, create a new script that is in fact multi-series with no bool that switches between. Then test that your custom method is in fact working as expected for the secondary series.

    Comment


      #3
      Hello,

      I did as you suggested but the problem is still there. Please find code below and screenshot attached.

      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 S01test2 : Strategy
          {
              #region Variables
      
      		// Dane instrumentu
      		private string				inst = "";
      		private int					ctf = 0;
      		
      		// Parametry
      		private W01					w;
      		private int					o_entry = 20;
      		private int					o_sl = 20;
      		private int					kierunek = 1;
      		private int					ryzyko = 50000;
      		private double				kurs = 1;
      		
      		// Zlecenia				
      		private IOrder				O_Long_0 = null;
      		private IOrder				O_Long_1 = null;
      		
              #endregion
      
              /// <summary>
              /// </summary>
              protected override void Initialize()
              {
            		Add("$EURJPY", BarsPeriod.Id, BarsPeriod.Value); 	
      						
      			CalculateOnBarClose = true;
      			TraceOrders = true;
              }
      
              /// <summary>
              /// </summary>
              protected override void OnBarUpdate()
              {		
      			if (CurrentBar < BarsRequired)
      			{												
      				return;
      			}
      			
      			
      			inst = Instrument.MasterInstrument.Name;
      			ctf = BarsPeriod.Value;
      			w = W01(kierunek, o_entry, o_sl);
      			
      			
      			// M03 Start | W piatek po 21:00 nic nie robimy (tylko dane Live)
      			if (!Historical && Time[0].DayOfWeek == DayOfWeek.Friday && ToTime(Time[0]) > 210000)
      			{
      				Print(Time[0]+ " | " + DayOfWeek.Friday);
      				return;
      			}
      			// M03 End | W piatek po 21:00 nic nie robimy
      			
      			
      			// LONG
      			
      			
      			if (kierunek == 1 && w.DC.ContainsValue(0) && w.DC[0] == 0)
      			{							
      				if (BarsInProgress == 0)	{M01L(BarsInProgress, ref O_Long_0);}
      				if (BarsInProgress == 1)	{M01L(BarsInProgress, ref O_Long_1);}
      			}
      					
      			if (kierunek == 1 && Position.MarketPosition == MarketPosition.Long &&
      				DonchianChannel(o_sl).Lower[0] > DonchianChannel(o_sl).Lower[1])
      			{
      				M02L(BarsInProgress);
      			}
      			
              }
      
      		#region M01 LONG | USTAWIENIE ZLECENIA DONCHIAN	
      		
      		void M01L(int bip, ref IOrder O_L)
      		{
      			double	entry = DonchianChannel(o_entry).Upper[0] + 3 * TickSize;
      			double	sl = DonchianChannel(o_sl).Lower[0] - 1 * TickSize;
      			int		psize = (int) ((ryzyko / (entry - sl)) * kurs);
      			
      			//Wymogi FXCM -> wielkosc pozycji = min. 1000 i dalej wielokrotnosc 1000
      			if (psize >= 800)
      			{
      				int		psize_fxcm = (int)(Math.Round((double)psize/1000, 0) * 1000);
      							
      				O_L = EnterLongStop(bip, true, psize_fxcm, entry, "Long_"+bip);
      				SetStopLoss("Long_"+bip, CalculationMode.Price, sl, false);
      			
      				Print(Time[0]+ " | " +inst+ " | " +ctf+ " | Zlecenie LONG | PSize = " +psize+ "/" +psize_fxcm);
      			}
      			if (psize < 800)
      			{
      				Print(Time[0]+ " | " +inst+ " | " +ctf+ " | Brak zlecenia LONG - za male PSize (" +psize+ ")");
      			}
      		}
      		
      		#endregion
      		
      		#region M02 LONG | PROWADZENIE POZYCJI DONCHIAN
      		
      		void M02L(int bip)
      		{
      			double	ts = DonchianChannel(o_sl).Lower[0] - 1 * TickSize;
      				
      			SetStopLoss("Long_"+bip, CalculationMode.Price, ts, false);
      		}
      		
      		#endregion
      
          }
      }
      Attached Files

      Comment


        #4
        Hello kucharek,

        Thank you for your patience.

        The executions can have a race condition where the primary series and it's duplicate instrument secondary series have exceed the EntriesPerDirection. It would be recommend to only submit to one BIP, or check that the previous order is in fact accepted before submitting the next.

        Comment


          #5
          I do not understand your reply. Please clarify in more details.

          When I do test with different instruments (for example EURUSD as BIP = 0 and EURJPY as BIP= 1 I get same situation with EURJPY.
          When EURJPY is BIP = 0 the situation is ok.
          I have many examples for such behavour. It is not an exception here.

          Also, as you can see, I have different order names for every BIP so do not understand why order state from BIP = 0 have any relations to order from BIP = 1. Please note I use Entry handling = UniqueEntries so entry BIP = 0 shal be independent of entry BIP = 1.
          Last edited by kucharek; 05-25-2015, 01:47 PM.

          Comment


            #6
            Hello kucharek,

            Thank you for your response.

            What are setting EntriesPerDirection and EntryHandling to?

            Comment


              #7
              We are loosing time here.

              I have already given you this information in my first message:

              I use Entry handling = UniqueEntries and Entriesperdirection = 1.
              Last edited by kucharek; 05-25-2015, 11:55 PM.

              Comment


                #8
                Hello kucharek,

                Thank you for adding that quote.

                Using a basic version of your strategy my executions as the primary and secondary match no matter the primary series I use, however using your code I do not have access to W01v01 in my installation. Would you mind providing this indicator?

                My test example is attached to this response.
                Attached Files

                Comment


                  #9
                  Please find the indicator attached.
                  Attached Files

                  Comment


                    #10
                    Hello kucharek,

                    Thank you for your response.

                    Do you see the error message when running the strategy on a live account, simulation account, backtesting, or even in Market Replay?

                    I am unable to reproduce the same behavior with your strategy in backtesting nor my own strategy.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by pechtri, 06-22-2023, 02:31 AM
                    10 responses
                    124 views
                    0 likes
                    Last Post Leeroy_Jenkins  
                    Started by judysamnt7, 03-13-2023, 09:11 AM
                    4 responses
                    59 views
                    0 likes
                    Last Post DynamicTest  
                    Started by ScottWalsh, Yesterday, 06:52 PM
                    4 responses
                    36 views
                    0 likes
                    Last Post ScottWalsh  
                    Started by olisav57, Yesterday, 07:39 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post olisav57  
                    Started by trilliantrader, Yesterday, 03:01 PM
                    2 responses
                    22 views
                    0 likes
                    Last Post helpwanted  
                    Working...
                    X