Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get current unrealised PnL of 2 or more instruments

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

    How to get current unrealised PnL of 2 or more instruments

    Hello,
    I want to know how one can get the current open unrealized PnL of 2 different instruments. Suppose a strategy opens 2 orders for 2 instruments in long and short positions, then is there a method to get current total unrelized pnL? Thanks.

    #2
    Hello woodies,

    The Positions collection will hold a Position object for all instruments added to the Strategy.
    https://ninjatrader.com/support/help.../positions.htm

    With this you can use the GetUnrealizedProfitLoss().
    https://ninjatrader.com/support/help...profitloss.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      Thanks for the link. Will try this method.

      Comment


        #4
        Code:
        else if (State == State.Configure)
        {
        //Add 2 data series of 2 instruments
        AddDataSeries(PrimaryInstrument, BarsPeriodType.Second,5); //index1
        AddDataSeries(HedgeInstrument, BarsPeriodType.Second,5); //index2
        
        }
        
        private void GoLongSpread()
        {
        EnterLong(1,Qty1,"");
        EnterShort(2,Qty2,"");
        }
        
        private void GoShortSpread()
        {
        EnterShort(1,Qty1,"");
        EnterLong(2,Qty2,"");
        }
        
        private void CloseSpread()
        {
        if(//BarsInProgress==1 &&
        Positions[1].MarketPosition==MarketPosition.Long)
        {
        ExitLong();
        }
        else if(//BarsInProgress==2 &&
        Positions[2].MarketPosition==MarketPosition.Short)
        {
        ExitShort();
        }
        if(//BarsInProgress==1 &&
        Positions[1].MarketPosition==MarketPosition.Short)
        {
        ExitShort();
        }
        else if(//BarsInProgress==2 &&
        Positions[2].MarketPosition==MarketPosition.Long)
        {
        ExitLong();
        }
        
        return;
        }
        Hello,
        I have been working with the previous guidance for opening and closing the spread.
        When opening the spread, the method works smoothly but when closing, it closes only the primary instrument and not the hedge or secondary instrument.
        I have tried the Positions[index] and also BarsInProgress == index conditions , but both ways it does not close the spread fully.

        I have also tried to code the individual order handling using Order objects and tracking the orders in OnOrderUpdate and OnExecution methods, but the EnterLong() or short methods are working equally well. Also for spread trading, it is necessary to scalein and scale out, so keeping track of orders with Order object becomes complicated.
        The Flatten() method works for closing the spread order but disables the strategy.
        Can you offer a solution for properly closing a spread order?
        Thanks.

        Comment


          #5
          Hello woodies,

          If you are placing orders to multiple instruments, use the overload that specifies the barsInProgressIndex.

          ExitLong(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal)
          https://ninjatrader.com/support/help...8/exitlong.htm

          Place orders to all of the specific bars in progress you would like orders placed to.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thank you, that worked. I tried that overload earlier with indexing but leaving other parameters empty.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Danila, Today, 04:38 AM
            2 responses
            7 views
            0 likes
            Last Post Danila
            by Danila
             
            Started by sinpeople, Today, 04:38 AM
            0 responses
            7 views
            0 likes
            Last Post sinpeople  
            Started by kiffgj, Today, 04:23 AM
            0 responses
            6 views
            0 likes
            Last Post kiffgj
            by kiffgj
             
            Started by Leeroy_Jenkins, Today, 03:45 AM
            0 responses
            10 views
            0 likes
            Last Post Leeroy_Jenkins  
            Started by Realsmooth3, Yesterday, 09:10 PM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_Marco  
            Working...
            X