Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceExit

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

    BarsSinceExit

    Hi all,

    I am constructing a strategy which will have as a component a statement that prevents entering for a certain number of bars after the initial entry.

    The current way i am trying to achieve this is highlighted below.

    PHP Code:
            protected override void Initialize()
            {
                double TradeSetOne = 0;
                double TradeSetTwo = 0;
    
            protected override void OnBarUpdate()
    
                // Condition set 1
                if (conditions
                    && TradeSetOne == 0)
                {
                    EnterLong:
                    TradeSetOne = 1;
                }
    
                if (conditions
                    && BarsSinceExit() > 20
                    && TradeSetOne == 1) 
                {
                    EnterLong:
                } 
    
    The problem arises due to error CS0103 that states that 'TradeSetOne' does not exist in the current context.

    I was just hoping if someone could point out why this is this case and what the solution could be.

    Many Thanks for any help
    4blue

    #2
    Please try defining those variables in the Variables section of the script and then just assign the initial value to them. Currently you define them locally just in the Initialize().

    Comment


      #3
      Thank you again Bertrand for the quick response.

      Problem sorted.

      4blue

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      633 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      567 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X