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

backtest error when opening and closing position on the same candle

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

    backtest error when opening and closing position on the same candle


    Good afternoon and thanks in advance.

    My problem is the following. When performing a backtest of a strategy, when the entry and exit of the position occurs in different candles, everything works well. But when the entry and exit of the position occurs in the same candle, it executes them over and over, increasing my profit or loss.

    This in turn prevents obtaining correct information when optimizing.

    I have only one input activated per signal.

    Regards.

    #2
    Hello mcjosejavier, thanks for your question.

    It looks like the entry condition is becoming true multiple times within a bar. Its a problem with the strategy logic. We have this method that you can use to prevent this from happening:


    If that is 0, then don't enter the trade again.

    You could also check the CurrentBar value to control this.

    You can prove the strategy is entering multiple times using a Print statement above your entry order. e.g.

    if(EntryCondition)
    {
    Print("Entering Position");
    EnterLong();
    }

    Kind regards.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thank you very much. Finally I have made the result of the backtest equal to the result in playback.

      protected override void OnBarUpdate ()
      {
      if (BarsSinceEntryExecution () == 0)
      return;

      Regards.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by GLFX005, Today, 03:23 AM
      0 responses
      1 view
      0 likes
      Last Post GLFX005
      by GLFX005
       
      Started by XXtrader, Yesterday, 11:30 PM
      2 responses
      11 views
      0 likes
      Last Post XXtrader  
      Started by Waxavi, Today, 02:10 AM
      0 responses
      6 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Started by TradeForge, Today, 02:09 AM
      0 responses
      11 views
      0 likes
      Last Post TradeForge  
      Started by Waxavi, Today, 02:00 AM
      0 responses
      2 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Working...
      X