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

event logging tactic change

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

    event logging tactic change

    i'm needing to modify an existing, working, indicator that marks peaks in a CCI
    it will only watch the last 3 peaks as the x axis moves forward
    the way the code is set up is using BarsSinceSession as the positioning tool
    because most of the markets i watch have relevant events that span the close i need to change the way the indicator positions the event from BarsSinceSession to CurrentBar or Count whichever would work better ...
    but for some reason i'm stumped - not much programming skill -
    here's two samples...

    old code sample:

    ThirdTopCCI = ScndTopCCI;
    ThirdTopPrice = ScndTopPrice;
    ThirdTopBar = ScndTopBar;
    ThirdTopBarsAgo = (Bars.BarsSinceSession - ThirdTopBar);

    ScndTopCCI = FirstTopCCI;
    ScndTopPrice = FirstTopPrice;
    ScndTopBar = FirstTopBar;
    ScndTopBarsAgo = (Bars.BarsSinceSession - ScndTopBar);

    FirstTopCCI = Value[1];
    FirstTopPrice = High[1];
    FirstTopBar = Bars.BarsSinceSession-1;
    FirstTopBarsAgo = 1;

    here's my stab at it using CurrentBar - which isn't working
    am i just missing something about the properties of the two bar location methods ??

    ThirdTopCCI = ScndTopCCI;
    ThirdTopPrice = ScndTopPrice;
    ThirdTopBar = ScndTopBar;
    ThirdTopBarsAgo = (CurrentBar - ThirdTopBar);

    ScndTopCCI = LastTopCCI;
    ScndTopPrice = LastTopPrice;
    ScndTopBar = LastTopBar;
    ScndTopBarsAgo = (CurrentBar - ScndTopBar);

    LastTopCCI = CCI[1];
    LastTopPrice = High[1];
    LastTopBar = CurrentBar-1;
    LastTopBarsAgo = 1;

    thanks,
    wes

    #2
    Hello Wes,

    With the information that you gave us it is hard to say what is going on inside of the indicator. Is the Indicator not working as you expect or are you getting an error inside of the Log tab of the Control Center when you try to use the modified version?

    Also, would it be possible to post the indicator so that we can see the entire code to get a better feel for this?
    JCNinjaTrader Customer Service

    Comment


      #3
      thanks for getting back JC,
      i guess it's just a question of:
      should CurrentBar work in place of BarsSinceSession in the previous code sample?
      if it "should" then i've got some other problem that i need to work out first...
      thanks,
      wes

      Comment


        #4
        Hello Wes,

        Typically it does not since "CurrentBar" counts up from 0 and "BarsSinceSession" is going to count backwards like a Bars ago value so the two are going to be very different.
        JCNinjaTrader Customer Service

        Comment


          #5
          oh, wow did i ever miss something about BarsSinceSession
          i thought it was an integer that started at 1 and counting up to the right (x-axis)
          1 being the 1st bar of the current session
          so if i'm, say 225 volume bars into a session and #225 is still unfinished
          i thought the BarsSinceSession int value = 225
          but what you just said is that bar 225 of a session would be 1 and the session first bar would be 225 ?
          ~ "BarsSinceSession" is going to count backwards like a Bars ago value ~

          help me out on this one...
          what i read in the definition is 1...225
          and does "elapsed" mean closed? as in Close[1]
          or just the number of bars including the open bar ? (where Close[1] would be #224)

          10.4.3.7.1 BarsSinceSession
          Definition
          The number of bars that have elapsed since the session started.
          Property Value
          An int value representing the number of bars elapsed

          Comment


            #6
            back to the other issue:
            if i need to capture the data of a bar and some of its indicator values as well
            based on an event evaluating to true -
            - which leads to the event tracking code of which i gave you two samples -
            and i want to avoid the Session open issue as it's currently coded...
            would i use Count or CurrentBar to best keep temporary track of which bars
            in recent history evaluate to true in my condition set ?
            (in this case the condition is a peak in CCI)
            i guess what i'm saying is i don't have a firm grip on bar numbering for NT7 in C#
            other than the relative sense - as in Close[0] vs Close[1] vs Close[2]
            just need a little guidance and so i postulated a solution because Session start is a problem for me in this indicator coding
            thanks

            Comment


              #7
              Hello stafe,

              Let me try to clarify. CurrentBar is going to tell how many bars are on a chart so for example if there are 200 bars on a chart then CurrentBar is going to count from 0 to 199 from left to right (its only 199 because it starts at 0).

              So when you are calling Close[0] you are getting the value for CurrentBar = 199 since that is the last bar on the chart. Also, Close[1] (meaning 1 bar ago) will be the same thing as CurrentBar = 198.


              Let me know if helps clear things up.
              JCNinjaTrader Customer Service

              Comment


                #8
                that clarifies CurrentBar count
                thank you

                unfortunately, now i need an example with similar specificity of BarsSinceSession
                since the definition from the manual i posted below doesn't give the same kind
                of clarity and the issue has been muddied a bit by post #4
                - and since BarsSicneSession is the bar counter/positioning tool i'm trying to replace
                thanks

                Comment


                  #9
                  stafe, to see exactly what Bars.BarsSinceSession does I would recommend to just plot the call as indicator and add to your charts. You will see it reset at the session breaks and count the bars that have occurred then in the current session, so if you're in the middle of the session in OnBarUpdate for example you can check how many bars this point is into the session from the start.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Bertrand, please read post #4
                    somehow the definition of BarsSinceSession got really muddied for me
                    could you please clarify with an example similar to post #7
                    ? does BarsSinceSession start with 0zero as being the 1st bar to have "elapsed"
                    or ? does BarsSinceSession start with 1 like Count
                    and help me with the term "elapsed" does that mean closed?
                    so that CurrentBar#0 does not show up in the BarsSinceSession count

                    how does all this relate to my problem?
                    read post number 1
                    - i'm trying to change someone else's indicator so that it doesn't reset after Session Open
                    - that indicator is currently written using BarsSinceSession as the event loggging tool
                    i want to use either CurrentBar or Count
                    - but since JC's comment in post #4 we've been circling around and not getting anywhere
                    - this is really just a simple question that is asking for a "this does this" and "that does that" answer
                    - NinjaScript is new to me... obviously... and when i get a comment from on high like post number #4 which seems to contradict the definition in the Manual (post#5) it will throw me into a tailspin until i get it clarified... from on high...

                    thanks

                    Comment


                      #11
                      stafe, that's exactly why I was suggesting you to plot the BarsSinceSession info on your chart so you would have a simple visual correlation to work with, which the language idiosyncrasies of describing out of the equation.

                      The count will start at 0 with the session break, yes so your second bar has count 1. And elapsed means closed bars, that is correct.
                      Attached Files
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        thank you thank you thank you
                        your reply was quite clear
                        thank you

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by DawnTreader, 05-08-2024, 05:58 PM
                        7 responses
                        25 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by sgordet, Today, 05:24 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post sgordet
                        by sgordet
                         
                        Started by royhagerman, Today, 04:30 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post royhagerman  
                        Started by haas88, 03-21-2024, 02:22 AM
                        18 responses
                        208 views
                        0 likes
                        Last Post haas88
                        by haas88
                         
                        Started by Board game geek, Today, 02:20 AM
                        0 responses
                        7 views
                        0 likes
                        Last Post Board game geek  
                        Working...
                        X