Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strategy terminates itself

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

    #16
    Thanks Patrick, I have solved the other problems or errors, but this problem remains. I have posted what comes up in the trace file that could be causing this problem.

    Comment


      #17
      Hello,

      Thank you for the reply.

      You said that you have two strategies running and they are interfering with each other. Are you saying that one of the two strategies is cancelling the other strategies orders?

      Also are these being run on the same instrument and account?


      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #18
        NinjaTrader_Jesse,

        Originally posted by NinjaTrader_Jesse View Post
        You said that you have two strategies running and they are interfering with each other. Are you saying that one of the two strategies is cancelling the other strategies orders?
        Yes!

        Originally posted by NinjaTrader_Jesse View Post
        Also are these being run on the same instrument and account?
        This answers could be found in the attached trace file.
        As you can see they are both run on Sim101 and its 2 different currencypairs, USDCAD and USDSEK. I have re-created this problematic behaviour in both my eSignal datafeed as well as my Simulated datafeed.

        As I also deal with risk positioning, then I need to add other currencypairs using the add() command in Initialize() in order to be able to do that. I was asking if maybe this is causing the problem?

        Please see the attached code and trace file from my previous email where I have attached the code for LoadAllCurrencyPairs() that is using the Add() function and is called from within Initialize().

        A summary of HOW the erroneous behaviour occurs:
        I run 2 independent charts on 2 different currency pairs running my strategy.
        Chart 1 got an order entry.
        When entry on chart number 2 is enabled, it enters its Deactivation() function in my strategy on Chart 2 ( I use a message box for debugging), that disables the strategy on Chart 1.
        In other words, after Chart 1 is in position and when Chart 2 enables its entry then the strategy in Chart 1 is disabled from the code in my strategy on Chart 2, but there is NO message box showing up on Chart 1.
        I added this message box for debugging purposes.

        Also noticed:
        When I have a chart number X running my strategy that has taken an entry position, and then I go to my Positions tab and Close an open position I entered manually before, than this close ALSO disables my strategy in chart X

        Also noticed:
        WHEN, and only WHEN I run my strategy on 2 or more charts using the very same currency pair (Barsinprogress==0) then this erroneous behaviour does NOT appear.
        It only appears when I use different chart windows with different currency pairs.

        What this means is that the strategies are NOT fully isolated, and I think this has something to do with HOW I add the other currency pairs into my primary barsinprogress==0 chart. I have attached the function that adds my other currency pairs (barsinprogress !=0) in this thread.

        Maybe the problems occurs when I open a new chart with a currency pair that has been already opened as a secondary currency pair in the first chart through my Add() function?!?

        These are my parameters in Initialize():
        EntriesPerDirection = 1;
        EntryHandling = EntryHandling.AllEntries;
        ExitOnClose = false;
        RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;
        CalculateOnBarClose = false;
        Enabled = true;
        _currentOrder = null;
        this.LoadAllCurrencyPairs();

        This is myLoadAllCurrencyPairs() function:
        private void LoadAllCurrencyPairs()
        {

        foreach (string pair in this._forextList)
        {

        this.Add("$" + pair, PeriodType.Minute, 1);
        }
        }

        Also, adding my OnBarUpdate() function:
        protected override void OnBarUpdate()
        {
        try
        {
        if (_deActivate)
        {
        DeActivation();
        return;
        }

        if (BarsInProgress != 0)
        return;

        else if (BarsInProgress == 0)
        {
        SettingVariablesAndGraphics();

        if (_currentRayContainer != null)
        {
        ThisInstrumentOrders();
        }
        }
        }
        catch (Exception e)
        {
        if (_firstException)
        {
        _firstException = false;
        CSTUtilities.ExceptionMessage(e);
        }
        }
        }



        Ninjatrader: What is causing this errorneous behaviour?

        Thanks,
        Daniel
        Last edited by warcious; 11-02-2016, 11:30 PM.

        Comment


          #19
          Hello warcious,

          Thank you for your posts on this matter.

          We need to clear a few items up and I would like to request your Log, not just your Trace.
          1. So your "deactivation" logic is your own and you intentionally disable other strategies? This seems to be contrary to your statement that it is unexpected.
          What is your "deactivation" logic? Is this something you can provide to help us assist you in this matter?
          I am confused on the overall logic for DeActivation(). Why would Add() have anything to do with it? Why would it only concern itself with other primary instruments that do not match the current strategies?
          These are all questions I cannot answer without your code or you advising in detail.

          2. The Message Box generally appears when you "deactivate" a strategy?

          3. Closing a position that a strategy is managing from the the Positions tab should disable the strategy that is managing the position.

          I look forward to your response.

          Comment


            #20
            Originally posted by NinjaTrader_PatrickH View Post
            Hello warcious,

            We need to clear a few items up and I would like to request your Log, not just your Trace.
            Attached in this email, but as I stated before, there is nothing of value in the Log file.

            1. So your "deactivation" logic is your own and you intentionally disable other strategies? This seems to be contrary to your statement that it is unexpected.
            What is your "deactivation" logic? Is this something you can provide to help us assist you in this matter?
            The "Deactivation" logic and code is below, and it does NOT intentionally disable other strategies. What happens is that when my first chart window, trading a currencypair is being activated and gets an entry, then when I open a different chart, trading a different currencypair. When this 2:nd chart gets an entry, then somehow it goes to Deactivation() function in strategy running on chart 2, and suddenly disables the 1:st chart window and strategy, so it stops working. As I explained above, it is almost like these strategies somehow effect eachother. BUT, this behaviour does NOT happen if I open a second chart using the same currencypair as I used on the first chart.
            Let me know if this makes sense?

            This is my Deactivate logic:

            private void DeActivation()
            {
            if (_weGotError)
            {
            _currentOrder = null;
            if (Position.MarketPosition != MarketPosition.Flat)
            {
            OtherWayToClosefullPosition();
            return;
            }
            Deactivate();
            CancelAllOrders(true, true);
            _deActivate = false;
            _weGotError = false;
            return;
            }
            if (_checkBoxEnableBarEntry.Checked)
            {
            _checkBoxEnableBarEntry.Checked = false;
            Deactivate();
            }
            //Two deactivations if something goes wrong
            if (_deActivate && _strategyState == StrategyState.Enter && (_currentOrder == null) && Position.MarketPosition == MarketPosition.Flat)
            {
            CancelAllOrders(true, false);
            Deactivate();
            _deActivate = false;
            return;
            }
            else
            {
            if (_strategyState == StrategyState.Enter)
            {
            if (_currentOrder != null && _currentOrder.OrderState != OrderState.Cancelled)
            CancelAllOrders(true, false);
            else
            {
            _deActivate = false;
            _currentOrder = null;
            }
            }
            else if (_strategyState == StrategyState.Exit)
            {
            if (Position.MarketPosition != MarketPosition.Flat)
            {
            OtherWayToClosefullPosition();
            }
            }
            }
            if (_deActivate) return;
            Deactivate();
            }

            And the Deactivate function: Deactive()
            private void Deactivate()
            {
            _strategyState = StrategyState.NotActive;
            }

            LoadAllCurrencyPairs():
            private void LoadAllCurrencyPairs()
            {

            foreach (string pair in this._forextList)
            {
            this.MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
            this.Add("$" + pair, PeriodType.Minute, 1);
            }
            }

            I am confused on the overall logic for DeActivation(). Why would Add() have anything to do with it? Why would it only concern itself with other primary instruments that do not match the current strategies?
            These are all questions I cannot answer without your code or you advising in detail.
            Because when I disable (comment out) the function LoadAllCurrencyPairs(), that uses add() to add other underlying currency pairs for my lot sizing function, then I do not have this behavior at all, and everything works fine. The erroneous behavior starts the moment I add other underlying currency pairs into my strategy, than I get this strange behavior when I open new charts to trade a different currency pair. It is important to note that I am always adding all currency pairs from my Forex-list for potential cross currency comparison each time I open a new window using a currency pair as a instrument I want to trade.

            2. The Message Box generally appears when you "deactivate" a strategy?
            Yes, right now it does. I added a Message Box into the Deactivation function for debugging purposes. I always use Message Boxes for debugging purposes.

            3. Closing a position that a strategy is managing from the the Positions tab should disable the strategy that is managing the position.
            Yes, it does, but also deactivates other strategies that run on other preliminary currency pairs as I explained above. I want to know what is causing this behavior.

            I look forward to your response.
            Thank you, looking forward to your answer as this is such a critical situation to me.
            Attached Files
            Last edited by warcious; 11-03-2016, 06:23 PM.

            Comment


              #21
              NinjaTrader_PatrickH:

              After putting MessageBoxes everywhere where the CancelAllOrders() native functions is being called I found out that it is inside OnPositionUpdate() in my code that the CancelAllOrders() function is being called that cancel my other strategies:

              protected override void OnPositionUpdate(IPosition position)
              {
              try
              {
              if (_strategyState == StrategyState.Enter && position.MarketPosition != MarketPosition.Flat)
              {
              _realQuantity = (int)_numericUpDownQuantity.Value;
              _strategyState = StrategyState.Exit;
              }

              if (_strategyState == StrategyState.Exit && position.MarketPosition == MarketPosition.Flat)
              {
              SetNotActive();
              }
              base.OnPositionUpdate(position);
              }
              catch (Exception e)
              {
              CSTUtilities.ExceptionMessage(e);
              }
              }

              private void SetNotActive()
              {
              CancelAllOrders(false, true);
              _strategyState = StrategyState.NotActive;
              MessageBox.Show("Deactivating inside SetNotActive() at time: " + Convert.ToString(DateTime.Now));

              SetVisualToNotActive();
              if (_deActivate)
              {
              _currentOrder = null;
              _deActivate = false;
              }
              }

              Comment


                #22
                Thank you for the update, warcious.

                CancelAllOrders() is not supported in NinjaTrader 7. The function is there but it is not supported for use in NinjaScript. The only overloads it has are to cancel all entries or all exits and it would appear it also disables strategies. I would recommend straying away from this function and potentially tracking your orders in your code and then cancelling them with CancelOrder().

                Comment


                  #23
                  Originally posted by NinjaTrader_PatrickH View Post
                  Thank you for the update, warcious.

                  CancelAllOrders() is not supported in NinjaTrader 7. The function is there but it is not supported for use in NinjaScript. The only overloads it has are to cancel all entries or all exits and it would appear it also disables strategies. I would recommend straying away from this function and potentially tracking your orders in your code and then cancelling them with CancelOrder().
                  Thank you for your earlier reply.
                  After doing further debugging I have replaced CancelAllOrders() with CancelOrder() and it is NOT working, and I get the very same erroneous behavior using CancelOrder(), this is how my new SetNotActive() function looks like where this problem occurs predominantly.

                  private void SetNotActive()
                  {
                  //CancelAllOrders(false, true); // Cancel All Exit my orders, Entry = false, Exit = true
                  //CancelOrder(_currentExitOrder50);
                  //CancelOrder(_currentExitOrder75);
                  //CancelOrder(_currentExitOrder100);
                  //CancelOrder(_currentExitOrderOther);
                  //CancelOrder(_currentExitOrderSTOP);

                  if (_currentExitOrder50 != null) CancelOrder(_currentExitOrder50);
                  if (_currentExitOrder75 != null) CancelOrder(_currentExitOrder75);
                  if (_currentExitOrder100 != null) CancelOrder(_currentExitOrder100);
                  if (_currentExitOrderOther != null) CancelOrder(_currentExitOrderOther);
                  if (_currentExitOrderSTOP != null) CancelOrder(_currentExitOrderSTOP);

                  _strategyState = StrategyState.NotActive;
                  MessageBox.Show("Deactivating inside SetNotActive() at time: " + Convert.ToString(DateTime.Now));

                  SetVisualToNotActive();
                  if (_deActivate)
                  {
                  _currentOrder = null;
                  _deActivate = false;
                  }
                  }

                  BUT, can I really use CancelOrder() IF I am ONLY using market order type throughout my strategy and NOT limit order type for all my orders?

                  I am only using EnterLong(), EnterShort() together with ExitLong() and ExitShort() functions in my strategy due to the previous problem with incompatibility problems between using eSignal as preliminary datafeed and then placing LimitOrders through Ninjatrader7 and executing them through FXCM. This did NOT work at all unfortunately!
                  Last edited by warcious; 11-06-2016, 08:52 PM.

                  Comment


                    #24
                    Hello warcious,

                    Thank you for your response.

                    You would need to ensure the Market Orders IOrder objects is being set to null when filled if you are trying to ensure this is not CancelOrder() causing this item.

                    You may wish to look to the StrategyState code you have. At this point I would recommend debugging your strategy further.

                    You can find information on debugging at the following link: http://ninjatrader.com/support/forum...ead.php?t=3418

                    Comment


                      #25
                      Originally posted by NinjaTrader_PatrickH View Post
                      Hello warcious,

                      You would need to ensure the Market Orders IOrder objects is being set to null when filled if you are trying to ensure this is not CancelOrder() causing this item.

                      You may wish to look to the StrategyState code you have. At this point I would recommend debugging your strategy further.
                      Thank you for your reply!
                      I have tried to debug by activating the TraceOrder function as well as making sure that each IOrder object is set to null after ExitLong() or ExitShort() function is being run (filled).
                      Unfortunately, the Output Window does not give any valuable output when my problem occurs.

                      My variables:
                      private IOrder _currentOrder;
                      private IOrder _currentExitOrder50;
                      private IOrder _currentExitOrder75;
                      private IOrder _currentExitOrder100;
                      private IOrder _currentExitOrderOther;
                      private IOrder _currentExitOrderSTOP;

                      Inside my OnStartUp() i make sure that each IOrder object is null:
                      protected override void OnStartUp()
                      {
                      try
                      {
                      // Add Toolbar Button
                      ButtonToThetop();

                      MessageBox.Show("
                      _currentExitOrder50: " + _currentExitOrder50
                      + "\n_currentExitOrder75: " + _currentExitOrder75
                      + "\n_currentExitOrder100: " + _currentExitOrder100
                      + "\n_currentExitOrderOther: " + _currentExitOrderOther
                      + "\n_currentExitOrderSTOP: " + _currentExitOrderSTOP
                      + "\n__currentOrder: " + _currentOrder);

                      _currentOrder = null;
                      _currentExitOrder50 = null;
                      _currentExitOrder75 = null;
                      _currentExitOrder100 = null;
                      _currentExitOrderOther = null;
                      _currentExitOrderSTOP = null;

                      Example of how my ExitShort() code looks like:
                      if (CurrentPrice >= RayPrice(_currentRayContainer.StopRay))
                      {
                      _currentExitOrderSTOP = ExitShort("Exit Short STOP","");
                      MessageBox.Show("_currentExitOrderSTOP has ExitShort and this is is content before I null it: " + Convert.ToString(_currentExitOrderSTOP));
                      _currentExitOrderSTOP = null;

                      Example of how my ExitLong() code looks like:
                      _currentExitOrderSTOP = ExitLong("Exit Long STOP","");
                      MessageBox.Show("_currentExitOrderSTOP has ExitLong and this is is content before I null it: " + _currentExitOrderSTOP);
                      _currentExitOrderSTOP = null;


                      Patrick: Do I need to use the function OnExecution() maybe?
                      Last edited by warcious; 12-07-2016, 12:03 AM.

                      Comment


                        #26
                        Hello warcious,

                        Thank you for your post.

                        What is the current behavior you are debugging at this time?
                        What is occurring? What should be occurring?

                        Comment


                          #27
                          Patrick,

                          I sent you a video.
                          My strategies are disabling each other, they are not isolated.
                          If I setup more then 1 chart running my strategy, and then one Entry line gets triggered, then it disables my my other strategies.

                          Comment


                            #28
                            Hello warcious,

                            Thank you for your response.

                            Can you provide the most updated version for testing on our end? You can send this to platformsupport[at]ninjatrader[dot]com with 'ATTN: Patrick H' in the subject line and a reference to this thread in the body of the email.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by jaybedreamin, Today, 05:56 PM
                            0 responses
                            3 views
                            0 likes
                            Last Post jaybedreamin  
                            Started by DJ888, 04-16-2024, 06:09 PM
                            6 responses
                            18 views
                            0 likes
                            Last Post DJ888
                            by DJ888
                             
                            Started by Jon17, Today, 04:33 PM
                            0 responses
                            1 view
                            0 likes
                            Last Post Jon17
                            by Jon17
                             
                            Started by Javierw.ok, Today, 04:12 PM
                            0 responses
                            6 views
                            0 likes
                            Last Post Javierw.ok  
                            Started by timmbbo, Today, 08:59 AM
                            2 responses
                            10 views
                            0 likes
                            Last Post bltdavid  
                            Working...
                            X