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

accumulation

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

    accumulation

    Hello-

    I've never been able to get accumulation to work the way I want it to work.

    I don't want to use "if (Bars.IsFirstBarOfSession)"

    I want to use the first bar processed by OnBarUpdate after I start my data feed. Is there a way I can check for that?

    If it is not the first bar, I want my accumulation to begin.

    I assume this will be level 1 data that stays on my chart.

    Thank you.

    #2
    Hello imalil,

    If you are looking for the first historical bar this would be CurrentBar 0.

    If you are wanting the first real-time bar, you can detect when the State property is State.Realtime. Use a bool to have this trigger only once.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi, Chelsea-

      Thanks for the response. I'm having a logical problem with states historical and realtime. I know this is very simple stuff but I've never worked with them before. I'm hoping you'll give me an example.

      Let's say I have:
      'variable1 = variable2 + 85'

      The first pass through OBU, or ANY TIME OF DAY OF MY CHOOSING, I want this formula to trigger one time.

      Every other time through OBU I want:
      'variable1 = variable1 + variable2 + 85'

      I would like it to stay on the chart, historical, but I'll take anything if it'll let me see the value.

      I do not know how to write this. I know it's simple but I've never done it and my trial and error has run out.

      Thank you.

      Comment


        #4
        Hello imalil,

        Thank you for the reply.

        Lets go over the requirement for what you want to do.

        The first pass through OBU, or ANY TIME OF DAY OF MY CHOOSING, I want this formula to trigger one time.
        The first pass through OBU will be easy, thats what chelsea has noted or CurrentBar == 0. Bar 0 is always processed first and will always be the first time OBU is called.

        Any time of day is slightly different, what do you mean by this? Is this that you want to press a button and reset the value or do you mean at a pre-programmed time? Both would be fairly different processes so I would like to gather some clarification here before continuing.


        The overall answer is likely going to come down to an if else else condition such as:

        Code:
        if(CurrentBar == 0)
        {
        
        } 
        else if (Time of my choosing condition)
        {
        
        }
        else 
        {
        
        }
        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks for the reply, Jesse.

          When I start my data feed, the first bar that prints is where I want
          • 'variable1 = variable2 + 85'
          CurrentBar == 0 does not seem to work.

          My code never visits this block. I put a print statement in and it never prints. This is the problem I've always had.


          Every bar after I want:
          • 'variable1 = variable1 + variable2 + 85'
          This is where my code visits on every pass. And my values are very bad.

          When I put
          • ANY TIME OF DAY OF MY CHOOSING
          I didn't mean to use it with the CurrentBar == 0. I meant 'instead of'. As another option. For example:

          Instead of writing
          if(firstbarofsession)
          I would write:
          if(firstbaraftertimeofday 0830)
          {
          }
          else
          {
          }

          Something like that.

          I know this a simple concept, I've just never been able to get it, and I really need to get it.

          Thank you.

          Comment


            #6
            Hello imalil,

            You could check if state == state.realtime within OBU. After state is in real time, set a bool to true so that on the next OBU the first if statement becomes true.

            For example,
            Code:
             private bool firstRealtimebar=false;
             protected override void OnBarUpdate()
            {            [INDENT]if(firstRealtimebar==true)
            {
               Print("Change the way its added");
            }    
            if(State==State.Realtime)
            {
               Print("in realtime on bar"+CurrentBar.ToString());
            [B]  firstRealtimebar=true;[/B]
            }[/INDENT]
              }
            See OnStateChange section of our helpguide,


            Please let us know if you need further assistance.

            Alan P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by kevinenergy, Yesterday, 12:01 PM
            6 responses
            23 views
            0 likes
            Last Post kevinenergy  
            Started by DawnTreader, 05-08-2024, 05:58 PM
            15 responses
            49 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by ZeroKuhl, Yesterday, 04:31 PM
            7 responses
            40 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by xepher101, Today, 12:19 PM
            1 response
            23 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by jpeep, 08-16-2020, 08:31 AM
            16 responses
            498 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X