Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 algospoke, Today, 06:36 PM
      0 responses
      1 view
      0 likes
      Last Post algospoke  
      Started by ETFVoyageur, Yesterday, 06:05 PM
      8 responses
      50 views
      0 likes
      Last Post ETFVoyageur  
      Started by futtrader, 04-21-2024, 01:50 AM
      7 responses
      68 views
      0 likes
      Last Post NinjaTrader_Eduardo  
      Started by pibrew, Today, 06:10 PM
      0 responses
      7 views
      0 likes
      Last Post pibrew
      by pibrew
       
      Started by pibrew, 04-28-2024, 06:37 AM
      2 responses
      19 views
      0 likes
      Last Post pibrew
      by pibrew
       
      Working...
      X