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

PriorDayOHLC, Efficiency of Method

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

    PriorDayOHLC, Efficiency of Method

    I read the code for the built-in indicator PriorDayOHLC

    I wonder if there is a more efficient way to process these value just once, instead of during each OBU for realtime data?

    In my mind, it seems since this indicator is only dealing with historical values, it should not be called by OBU realtime. But maybe I don't completely understand the lifecycles of historical vs realtime.

    My understanding:
    When a chart with this indicator is at state.DataLoaded, the code will iterate through the historical bars, and find the open, high, low and close during each historical bar's OBU event, and update the plot values.

    Then it will switch state to realtime, and for each bar drawn by the realtime (new incoming data), it continues to update it's plot objects. At my current level of understanding this seems like a waste of CPU & Memory resources.


    Is there a code example that would only run once, that would draw a line, instead of a continuous plot, and when state = Realtime, this code would stop running?

    I copied the indicator and added a test of
    Code:
    state == state.realtime  { return;  }
    but the plot appears to continue to plot for new bars
    I need help understanding that concept.

    Is drawing a ray instead of a plot more efficient?

    thanks

    #2
    Hello,

    Thank you for the post.

    You could certainly limit any indicator to be called a single time, or a number that you define to limit its use. Each indicator is calculated on each bar when used from OnBarUpdate. You could instead do this once and store the values to variables.

    To do something only once per session, I would still suggest using OnBarUpdate and then use the IsFirstBarOfSession variable. This would allow the indicator to be reset each day, and not only when you enable the script.




    I don't have a specific example that shows calling the PriorDayOHLC only once per day, but you could the help guide sample syntax and surround the code with it like the following:

    Code:
    if (Bars.IsFirstBarOfSession)
    {
        // set variables to the values you need once per day
    }
    Using a Ray to display this data would still require rendering so I am not certain that part would be any more efficient than just allowing this to plot. You would prevent the indicator from being calculated more than once in the above sample so that would, in turn, save some resources.

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

    Comment


      #3
      aha, FBOS is a good idea to limit the process.

      is there a good resource that describes the rendering and differences behind draw versus plot?
      is a plot able to be used in a market analyzer alert concept, but a draw might not be?
      I need to learn more about this.

      as an alternative, if I used state.dataloaded to call a custom method, could that custom method access the Bars collection, and loop thru it once? Is it the same access to the Bars collection as OBU offers, but it is only called once? and in my example I only need historical data, so the one-time-only trigger would be ideal.

      I'm enjoying this learning

      Comment


        #4
        Hello,

        Thank you for the reply.

        In reference to my last post, I had just noted that if you are drawing a Ray, that would still require the chart to Render something. A Plot is also Rendered, Rendering is just the term used to display the data in a visible way.

        There is no guide to differences between Rendering and a Plot specifically, these are two totally different concepts. A Plot is a type that holds data in a series and is also Rendered in a chart, a series<Double> would be the counterpart to a Plot that is not rendered but still stores data in a series. Plots specifically are used to expose data from Indicators, for example, if you wanted to use it with the Market Analyzer. A series<double> would be used for storing data in a series and generally is not used to expose data.

        You can read on these two concepts here:





        Rendering is a part of most types in NinjaScript or that most types have the option to override OnRender. This simply gives the script access to the same rendering techniques the platform uses to show things on the chart. We have a lot of documentation on this subject as it is quite complicated. This uses SharpDX so there are many tutorials online as well.




        This allows you to use X and Y coordinates to draw instead of the helper methods for drawing things like Draw.Dot(..)which uses a BarsAgo and Price. If you implement OnRender in your own script, you can then draw more advanced graphics in a custom way.

        Regarding state.dataloaded, if you need to do something only once after data is loaded this state would be fine. Keep in mind new sessions don't call this, so the script would not be updated daily only 1 time after it was enabled.

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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, Today, 06:40 PM
        0 responses
        9 views
        0 likes
        Last Post algospoke  
        Started by maybeimnotrader, Today, 05:46 PM
        0 responses
        7 views
        0 likes
        Last Post maybeimnotrader  
        Started by quantismo, Today, 05:13 PM
        0 responses
        7 views
        0 likes
        Last Post quantismo  
        Started by AttiM, 02-14-2024, 05:20 PM
        8 responses
        168 views
        0 likes
        Last Post jeronymite  
        Started by cre8able, Today, 04:22 PM
        0 responses
        10 views
        0 likes
        Last Post cre8able  
        Working...
        X