Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get position of a different Strategy

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

    Get position of a different Strategy

    I have two day trading strategies:

    I want that the second one not open new positions when the first strategy has executed a stop loss order during the day.

    Is there any way of doing this? Perhaps thru Global Variables?

    A example would be more than welcome!

    Thank you in advance.

    #2
    Hello Plaket,

    Thank you for your note.

    The easiest and most reliable way to accomplish something like this would actually be combining your two strategies into one strategy that submits orders to 2 different instruments.

    For handling orders on multiple instruments, you can use either the Managed approach or Unmanaged approach, it would depend on what type of logic you want to create.

    There is a simple example that comes with the platform using the managed approach, it is called SampleMultiInstrument.

    Regarding using the opposing instruments orders to control logic, such as ceasing orders on one instrument when the first instrument has executed a stop order, you could look at the following example that demonstrates using Order objects and the OnOrderUpdate/OnExecution overrides to control logic: https://ninjatrader.com/support/foru...-orders?t=7499

    I look forward to being of further assistance.

    Comment


      #3
      Thank you Kate,

      I know that a possible solution would be to combine both strategies in only one strategy but here it is not possible. I need to have two individual strategies.

      What I need is that one strategy does not open new positions if the other strategy has executed a stop loss during the day.

      Could I do that using global variables?

      I would be something like this:

      If the strategy A has executed a Stop loss during the day a Global Variable is == 1 if not is == 0. That way the strategy B only would open positions if Global Variable is == 0.

      Would be possible to do something like that?

      Thanks,

      Comment


        #4
        Hello Plaket,

        You can actually do this in the UserDefinedMethods: http://ninjatrader.com/support/helpG...ed_methods.htm

        For example; under Tools > Edit NinjaScript > Strategy > User Defined Methods > Edit:
        Code:
        namespace NinjaTrader.Strategy
        {
            /// <summary>
            /// This file holds all user defined strategy methods.
            /// </summary>
            partial class Strategy
            {
                public bool Stopped = false; 
            }
        }
        Then, in your first strategy, you could set Stopped = true; after your strategy executes a stop loss, and then in the second strategy you could put this at the beginning of OnBarUpdate:

        Code:
        If (Stopped)
             return;
        You'd probably also want to set the Stopped bool to false in the Initialize() method so next time you restart Strategy 1 you reset that value.

        Please let us know if we may be of further assistance to you.

        Comment


          #5
          Great help Kate, thank you.

          Could this solution work calling the variable from the OnBarUpdate() method of each strategy and using the managed approach?

          Thanks

          Comment


            #6
            Hello Plaket,

            Thank you for your reply.

            I'd expect for the way you're planning to use it, you'd likely want to trigger it in OnExecutionUpdate so you know if the StopOrder was actually filled before you change the bool.

            Here's a link to our help guide on OnExecutionUpdate:


            Please let us know if we may be of further assistance to you.

            Comment


              #7
              Thanks Kate,

              One last thing please, is it possible to access the Public Stopped variable (post #4) from an Indicator instead of from a Strategy?

              Thanks,

              Comment


                #8
                Hello Plaket,

                Thank you for your reply.

                No, you would not be able to access it from an indicator as the namespaces are different.

                Please let us know if we may be of further assistance to you.

                Comment


                  #9
                  Originally posted by Plaket View Post
                  Thank you Kate,

                  I know that a possible solution would be to combine both strategies in only one strategy but here it is not possible. I need to have two individual strategies.

                  What I need is that one strategy does not open new positions if the other xender discord omeglestrategy has executed a stop loss during the day.

                  Could I do that using global variables?

                  I would be something like this:

                  If the strategy A has executed a Stop loss during the day a Global Variable is == 1 if not is == 0. That way the strategy B only would open positions if Global Variable is == 0.

                  Would be possible to do something like that?

                  Thanks,
                  You'd probably also want to set the Stopped bool to false in the Initialize() method so next time you restart Strategy 1 you reset that value.
                  Last edited by WAILITA; 08-08-2019, 01:57 PM.

                  Comment


                    #10
                    Originally posted by WAILITA View Post

                    You'd probably also want to set the Stopped bool to false in the Initialize() Aot watch online method so next time you restart Strategy 1 you reset that value.
                    Thank you for your reply.

                    Comment


                      #11
                      Originally posted by Plaket View Post
                      Thank you Kate,

                      I know that a possible solution would be to combine both strategies in only one strategy but here it is not possible. I need to have two individual strategies.

                      What I need is that one strategy does not open new positions if the other strategy has executed a stop loss during the day.

                      Could I do that using global variables? Emerald chat

                      I would be something like this: Uhmegle

                      If the strategy A has executed a Stop loss during the day a Global Variable is == 1 if not is == 0. That way the strategy B only would open positions if Global Variable is == 0.

                      Would be possible to do something like that?

                      Thanks,
                      Yes, absolutely — what you're describing is a valid use case for global variables when working with two separate strategies that need to "communicate" in a limited way.
                      You're on the right track.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      547 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      323 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      99 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      543 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      545 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X