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 Kensonprib, 04-28-2021, 10:11 AM
          5 responses
          191 views
          0 likes
          Last Post Hasadafa  
          Started by GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,230 views
          0 likes
          Last Post xiinteractive  
          Started by andrewtrades, Today, 04:57 PM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          7 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          441 views
          0 likes
          Last Post Delerium  
          Working...
          X