Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

StrategyId needed

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

    StrategyId needed

    NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy("S10_P10", entryOrder);
    This does not return a strategyID, which is needed for any following action, like closing the strategy.
    How can I get it?
    Thanks.

    #2
    Hello kenz987,

    Thanks for your post.

    An AtmStrategyId will only have purpose for the NinjaScript Strategy Atm Strategy methods. Throughout AddOn's we can use the AtmStrategy itself. To get this, you could subscribe to Order Update events and then check if the iterating order's name is "Entry" If it is, check the order's GetOwnerStrategy method. You can cast this as an AtmStrategy and if the cast is successful, you will then have the owning strategy as an AtmStrategy. The AtmStrategy.Template property can be used check the AtmStrategy template associated with the order.

    Note that the AddOn Framework example describes how an AtmStrategy can be passed in various Atm Strategy Helper methods which reimplement the functionality of the NinjaScript Atm Strategy methods. See lines 1821 to 1904. The AddOn Framework example can be found below.



    We look forward to assisting.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks Jim, but to close the strategy I need the string strategyID, and I can not find it, How else can I close it if needed?

      Comment


        #4
        Hello kenz987,

        You can call atmStrategy.CloseStrategy() to close the ATM strategy once the target/stop reach an Accepted/Working OrderState. You could for example, check if "Stop1" belongs to an ATM strategy taking the approach in the example above, and if the order is in an Accepted state, calling CloseStrategy from the AtmStrategy will close the ATM strategy.

        Also note that the ATM strategy will have a Strategy ID as we see with NinjaScript strategies, that can be used to uniquely identify the strategy. In the example, this strategy can be referenced as stratbase.Id or atmStrategy.Id. This Id is not the same as the Atm Strategy Id that is used in the NinjaScript strategy ATM Strategy Methods.

        I look forward to being of further assistance.

        JimNinjaTrader Customer Service

        Comment


          #5
          Yes, this worked: atmStrategy.CloseStrategy("Entry"); Thank You!

          but to get the PnL it needs a string id, not the long id.
          this does not compile
          double dPL = atmStrategy.GetAtmStrategyUnrealizedProfitLoss(atm Strategy.Id)

          also this does not work:
          double dPL = atmStrategy.GetAtmStrategyUnrealizedProfitLoss("En try")
          it wants a string strategyID

          Comment


            #6
            Hello kenz987,

            The NinjaScript ATM Strategy methods would be used specifically when the ATM strategy is initiated from a NinjaScript strategy with AtmStrategyCreate(). As you are initiating the ATM strategy from AddOn code, these methods would not be relevant. The strategy Id is not the same as the ATM Strategy Id which is used in those methods, and the strategy Id cannot be used in its place.

            Please see the methods implemented in the AddOn Framework Basic example for how an ATM strategy's Unrealized PnL can be fetched without the ATM strategy Id. This example is linked in my first reply.

            From the AddOn Framework example:
            Code:
            private double GetAtmStrategyUnrealizedProfitLoss(NinjaTrader.NinjaScript.AtmStrategy atm)
            {
                if (atm == null || atm.State != State.Realtime || atm.Position == null)
                    return 0.0;
            
                return atm.Position.GetUnrealizedProfitLoss(Cbi.PerformanceUnit.Currency);
            }
            I look forward to assisting.
            JimNinjaTrader Customer Service

            Comment


              #7
              Thank you!!!. . . .
              Last edited by kenz987; 02-05-2020, 02:45 PM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by jclose, Today, 09:37 PM
              0 responses
              5 views
              0 likes
              Last Post jclose
              by jclose
               
              Started by WeyldFalcon, 08-07-2020, 06:13 AM
              10 responses
              1,413 views
              0 likes
              Last Post Traderontheroad  
              Started by firefoxforum12, Today, 08:53 PM
              0 responses
              11 views
              0 likes
              Last Post firefoxforum12  
              Started by stafe, Today, 08:34 PM
              0 responses
              11 views
              0 likes
              Last Post stafe
              by stafe
               
              Started by sastrades, 01-31-2024, 10:19 PM
              11 responses
              169 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X