Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop order are pending, why ?

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

    Stop order are pending, why ?

    Hi everybody,

    I have a problem : when I trade a lot of contract with my system, some stop orders remains pending (often a few to half) so it could be a big disaster if I'm not front of my computer.

    Here is the code :

    Code:
                        EnterShort(Numbercontract1, "Vente");
    				EnterShort(Numbercontract2, "Vente2");
    				SetStopLoss( "Vente", CalculationMode.Ticks,8, false);
    				SetProfitTarget("Vente", CalculationMode.Ticks,8);
    				SetStopLoss( "Vente2", CalculationMode.Ticks,8, false);
    				SetProfitTarget("Vente2", CalculationMode.Ticks,23);

    Looking forward your answers,

    It comes from the fact I can manage the number of contract from the indicator box ?

    Thanks a lot !

    After

    #2
    Hello After,

    Thank you for your post.

    I see no issues with the code. Please send me your log and trace files for today so that I may look into what occurred. You can do this by going to the Control Center-> Help-> Mail to Platform Support. Please place this thread in the subject line: "http://www.ninjatrader.com/support/forum/showthread.php?t=71015"

    Comment


      #3
      Thanks Patrick

      Here you can see the answer of the Ninja support :

      Hello,
      Thank you for writing in today. Looking in your log file for today, I can see numerous orders using the same OCO ID. Have you been leaving OCO turned on while placing more than one set of orders, by chance? If so, this can cause any orders after the second order placed with the same OCO ID to be stuck in a pending state, as it causes issues with the information being sent from the platform to your broker.
      To avoid this, please turn OCO off after each set of bracketed orders, then turn it on once more before placing the next set of bracketed orders. This will cause NinjaTrader to create new OCO ID's for each set of orders, which should eliminate this issue.

      Here you can see the whole code :

      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>
          /// Enter the description of your strategy here
          /// </summary>
          [Description("Enter the description of your strategy here")]
          public class Lynx3012 : Strategy
          {
             #region Variables
              // Wizard generated variables
                  private double Level = 1; 
                 
              // 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 = true;
      			
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {    
      			
      			if (CurrentBar>20) {
      		
      			
      			
      			
      			
      			///////Indicateur final
      			
      	
      				
      				if (Close[0]>Level && Close[1]<Level) {
      				
      				EnterShort(6, "Vente");
      				EnterShort(6, "Vente2");
      				SetStopLoss( "Vente", CalculationMode.Ticks,8, false);
      				SetProfitTarget("Vente", CalculationMode.Ticks,8);
      				SetStopLoss( "Vente2", CalculationMode.Ticks,8, false);
      				SetProfitTarget("Vente2", CalculationMode.Ticks,23);
      				
      				
      			}
      			
      		
      			
      			
      			
      			if (Close[0]<Level && Close[1]>Level) {
      				
      				
      				EnterLong( 6, "Achat");
      				EnterLong( 6, "Achat2");
      				SetStopLoss( "Achat", CalculationMode.Ticks,8, false);
      				SetProfitTarget("Achat", CalculationMode.Ticks,8);
      				SetStopLoss( "Achat2", CalculationMode.Ticks,8, false);
      				SetProfitTarget("Achat2", CalculationMode.Ticks,23);
      			
      				
      				
      			}
      			
      			
      			
      			if (Position.MarketPosition == MarketPosition.Long)
      			{
      				// Once the price is greater than entry price+50 ticks, set stop loss to breakeven
      				if (Close[0] > Position.AvgPrice + 6 * TickSize)
      				{
      					SetStopLoss( "Achat2", CalculationMode.Price, Position.AvgPrice, false);
      				}
      			}
      			
      			if (Position.MarketPosition == MarketPosition.Short)
      			{
      				// Once the price is greater than entry price+50 ticks, set stop loss to breakeven
      				if (Close[0] < Position.AvgPrice - 6 * TickSize)
      				{
      					SetStopLoss( "Vente2", CalculationMode.Price, Position.AvgPrice, false);
      				}
      			}
      			
      			
      		
      		
      		}
      			
      			
      			
              }
      
             #region Properties
      
              [Description("")]
              [GridCategory("Parameters")]
              public double LEVEL
              {
                  get { return Level; }
                  set { Level = Math.Max(1, value); }
              }
      
         
      	
              #endregion
          }
      }





      I absolutely don't understand what I should modify, could someone help me ?

      Thanks a lot !

      Comment


        #4
        Hello After,

        Thank you for your response.

        The Set() methods will use their own OCO id and should not run into the issue Dave explained. So your strategy should be fine on this front. However, the strategy does not reset it's Set() methods at any point in the strategy when you are flat. I would also ask if the strategy is intended to reverse your position?

        For an example on resetting the Set() methods when flat please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3222

        I look forward to your response.

        Comment


          #5
          Thanks Pat !

          "I would also ask if the strategy is intended to reverse your position?"

          No never, it's just one signal (buy or sell) with :
          6 contracts with one stop loss and one take profit
          6 contracts with the same stop loss but another take profit

          You mean, I just have to reset the stop loss like this when I'm flat ?

          Code:
          if (Position.MarketPosition == MarketPosition.Flat)
          			{
          				SetStopLoss(CalculationMode.Ticks, stoplossticks);
          }

          Comment


            #6
            Hello After,

            You mean, I just have to reset the stop loss like this when I'm flat ?
            Code:
            if (Position.MarketPosition == MarketPosition.Flat)
            			{
            				SetStopLoss(CalculationMode.Ticks, stoplossticks);
            }
            That is correct.

            If the strategy is not intended to reverse the position I would try setting Position.MarketPosition == MarketPosition.Flat as one of the entry conditions both long and short.

            Comment


              #7
              Okay thanks a lot !

              I'm curious, why should I reset the stop which goes to breakeven as when there is a signal the system reads :

              Code:
              SetStopLoss( "Achat", CalculationMode.Ticks,8, false);
              Ninja keeps in memory previous stop loss and it could create issue ?


              Moreover, this line could help concerning our issue in the initialize part or not at all ?

              Code:
              EntriesPerDirection = 1;

              Comment


                #8
                Hello After,

                Thank you for your response.
                Originally posted by After View Post
                Ninja keeps in memory previous stop loss and it could create issue ?
                That is correct.
                Originally posted by After View Post
                Moreover, this line could help concerning our issue in the initialize part or not at all ?

                Code:
                EntriesPerDirection = 1;
                Not necessarily, as the Stop Loss would still be using the previous value unless reset.

                Comment


                  #9
                  Okay thanks Pat !

                  I have another system on forex, same thing with stop loss, but those are variable. Should I reset them ? If yes, how ? Because I don't know what will be the next stop loss

                  Comment


                    #10
                    Hi After,

                    Thanks for your note.

                    I would recommend that you set the stop loss one line before submitting the entry so that the new entry when filled uses the correct stop loss.

                    That or just any reasonable amount of ticks when resetting the stop loss when flat.

                    If you set the stop loss just before you call the entry, this may work better for you.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Chelsea

                      I go back to you because we still got this problem : stop orders remains pending

                      The system resets (when it's flat) the stop which moves to breakeven.

                      How could we do ? We don't got any error message in the log

                      It's very annoying, we will have to change the platform if this problem remains

                      Thanks a lot !
                      Last edited by After; 01-07-2015, 08:49 AM.

                      Comment


                        #12
                        Hello After,

                        Have you tried my suggestion of setting the stop one line above the entry?

                        Is the stop loss not being set to the new price before the order goes in?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          "Have you tried my suggestion of setting the stop one line above the entry?"

                          Yes

                          "Is the stop loss not being set to the new price before the order goes in?"

                          Don't got it, could you explain ? I would say the stop loss is set before the order goes in

                          Here you can see a part of the code with modifications :

                          Code:
                                                          if (X) {
                                                          SetStopLoss( "Achat", CalculationMode.Ticks,8, false);
                          				SetProfitTarget("Achat", CalculationMode.Ticks,8);
                          				SetStopLoss( "Achat2", CalculationMode.Ticks,8, false);
                          				SetProfitTarget("Achat2", CalculationMode.Ticks,23);
                          				EnterLong( 6, "Achat");
                          				EnterLong( 6, "Achat2");
                          				}
                          				
                          			
                          			
                          			
                          			
                          			if (Position.MarketPosition == MarketPosition.Long)
                          			{
                          				// Once the price is greater than entry price+50 ticks, set stop loss to breakeven
                          				if (Close[0] > Position.AvgPrice + 6 * TickSize)
                          				{
                          					SetStopLoss( "Achat2", CalculationMode.Price, Position.AvgPrice, false);
                          				}
                          			}
                          			
                          			if (Position.MarketPosition == MarketPosition.Short)
                          			{
                          				// Once the price is greater than entry price+50 ticks, set stop loss to breakeven
                          				if (Close[0] < Position.AvgPrice - 6 * TickSize)
                          				{
                          					SetStopLoss( "Vente2", CalculationMode.Price, Position.AvgPrice, false);
                          				}
                          			}
                          			
                          			if (Position.MarketPosition == MarketPosition.Flat)
                          			{
                          				SetStopLoss( "Achat2", CalculationMode.Ticks,8, false);
                          				SetStopLoss( "Vente2", CalculationMode.Ticks,8, false);
                                      }

                          Comment


                            #14
                            Hi After,

                            When the EnterLong( 6, "Achat"); fills, how many ticks away is the stop loss set? (it should be 8 ticks).

                            What is the incorrect behavior?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Yeah each stop loss is set on 8 ticks, but some (the number is random) are pending, not working !

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by futtrader, 04-21-2024, 01:50 AM
                              4 responses
                              41 views
                              0 likes
                              Last Post futtrader  
                              Started by Option Whisperer, Today, 09:55 AM
                              1 response
                              11 views
                              0 likes
                              Last Post bltdavid  
                              Started by port119, Today, 02:43 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post port119
                              by port119
                               
                              Started by Philippe56140, Today, 02:35 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Philippe56140  
                              Started by 00nevest, Today, 02:27 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post 00nevest  
                              Working...
                              X