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

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.
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        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.
            Kate W.NinjaTrader Customer Service

            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.
                Kate W.NinjaTrader Customer Service

                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

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by DanielTynera, Today, 01:14 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post DanielTynera  
                    Started by yertle, 04-18-2024, 08:38 AM
                    9 responses
                    40 views
                    0 likes
                    Last Post yertle
                    by yertle
                     
                    Started by techgetgame, Yesterday, 11:42 PM
                    0 responses
                    10 views
                    0 likes
                    Last Post techgetgame  
                    Started by sephichapdson, Yesterday, 11:36 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post sephichapdson  
                    Started by bortz, 11-06-2023, 08:04 AM
                    47 responses
                    1,615 views
                    0 likes
                    Last Post aligator  
                    Working...
                    X