• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculating indicator values for the Next bar (after current bar)

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

    Calculating indicator values for the Next bar (after current bar)

    The subject may seem strange, as one might think "how can you calculate anything for the next bar when the bar isn't even plotted yet?"

    In my code I have some assumptions for what the next open/close might look like based on historical patterns, so I mathematically determine some values for the next bar.

    I would like to take my assumed values, append them to the DataSeries as a new value, then feed that new DataSeries into an Indicator.

    Is there any way in NinjaTrader to extend a data series by appending a value, then use that DataSeries in an Indicator or Strategy?

    Sorry if what I am trying to do isn't clear. Thanks -Dave

    #2
    Hello Dave,

    I believe I understand what you are trying to do. Basically, you are wanting to get your estimated values into other Indicators/Strategies.

    Their would be two possible ways you can try to accomplish this.

    The first would be set your calculated values to a plot inside of an Indicator. Inside of NinjaTrader you can set your Indicator to plot off of another Indicator, by selecting the "Input series" inside of the Indicator Parameters. So this way you can set another indicator based off your calculated values inside of your Indicator.

    The other way which you can use in both an indicator and strategy would be to have your indicator that is calculating the values expose a DataSeries where you can store all of this information. Note that this will require adding code to call your indicator in the indicator/strategy that you want.

    Here is an example of exposing variables that you may view for reference.
    http://www.ninjatrader.com/support/f...ead.php?t=4991

    Let us know if this will work for you.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hi JC - thanks for the response.

      Originally posted by NinjaTrader_JC View Post
      Basically, you are wanting to get your estimated values into other Indicators/Strategies.
      Not quite - I am actually trying to do a what-if scenario before the next bar is calculated... here is my task using the SampleMACrossover strategy as an example:

      chart = 60 minute (could be anything)
      fast = 4
      slow = 7

      The strategy rule is: If crossabove(fast,slow,1) then go long (reverse logic for short).

      The time is 13:57:00 PM - We are 57 minutes into the current bar - a new bar will be drawn in 3 minutes.

      Currently, the fast SMA(4)[0] value is 54.26 and the slow SMA(7)[0] value is 54.30, so crossabove(54.26,54.30,1) = false... but this could change in 3 minutes once the open of the current bar is plotted (if my understanding of bar construction and moving average plots is correct)

      The time is now 14:00:01, and the SMA values have suddenly changed so that fast is now < slow (they now cross in the other direction) so the strategy initiates a Buy order.

      Rather than have the Buy order execute at the open of the next bar after the SMA calculations are done, I would like calculate each SMA for the next bar using a 'what if' value for the opening value of the next bar, 3 minutes in advance of the close of the current bar. (In my code that value could be anything, for example the Median of the last bar)

      If I were using Array Lists in C# I could just do a list.Add(value) then calculate a new average from that. Is there anything similar for indicators, or am I taking the wrong approach here?

      Thanks -Dave

      Comment


        #4
        Originally posted by dave416 View Post
        Hi JC - thanks for the response.



        Not quite - I am actually trying to do a what-if scenario before the next bar is calculated... here is my task using the SampleMACrossover strategy as an example:

        chart = 60 minute (could be anything)
        fast = 4
        slow = 7

        The strategy rule is: If crossabove(fast,slow,1) then go long (reverse logic for short).

        The time is 13:57:00 PM - We are 57 minutes into the current bar - a new bar will be drawn in 3 minutes.

        Currently, the fast SMA(4)[0] value is 54.26 and the slow SMA(7)[0] value is 54.30, so crossabove(54.26,54.30,1) = false... but this could change in 3 minutes once the open of the current bar is plotted (if my understanding of bar construction and moving average plots is correct)

        The time is now 14:00:01, and the SMA values have suddenly changed so that fast is now < slow (they now cross in the other direction) so the strategy initiates a Buy order.

        Rather than have the Buy order execute at the open of the next bar after the SMA calculations are done, I would like calculate each SMA for the next bar using a 'what if' value for the opening value of the next bar, 3 minutes in advance of the close of the current bar. (In my code that value could be anything, for example the Median of the last bar)

        If I were using Array Lists in C# I could just do a list.Add(value) then calculate a new average from that. Is there anything similar for indicators, or am I taking the wrong approach here?

        Thanks -Dave
        It sounds me like what you are saying would be simpler said this way: "what is the Close value of the CurrentBar that will result in a crossover on this bar?" Stated that way, all you need to do is solve the equation that equates the 2 moving averages, while using the RequiredClose as the next term in the moving averages. That actually means that you can calculate the RequiredClose at the start of the bar, not 3 minutes before the bar closes.

        Comment


          #5
          Originally posted by koganam View Post
          It sounds me like what you are saying would be simpler said this way: "what is the Close value of the CurrentBar that will result in a crossover on this bar?"
          If CalculateOnBarClose = True then yes that would be the case. The problem arises when CalculateOnBarClose = False, at which point if i am to predict the open of the next bar, I will also need to add 1 to the number of bars in the average calculation, or in C# terms I will need to append 1 value on to the entire DataSeries and be able to set it to a value of the strategy's choosing.

          That actually means that you can calculate the RequiredClose at the start of the bar, not 3 minutes before the bar closes.
          Unfortunately I don't think this would work for my strategy - The strategy's goal is to initiate an order just before the close of a bar for two reasons: 1) the most accurate prediction of the open of the next bar can occur, and 2) I am finding that a lot of volatility occurs on the open of each bar which is not ideal for filling orders - this could be avoided somewhat by submitting an order just before the close of the current bar.

          Stated that way, all you need to do is solve the equation that equates the 2 moving averages, while using the RequiredClose as the next term in the moving averages.
          Yes precisely - so then the question is:

          Can a new custom value be appended to the end of a DataSeries?


          Thanks -Dave

          Comment


            #6
            Originally posted by dave416 View Post
            If CalculateOnBarClose = True then yes that would be the case. The problem arises when CalculateOnBarClose = False, at which point if i am to predict the open of the next bar ...
            I do not quite see why. The calculation would be valid at anytime within the bar, so doing it once when the bar opens is more efficient that doing it on every tick within the bar. Yes, you can isolate the beginning of the bar: NinjaScript gives us FirstTickOfBar for that, and there are other methods also available.
            Unfortunately I don't think this would work for my strategy - The strategy's goal is to initiate an order just before the close of a bar for two reasons: 1) the most accurate prediction of the open of the next bar can occur, and 2) I am finding that a lot of volatility occurs on the open of each bar which is not ideal for filling orders - this could be avoided somewhat by submitting an order just before the close of the current bar.
            How is knowing that information even earlier in the bar an issue?
            Yes precisely - so then the question is:

            Can a new custom value be appended to the end of a DataSeries?


            Thanks -Dave
            Not quite. NinjaScript does not allow you to do things to Plots that are in the future. However, nothing prevents you from using a drawing to mark the value. DrawDot() and DrawLine() come to mind.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by richa61416, Today, 01:18 PM
            0 responses
            3 views
            0 likes
            Last Post richa61416  
            Started by Robotman, Today, 01:08 PM
            0 responses
            4 views
            0 likes
            Last Post Robotman  
            Started by StevenNelson, Today, 12:29 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Kate  
            Started by anupsoni, Today, 12:23 PM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Kate  
            Started by aligator, Yesterday, 12:15 PM
            8 responses
            62 views
            0 likes
            Last Post NinjaTrader_Heath  
            Working...
            X