Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

PnL max loss per day & Exit delay.

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

    PnL max loss per day & Exit delay.

    Backtesting purposes. I'm using the script below from the Sample script for Halt Processing. I have a condition to exit by 3:55 each day and limit daily loss to 1500. Near to the last day of the backtest run period(which is a month long) a bunch of trades do not exit by the end of the day and do not exit until 2 days later on a Friday at 4pm. Any idea why it might be doing this?

    Code:
     protected override void OnBarUpdate()
            { 
    // At the start of a new session
    if (Bars.FirstBarOfSession && FirstTickOfBar)
    {
    priorTradesCumProfit = Performance.AllTrades.TradesPerformance.Currency.CumProfit;
    }
    //// After our strategy has a PnL less than -$1500 we will stop our strategy
    if (Performance.AllTrades.TradesPerformance.Currency.CumProfit - priorTradesCumProfit <= -1500)
    
    {
    /* A custom method designed to close all open positions and cancel all working orders will be called.
    This will ensure we do not have an unmanaged position left after we halt our strategy. */
    StopStrategy();
    
    // Halt further processing of our strategy
    return;
    }
     
    //Conditions for Entry here...
    
     
    if(ToTime(Time[0]) >= 155000)
    {
    ExitLong(200);
    }
    
    if (Positions.MarketPosition == MarketPosition.Flat && entrySubmit)
    {
    // Reset our bool to false to allow for submission of our entry order
    entrySubmit = false;
    }
    }
    
     
    private void StopStrategy()
    {
    // If our Long Limit order is still active we will need to cancel it.
    CancelOrder(myEntryOrder);
    
    // If we have a position we will need to close the position
    if (Position.MarketPosition == MarketPosition.Long)
    ExitLong(200); 
    
    }

    #2
    Hi Zachj,

    Thank you for posting.

    What time interval are you using for the backtest?

    Would you be willing to share the whole script so that I may test on my end? You may post it here or email me at Support[at]ninjatrader[dot]com if that is more comfortable.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Ok I just emailed it. Main timeframe is 5min with a 1min secondary. Multi-instrument, nearly 300 instruments.

      Comment

      Latest Posts

      Collapse

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