Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceExitExecution

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

    BarsSinceExitExecution

    I'm trying to make a simple strategy with 2 different time frames and the BarsSinceExitExecution function but as soon as I add the BarsSinceExitExecution function the backtest doesn't work. I have no error on the log file.
    What is wrong with my code ?

    if (BarsInProgress == 0)
    {
    if (
    ((Close[0] > Open[0])
    && (BarsSinceExitExecution(0, "", 0) > 10))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }
    }


    else if (BarsInProgress == 1)
    {
    if (
    ((Close[0] > Open[0])
    && (BarsSinceExitExecution(0, "", 0) > 20))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }
    }

    Last edited by bluesoul40; 04-09-2025, 05:28 AM.

    #2
    Hello bluesoul40,

    If those are the only entries then it won't work becase you are checking that there always was an exit. The first exit has to happen before that will count up so the method will return -1 forever because no entry is ever submitted. Your condition needs to check if the value is either -1 or the amount of bars you wanted.


    if ((BarsSinceExitExecution() > 10 || BarsSinceExitExecution() == -1))

    Comment


      #3
      Many thanks, it works. To simplify the whole thing would it be possible to change or force the value of the BarsInProgress index ?

      Comment


        #4
        Hello bluesoul40,

        You can use the syntax you had with the bars in progress,

        BarsSinceExitExecution(0, "", 0)

        You just need to make sure to also have a condition checking for -1 so it can kick off an initial entry.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        55 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        37 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        17 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        19 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        49 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X