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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      68 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      37 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      61 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      62 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      53 views
      0 likes
      Last Post CarlTrading  
      Working...
      X