Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help needed for Cumulative profit calculation during backtest

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

    Help needed for Cumulative profit calculation during backtest

    Hello
    I am nearing the end of my strategy development and I would like to test the performance of the strategy by compounding all profits and placing subsequent orders accordingly.

    I have created a double variable and I am adding all realized profits to this variable. I am then converting this double variable to Int and placing the Order(EnterLong only takes Int Values).
    I am also diving my take profit targets into 4 parts. The issue is, that sometimes the strategy holds the remaining order size till close of session and I miss out on a lot of opportunities as a result. As an example,

    say I have a total qty of 19546. Diving it in 4 equal parts of TP gives me 4886. The rounded 1 contract is left and the strategy holds on to it forever. How do I make it place all the remaining contracts on last TP or on the last stop loss?

    tp1=ExitLongLimit(1,true,execution.Order.Filled/4,fib100,"MyTarget","My Entry");
    tp2=ExitLongLimit(1,true,execution.Order.Filled/4,fib50,"MyTarget1","My Entry");
    tp3=ExitLongLimit(1,true,execution.Order.Filled/4,fib618,"MyTarget2","My Entry");
    tp4=ExitLongLimit(1,true,execution.Order.Filled/4,fib764,"MyTarget3","My Entry");

    Thanks

    #2
    Hello MyFirstMillion,

    Thanks for writing in.

    If you do not specify a "fromEntrySignal" parameter, the entire position is exited rendering your strategy flat. This would mean you may have your greatest profit target take the remainder of contracts, by simply using the variation of ExitLongLimit() below:

    Code:
    ExitLongLimit(double limitPrice, string signalName, string fromEntrySignal)
    This variation does not take an order quantity and will exit the remaining number of open contracts. You can find syntax for more variations and usage here: https://ninjatrader.com/support/help...tlonglimit.htm

    The same approach can be used for a stop loss with ExitLongStop(): https://ninjatrader.com/support/help...itlongstop.htm

    Please let me know if I may be of further assistance.

    Comment


      #3
      I will give it a try tonight and let you know if I have problems. Thank you for the quick response. ninja support is the best

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      549 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      549 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X