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

Program Structure using OnRender() with Multiple Time Frames

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

    Program Structure using OnRender() with Multiple Time Frames

    I want to use OnRender() with SharpDX to Render Text and Lines to my chart. Previously I have used OnBarUpdate() and BarsinProgress to let my code decide when and where to place Draw Objects using Draw.Text() The object is drawn and then forgotten about. While I have gone thru the sample Custom render I don't quite see how I must structure my code in OnBarUpdate() to interface with OnRender() in multiple time frames. Do I just create either a list or array of DrawObjects in OnbarUpdate() which contain the text and position and then just let OnRender() access the list and place them on the screen ? If OnRender() is looping thru 3 time frames of array elements it would seem it was attempting to execute a lot of code for objects that were potentially off the screen and even though it did not execute a draw it still executed quite a bit of code. Before I start learning this the hard way I was wondering if I could get some input on the best way to structure this.

    Thanks
    Jerry

    #2
    Hello,

    Thank you for the post.

    The list or array you mentioned should just contain values and not whole drawing objects. If the plan is to avoid using drawing tools, the list should just be the values you will be drawing from OnRender such as text or prices. How you store the values could be a list of custom objects or an array, even a ISeries<t> types like Plots.

    OnRender is called frequently and not specifically in sync with OnBarUpdate so it only would need to access the data to display it by the use of variables. The event driven methods like OnBarUpdate would still contain all the calculation logic that set Plots or drive the script like usual.

    For more extensive examples, you could see the Pivots indicator or the zigzag, these both utilize OnRender and have checks in place for performance. These also demonstrate how to store data in Plots, and utilize that data to draw.

    The specific concept that could be used from these items is how they check what bars are currently visible and only draw that region of data. Starting at line 293 of the pivots indicator it loops through the visible bars to plot the pivot lines based on data derived from plots. This type of logic can help with performance by only using the few indexes of the list rather than looping over the entire list.


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

    Comment


      #3
      Jesse
      Great answer, You confirmed what I thought I understood tying it all together with some examples
      specific to the issues I know I have to deal with. It is so much easier to adapt existing code to solve these especially when your unfamiliar with OnRender() and the instructions set that supports it. This was exactly what I was hoping for when I posted this request.

      thanks I appreciate it.

      Jerry

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Barry Milan, Yesterday, 10:35 PM
      7 responses
      19 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by AttiM, 02-14-2024, 05:20 PM
      10 responses
      179 views
      0 likes
      Last Post jeronymite  
      Started by ghoul, Today, 06:02 PM
      0 responses
      9 views
      0 likes
      Last Post ghoul
      by ghoul
       
      Started by DanielSanMartin, Yesterday, 02:37 PM
      2 responses
      13 views
      0 likes
      Last Post DanielSanMartin  
      Started by DJ888, 04-16-2024, 06:09 PM
      4 responses
      13 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Working...
      X