Announcement

Collapse
No announcement yet.

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.

    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 CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      56 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      33 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      195 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      359 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      280 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X