Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Bar Counting help needed!

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

    Bar Counting help needed!

    Hello,

    Please help me learn how to modify the attached code to show proper counting of the attached screenshot.

    I'm attempting to continue counting as the closing prices rise. If the price is lower, stop counting. I'll add the short side later with CrossBelow of the EMAs. Not sure why there's some gaps or why the 4 bar is numbered since it's lower than 3 (just one of several "problems").

    Thanks for any help you can give. I appreciate it.

    Kirk
    Attached Files
    Last edited by zeller4; 11-27-2008, 10:34 PM.

    #2
    Hi Kirk,

    you do add 2 additional timeframes to your strategy (1 & 3min) and I would handle these timeframes separate in OnBarUpdate().
    With something like:

    switch (BarsInProgress)
    case 0:
    case 1:
    case 2:

    Regards
    Ralph

    Comment


      #3
      Thanks Ralph,

      I was going to implement the other time periods after fixing my understanding of the barcounting...

      If I comment out the lines on the add periods, I'm still having the same problem. Not sure what I need to do to fix the bar counting where I would expect to see backcolors or barnumbers.

      Kirk

      Comment


        #4
        NewCloseUp = Close[HighestBar(Close, 5)-1];

        With the statement above you store the closing value of the bar preceding the highest bar close of a 5-bars-period. I guess that is not intended, right?

        Regards
        Ralph

        Comment


          #5
          Right,

          I'm trying to post new subsequent higher closes, not even sure if I should just be using if close is higher than previous MAX instead of using "highestbar".

          I'll try that next.

          thanks,
          kz

          Comment


            #6
            Originally posted by zeller4 View Post
            ... using if close is higher than previous MAX instead of using "highestbar".
            Important desicion. Using "highestbar" would represent a breakout strategy , using close[0] > close[1] works like a trade-the-consolidation-strategy, at least occasionaly.

            Regards
            Ralph

            Comment


              #7
              Ralph,

              Changed from Strategy to Indicator to test this new version...
              Not sure why the #7 or #8 bars print since they are not higher closes.

              Also, the green bar two past the #7 location didn't print even though it's higher close than #6.

              Bars starting with #9 appear to be correct again.

              Any ideas how to fix the couple "errors"?

              Thanks in advance.

              Kirk
              Attached Files

              Comment


                #8
                Can you explain, what are your intentions - when you start counting and when you stop - reset back to 0?

                I commented out a lot of your code and changed couple lines - now it starts counting when MAs crosses and does count until next crossover.
                Attached Files
                Last edited by roonius; 01-08-2009, 08:58 PM.

                Comment


                  #9
                  Hi Kirk,

                  the weak point seems to be how you are using the dataseries 'higherclose' and 'lowerclose'. At an EMA-crossing you set initial values for these data series'. But independent from that you load values according to a predefined bar-span on every OnBarUpdate(). That doesn't look consitent to me.
                  I think an easier approach to get the desired values is to store the bar number of an EMA-crossing and then calculate the MAX/MIN value for the bars since crossing or for the bars number predefined, whichever is smaller:

                  max/min-value = MAX/MIN(useHigherLower ? Close : Input, Math.Min(bars_since_crossover, span))[0]

                  Only 4 variables are needed: crossover_bar, direction, min_value, max_value.

                  I didn't look at roonius' proposal.

                  Regards
                  Ralph

                  Comment


                    #10
                    Roonius,
                    Thanks for the revisions. That is working how I'd like with resetting back to zero for the next crossover. I'm attempting to use this as a basis for some statistics. ie how many new higher closes for a given time period, etc.

                    Ralph, thanks, your comments were also understood by Roonius resulting in commenting out extraneous code as you mentioned.

                    Thanks, to both of you.

                    Kirk

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by scalp, Today, 01:26 PM
                    1 response
                    4 views
                    0 likes
                    Last Post NinjaTrader_ChristopherJ  
                    Started by ETFVoyageur, Yesterday, 06:05 PM
                    2 responses
                    27 views
                    0 likes
                    Last Post ETFVoyageur  
                    Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
                    9 responses
                    32 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by memonic, Today, 01:23 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post memonic
                    by memonic
                     
                    Started by bertochi, 04-16-2020, 12:15 PM
                    34 responses
                    1,157 views
                    2 likes
                    Last Post notenufftime  
                    Working...
                    X