Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Prevent strategy from disabling before it even gets going

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

    Prevent strategy from disabling before it even gets going

    We used the following code (which we found on this forum) to stop our strategy once a specific profit or loss was reached:

    // After our strategy has a PnL greater than $1000 or less than -$400 we will stop our strategy
    Print(Performance.AllTrades.TradesPerformance.Curr ency.CumProfit);
    if (Performance.AllTrades.TradesPerformance.Currency. CumProfit > 1000
    || Performance.AllTrades.TradesPerformance.Currency.C umProfit < -400)
    {

    NinjaTrader.Gui.SuperDom.SuperDom.FlattenEverythin g();

    // Halt further processing of our strategy
    return;

    Trouble is, we're loading 10 days of data and the cumulative profit/loss is calculated from day 1 so the profit or loss is hit before we even get to today. How do we get the strategy to only start accumulating from the time it is initiated?

    #2
    Does this work?


    Code:
    protected override void OnBarUpdate()
            {
                if (Historical) return;
    
    ....
    
    }

    Originally posted by bassmanpete View Post
    We used the following code (which we found on this forum) to stop our strategy once a specific profit or loss was reached:

    // After our strategy has a PnL greater than $1000 or less than -$400 we will stop our strategy
    Print(Performance.AllTrades.TradesPerformance.Curr ency.CumProfit);
    if (Performance.AllTrades.TradesPerformance.Currency. CumProfit > 1000
    || Performance.AllTrades.TradesPerformance.Currency.C umProfit < -400)
    {

    NinjaTrader.Gui.SuperDom.SuperDom.FlattenEverythin g();

    // Halt further processing of our strategy
    return;

    Trouble is, we're loading 10 days of data and the cumulative profit/loss is calculated from day 1 so the profit or loss is hit before we even get to today. How do we get the strategy to only start accumulating from the time it is initiated?

    Comment


      #3
      So simple when you know how!

      Thank you VERY much, sledge.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      27 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      117 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      69 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      226 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      415 views
      0 likes
      Last Post CaptainJack  
      Working...
      X