Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate() vs. OnRender() best practices?

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

    OnBarUpdate() vs. OnRender() best practices?

    I gather from the BarsAgo argument that Draw.* are to be used from OnBarUpdate(), not from OnRender(). I also gather that there is no SharpDX equivalent to the numerous shapes Draw.* supports -- specifically the up arrow and down arrow. Have I got that right?

    I am trying to draw up/down arrows a fixed pixel distance from their bars (i.e. not a price difference). The reason is so that they look good both for the older low-priced bars and for the newer high-priced bars. As far as I can see, that requires using OnRender() because OnBarUpdate() does not get called when the user scrolls the chart horizontally, so the price/pixel distance is wrong for the scrolled window.

    As far as I can see, that means I need to use RenderTarget.DrawGeometry(). Somewhere in the verbiage it said to keep the geometry object for the duration of the application. On the other hand, it looks to me as if I need a new geometry object for each arrow, and again whenever the chart is scrolled (because the coordinates are in the geometry object and not in the call that draws it). That's potentially a lot of objects to think of as semi-permanent, but perhaps I misunderstood something.

    Is there a way to convert absolute bars in OnRender() to a suitable BarsAgo value to hand to one of the Draw.* functions? Using Draw.ArrowUp() seems to me to be a lot simpler than trying to do arrows with SharpDX. (Is there a sample of anything close to using SharpDX to draw arrows near bars?)
    Last edited by ETFVoyageur; 06-01-2024, 04:06 AM.

    #2
    Problem solved. Sample found by Visual Studio searching the solution. It takes a lot more code in OnRender() but the result works very well. I'm still curious whether there is a good solution using OnBarUpdate() but I doubt that there is.

    Comment


      #3
      Hello ETFVoyageur,

      " Draw.* are to be used from OnBarUpdate(), not from OnRender()."

      This is correct. Drawing tool scripts should be called from OnBarUpdate() and should not be called from OnRender().

      "I also gather that there is no SharpDX equivalent to the numerous shapes Draw.* supports -- specifically the up arrow and down arrow. Have I got that right?"

      The drawing tool scripts are using path geometry to render these custom shapes.

      You are welcome to the view the code. The DrawingTools > ChartMarkers script shows this for ArrowUp on lines 499 to 526.

      "Is there a way to convert absolute bars in OnRender() to a suitable BarsAgo value to hand to one of the Draw.* functions? "

      These kind of calculations should be done in OnBarUpdate(). In OnRender() you will need the absolute bar index to use with ChartScale.GetYByValue() and ChartControl.GetXByBarIndex().

      Below is a link to an example.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Draw.Text() using a WingDings type font will let you draw an arrow symbol with a pixel offset in OBU(), such as at Low[0] with -20 pixel offset.
        Am I missing something? This is a very simple approach that I think you already know about.
        Last edited by eDanny; 06-03-2024, 01:47 PM.
        eDanny
        NinjaTrader Ecosystem Vendor - Integrity Traders

        Comment

        Latest Posts

        Collapse

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