Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Global target on multi instrument strategy

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

    Global target on multi instrument strategy

    Hello,

    I'm building a multi instrument strategy which is able to buy mutiple instrument at the same time.

    Do you know how i can set a global profit target ?

    I would like to close all position if global pnl reach 100$ (for example) and not only the primary instrument.

    Thank
    johnok
    NinjaTrader Ecosystem Vendor - Trade With Me

    #2
    Using Positions https://ninjatrader.com/support/help.../positions.htm you can get access to the unrealized P/L on each open position with GetUnrealizedProfitLoss() https://ninjatrader.com/support/help...profitloss.htm and add them up.

    When it reaches your goal, you could close them individually or do something like CloseStrategy();
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Thanks for the answer !

      Yes, actually, i can do this method. But i need to set my strategy at OnPriceChange and that can be huge no ?

      I'm searching the best method to do that. If, the best choice is GetUnrealizedProfitLoss in position management, i will do that .

      Initially, i was think about something like "SetProfitTarget" but globally.

      Thank yet
      johnok
      NinjaTrader Ecosystem Vendor - Trade With Me

      Comment


        #4
        There's no "SetProfitTarget but globally" available, so you would need to use the way I described, probably. Instead of OnPriceChange, you could use a Timer to check once a second or something as that would be much more efficient than OnPriceChange. Or, you could add a 1-second timing series and key off of that with OnBarClose. If it's a real-time only need, I would use a Timer if it were me.
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          Ok,

          Yes, a timer with a second time series is a good idea to do this finally ! Thank for this and i will add a check like this !

          Thanks you again for the nice idea and have a nice day !
          johnok
          NinjaTrader Ecosystem Vendor - Trade With Me

          Comment


            #6
            Hello,

            I tried to close my position when i reach a PnL. But my close are not applied. I tried to close both instrument like this.

            PHP Code:
            if ( Positions[0].MarketPosition == MarketPosition.Long ) ExitLong(0, Positions[0].Quantity , message, "Buy");
            else if ( Positions[0].MarketPosition == MarketPosition.Short ) ExitShort(0, Positions[0].Quantity , message, "Sell");
            
            if ( Positions[1].MarketPosition == MarketPosition.Long ) ExitLong(1, Positions[1].Quantity , message, "Sell");
            else if ( Positions[1].MarketPosition == MarketPosition.Short ) ExitShort(1, Positions[1].Quantity , message, "Buy");​ 
            
            I also tried flatten feature and closestrategy but nothing works...

            Have you any idea ?

            Thanks
            johnok
            NinjaTrader Ecosystem Vendor - Trade With Me

            Comment


              #7
              Does "Buy" and "Sell" match exactly (case and everything) the string of the entry order? If you're not sure, change that to null for the last argument and it will exit regardless of the entry order's name. Also, do you only have entries on the first and second data series? If you're entering on any other series, this would not exit.

              Make sure you're also not trying to exit a position started by a different strategy or strategy instance because they do not share trade lists. On platforms like TradeStation you can have an entry strategy and an exit strategy and they work together, but that is not the case here.

              The idea that CloseStrategy() doesn't work confuses me - that makes it sound like your condition you're checking for whether or not do this isn't right because when CloseStrategy() runs it's all over - all orders canceled, all positions exited (that the strategy opened), strategy disabled, all done.
              Bruce DeVault
              QuantKey Trading Vendor Services
              NinjaTrader Ecosystem Vendor - QuantKey

              Comment


                #8
                That's it !

                My signal name was not every times at the good value. So the close action was not working every times !

                Thank you man !

                Have a nice day !
                johnok
                NinjaTrader Ecosystem Vendor - Trade With Me

                Comment


                  #9
                  Glad you got it worked out.
                  Bruce DeVault
                  QuantKey Trading Vendor Services
                  NinjaTrader Ecosystem Vendor - QuantKey

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Pabulon, Today, 03:08 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post Pabulon
                  by Pabulon
                   
                  Started by sukhob, 05-18-2023, 08:26 PM
                  2 responses
                  128 views
                  0 likes
                  Last Post TraderJA  
                  Started by timwey, Yesterday, 10:55 AM
                  4 responses
                  24 views
                  0 likes
                  Last Post timwey
                  by timwey
                   
                  Started by DJ888, 06-28-2024, 10:18 PM
                  3 responses
                  39 views
                  0 likes
                  Last Post AdamDJ8
                  by AdamDJ8
                   
                  Started by ntwong, Yesterday, 08:22 PM
                  0 responses
                  16 views
                  0 likes
                  Last Post ntwong
                  by ntwong
                   
                  Working...
                  X