Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

FirstTickOfBar && Open[0]?

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

    FirstTickOfBar && Open[0]?

    Hi Guys,

    Is there any way to have the strat check to see if it's the open of the bar and if, for example, the MACD crossed up at the open of the bar? I have to use CalculateOnBarClose = false for my trail so I can't seem to find the right code.

    Please correct me if I'm wrong but I don't think FirstTickOfBar works with anything set to [0] and I can't use indicators set to [1] as I'm checking to see if we've had a cross at open. Taking out FirstTickOfBar and using CrossAbove lets it enter whenever the condition becomes true, including intrabar and several times per bar. Unfortunately, I only want to enter if the conditions are true at open.

    Thanks,
    Dave

    #2
    Hi dsraider,

    Using FirstTickOfBar should work ok for this, something like...
    Code:
    if (FirstTickOfBar)
       if (CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
    Last edited by NinjaTrader_Tim; 06-28-2010, 08:44 AM.
    TimNinjaTrader Customer Service

    Comment


      #3
      It hasn't taken a trade yet but it did compile so I'll keep at it.

      Thanks, Tim.

      Comment


        #4
        Originally posted by dsraider View Post
        Hi Guys,

        Is there any way to have the strat check to see if it's the open of the bar and if, for example, the MACD crossed up at the open of the bar? I have to use CalculateOnBarClose = false for my trail so I can't seem to find the right code.

        Please correct me if I'm wrong but I don't think FirstTickOfBar works with anything set to [0] and I can't use indicators set to [1] as I'm checking to see if we've had a cross at open. Taking out FirstTickOfBar and using CrossAbove lets it enter whenever the condition becomes true, including intrabar and several times per bar. Unfortunately, I only want to enter if the conditions are true at open.

        Thanks,
        Dave

        Dave,

        Try defining a variable like this.

        private int BarID = 0;

        then compare it to CurrentBar value.

        protected override void OnBarUpdate()

        {


        if(BarID != CurrentBar)


        {


        Do Something ;


        }


        Set variable to new CurrentBar value.

        BarID = CurrentBar ;



        RJay
        RJay
        NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

        Comment


          #5
          I'll give that a try. Thank you, sir.

          Dave

          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