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

Using OnBarUpdate() within a Bars Type

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

    Using OnBarUpdate() within a Bars Type

    Hello Ninjatrader staff,

    When trying to use the "protected override void OnBarUpdate()" method in a Bars Type I am receiving the following error:

    'Ninjatrader.NinjaScript.BarsTypes.GoldBricks8.OnB arUpdate()': no suitable method found to override

    Does this mean that I inherently can't use the protected override void OnBarUpdate() method within the script of a Bars Type, or am I simply doing it wrong?

    Looking forward to your reply.

    Edit #1: I am able to provide the full script in a private e-mail should that be useful to solve my inquiry.

    Edit #2: My ultimate goal is to modify a double value within the Bars Type script when the "Close[0] > Close[1]" is true.
    Last edited by GLFX005; 05-28-2021, 03:12 AM.

    #2
    Hello GLFX005,

    Thanks for the post.

    OnBarUpdate is used in scripts that are applied to a bar series. A BarsType is actually what generates OnBarUpdate calls so you cannot use the OnBarUpdate override in a BarsType.

    BarsTypes are intended to give you each data point so you can tell when to form bars based on the data you are observing. That will get passed to the chart to display and then other scripts like indicators which have OnBarUpdate will see the bars that the BarsType generated.


    Edit #2: My ultimate goal is to modify a double value within the Bars Type script when the "Close[0] > Close[1]" is true.

    This would be a good task for a indicator or strategy but not necessarily a BarsType. If you were to do this with a BarsType you would need to make a whole bars type including how the bars are built. Once you have that you could add into the logic to check the previous bar values using the bars variable and its bars.GetClose() method. Getting the previous bar by its index and then getting its close value would be needed in that context. You could add a condition and then add a variable to be set. The OnDataPoint override is the main processing point for a BarsType, that is where each data point is processed so any logic would need to go in that override.


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

    Comment


      #3
      Hello Jesse,

      Thank you for your reply.

      How do I retrieve the Close value of the previously closed bar when using the "bars.GetClose()" method?
      Should I write "bars.GetClose(1)" to access the first bar in the past starting from the present?

      Comment


        #4
        Hello Jesse, here's an update on my progress.

        Using "bars.GetClose()" has not worked for me so far.
        What I am trying to figure out now is how to get the equivalent of "if (Close[1] > Open[1]" from OnBarUpdate() in OnDataPoint(), and then use that condition to modify a double value in my Bars Type script.

        Any ideas or suggestions on how to continue from here?

        Looking forward to your reply.

        Comment


          #5
          Hello GLFX005,

          Rather than using the get methods with an index it would likely be easier to just store the values you wanted to variables when you close the bar. You could then reference those variables when needed.

          You can study the existing bars types in the NinjaScript editor, they all work fairly different in terms of how they generate bars. Depending on what bars type you are starting from would determine where you would need to collect data to variable and where to determine bars had closed/starting a new bar.

          Please let me know if I may be of further assistance.
          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by geddyisodin, Today, 05:20 AM
          4 responses
          28 views
          0 likes
          Last Post geddyisodin  
          Started by geotrades1, Today, 10:02 AM
          2 responses
          5 views
          0 likes
          Last Post geotrades1  
          Started by ender_wiggum, Today, 09:50 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by rajendrasubedi2023, Today, 09:50 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by bmartz, Today, 09:30 AM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Erick  
          Working...
          X