Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing a moving average with OnRender command

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

    Drawing a moving average with OnRender command

    Hey, just wondering how to draw a moving average type line with the OnRender commands. At the moment I'm using a for loop with a Rendertarget.DrawLine() command, that draws a line between each number in the array. Just thinking there must be a more elegant solution..?

    #2
    Yes, you could draw all visible parts as one path, and it will look more natural, especially if it has sharp corners or is not a solid line. For example, look at the source code to the chart style @LineOnCloseStyle.cs, which is included with NinjaTrader, to see how you can do this by adding segments together and then rendering them all at the end.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hey Bruce,
      Thanks a lot for the tip! I'll give that a try
      EDIT: Yess, that was exactly what I was looking for. Thanks again!
      Last edited by Magzor; 04-02-2023, 04:06 PM.

      Comment


        #4
        Hello Magzor,

        Thanks for your post.

        QuantKey_Bruce is correct. In the NinjaScript Editor window, you may view the LineOnCloseStyle.cs ChartStyle file that comes default with NinjaTrader to see how to add line segments together and render them in OnRender.

        RenderTarget.DrawGeometry: https://ninjatrader.com/support/help...awgeometry.htm
        PathGeometry: https://ninjatrader.com/support/help...thgeometry.htm
        GeometrySink: https://ninjatrader.com/support/help...ometrysink.htm
        OnRender: https://ninjatrader.com/support/help...8/onrender.htm

        Please let me know if I may assist further.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        546 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X