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

Calculations current day

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

    Calculations current day

    Hello,

    I have a problem in my codings when I want to do calculations only for the current day. It shows me the numbers in my variables in the output window from the day before when there is no value from current day.

    How can I have simply eg "if(currentday and Low[1]<SMA[0]) then do..."

    Thank you
    Tony

    #2
    Hello tonynt,

    Thanks for opening the thread.

    NinjaScripts will process all historical data and then transition into processing realtime data. If you are trying to limit historical processing to the current day you could use a return condition as such:

    Code:
    if(Historical && Time[0].Date != DateTime.Today) return;
    If you are referencing a daily data series with COBC = false, a bars ago of 0 will represent the developing bar for the series.

    If you are referencing a daily data series with COBC = true, a bars ago of 0 will represent the bar that just completed. This would be yesterday's values for a daily series.

    To use the current day values for your calculations, I suggest to use a data series finer than a daily series for calculations, and then to use the CurrentDayOHL indicator for the developing daily Open High and Low values.

    CurrentDayOHL - https://ninjatrader.com/support/help...nt_day_ohl.htm

    If this does not resolve your inquiry, could you elaborate on what you are tying to accomplish?
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello Jim,

      thank you for your reply! I need this calculation within the onbarupdatecode where I have already "if(...CurrentBars[3]<1 return;"

      So I would need it "positive" coded instead of return. I tried to do now with your reply like
      if (Time[0].Date==DateTime.Today && ToTime(Time[0]) > 080000 && ToTime(Time[0]) < 093000
      && FirstTickOfBar && High[0]>SMA &&.....) {breakSMA=High[0]; barNumberbreak=CurrentBar;}

      But this does not work, it shows me the value of the Sept 18th when conditions from 19th is not true yet, but it should be "0" and show a value only when condition is true from today.

      I have tried to reset yesterdays value to zero in numerous locations in the code but for some reason yesterdays value is plotted on todays chart (calculated in onbarupdate even when the price was there the day before and not today)

      Thank you!
      Tony
      Last edited by tonynt; 09-20-2017, 11:41 AM. Reason: clearifying

      Comment


        #4
        Hello tonynt,

        I don't think I know enough about what exactly you are trying to accomplish, or how you have your strategy set up to provide further direction.

        Are you using CalculateOnBarClose = true or CalculateOnBarClose = false?

        When you print Time[0].Date with CalculateOnBarClose set to true, and then set to false, what results do you see in the output window?

        Keep in mind that when using COBC = false, you can reference the newly completed bar in the same way the COBC = true does as follows:

        Code:
        if(FirstTickOfBar)
        	Close[1]; // Bar that had just closed. Same as Close[0] with COBC = true.
        If you are using COBC = false, I recommend to keep all operations you would like to do on a bar close in a code block like this, separate from your logic that you would like iterated on each tick.

        Could you elaborate on what exactly you are trying to do with the strategy?

        I look forward to being of further assistance.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CortexZenUSA, Today, 12:53 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by usazencortex, Today, 12:43 AM
        0 responses
        5 views
        0 likes
        Last Post usazencortex  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        168 responses
        2,266 views
        0 likes
        Last Post sidlercom80  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X