Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculating P/L

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

    Calculating P/L

    just getting to grips with NT Strategy.

    Quick question: if I call multiple EnterLong's (same entry/instrument) and want to determine the P/L on exit what are my options? e.g.

    EnterLong(3)
    ExitLong(3)
    call Position.GetUnrealizedProfitLoss on fill exit event

    or

    if(Performance.AllTrades.Count >= 1)
    {
    Trade lastTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];
    ProfitLoss_LastTrade = lastTrade.ProfitTicks;
    }

    on fill exit event
    Last edited by delTik; 05-14-2016, 07:22 AM.

    #2
    Hello delTik,

    Thank you for writing in.

    You will want to obtain the last trade as you have outlined in your second block of code.

    This does not necessarily have to be done immediately upon the exit execution, however. As long as your strategy does not make additional trades, Performance.AllTrades.Count - 1 will still be referring to that last trade that was made by your strategy. If another trade occurred before you were able to obtain that PnL value, Performance.AllTrades.Count - 1 will be referring to that new trade.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by delTik View Post
      just getting to grips with NT Strategy.

      Quick question: if I call multiple EnterLong's (same entry/instrument) and want to determine the P/L on exit what are my options? e.g.

      EnterLong(3)
      ExitLong(3)
      call Position.GetUnrealizedProfitLoss on fill exit event

      or

      if(Performance.AllTrades.Count >= 1)
      {
      Trade lastTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];
      ProfitLoss_LastTrade = lastTrade.ProfitTicks;
      }

      on fill exit event
      If you are filled at 2 contracts and then 1 contract, that code will only return the final 1 contract traded. It would not be for all "3".

      So be careful.

      Comment


        #4
        ok thanks. so if I use

        Code:
        		protected override void OnExecutionUpdate(...)
        		{
        			if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
        	  		{
        				if(SystemPerformance.AllTrades.Count >= 1) 
        				{   
        					 Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
        					 cumulativeTick += lastTrade.ProfitTicks; 
        				}		
        			}
        		}
        on each execution event I'll have the correct cumlative PL?

        Comment


          #5
          Hello delTik,

          Thanks for your post.

          I copied your code into a test strategy and tested it against the sim101 account. After the first order completes, subsequent entry orders cause your accumulation to double the ticks. I think you would only want to add to your cumulativeTick when the execution is a profit target or a stop fill and not en entry fill.
          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, Today, 06:40 PM
          0 responses
          2 views
          0 likes
          Last Post algospoke  
          Started by maybeimnotrader, Today, 05:46 PM
          0 responses
          6 views
          0 likes
          Last Post maybeimnotrader  
          Started by quantismo, Today, 05:13 PM
          0 responses
          6 views
          0 likes
          Last Post quantismo  
          Started by AttiM, 02-14-2024, 05:20 PM
          8 responses
          167 views
          0 likes
          Last Post jeronymite  
          Started by cre8able, Today, 04:22 PM
          0 responses
          8 views
          0 likes
          Last Post cre8able  
          Working...
          X