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

Initial Start Price Used on Startup

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

    Initial Start Price Used on Startup

    Hi All,

    I have what is probably a simple question for most of you more experienced programmers. I have a simple script that is calculating an open vs. close price difference for a range of bars using a 30 min period. I want to use the first days close price as the base(start) value for all following calculations within the onbarupdate. I entered in the close of the first day using the onstartup. So I'm getting the correct base value, but Im not sure how to use it only once for the first calculation as the onbarupdate repeatedly adds it instead of only the first time. Any suggestions or advice on how to get around this?

    Thanks for the help,

    Lee

    #2
    Hello Lee,

    Thank you for your post.

    You can Bars.FirstBarOfSession for this purpose exactly when looking for the close price of the first bar of the day.
    http://www.ninjatrader.com/support/h...rofsession.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Hi Cal,

      Thanks for the response. Will that give me the close of the first bar of all the bars in the entire range? Im looking for just the first day's close and not any that follow.

      I was able to get this value, but where I'm having trouble is how to implement it within the code. I only want it to be used in the first calculation and none thereafter. Is this possible using the onbarupdate?

      Thanks,

      Lee

      Comment


        #4
        Hello Lee,

        Do you want the close price of the new session or of the entire chart series?

        New session would be to use the Bars.FirstBarOfSession in OnBarUpdate. This will be called for the first bar of each new session.

        The entire chart series you would use if(CurrentBar == 0) { //'Get close price here }
        This will be the very first bar on the chart from the entire series
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Hi Cal,

          Yes, close of the bar for the entire series was what I was looking for. I added this and I almost have it. But now I realize that I would like the close of the first day of the entire series regardless of time period used? Is there an option for that?

          Thanks,

          Lee

          Comment


            #6
            Lee,

            Yes, you would need to use Bars.FirstBarOfSession in this case. Below is an example of how to only get the close of first day

            Code:
            if(Bars.FirstBarOfSession && firstDay == false)
            {
                 // Current bar will be current day, subtract one for last bar or last closing price before new session
                 closingPrice = Close[CurrentBar - 1];
            
                 // Set our bool flag to true so this statement does not become true again
                 firstDay = true;
            }
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Hi Cal,

              I used your suggestion and got it to work.

              Thanks again for all the help!

              Lee

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Mongo, Today, 11:05 AM
              2 responses
              6 views
              0 likes
              Last Post Mongo
              by Mongo
               
              Started by guillembm, Today, 11:25 AM
              0 responses
              3 views
              0 likes
              Last Post guillembm  
              Started by Tim-c, Today, 10:58 AM
              1 response
              2 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by traderqz, Yesterday, 09:06 AM
              4 responses
              27 views
              0 likes
              Last Post traderqz  
              Started by traderqz, Today, 12:06 AM
              4 responses
              8 views
              0 likes
              Last Post traderqz  
              Working...
              X