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

Trying to use OnRender with Strategy and Range Bars

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

    Trying to use OnRender with Strategy and Range Bars

    I'm using the following sample code posted here elsewhere on a Strat. NOTE: This is for Range bars!

    It does put squares on top when loaded but as soon as another bar is painted it disappears what is wrong?

    I'm trying to combine this sample code from an indicator.


    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    for (int index = ChartBars.FromIndex; index <= ChartBars.ToIndex; index++)
    {
    
    // gets the pixel coordinate of the bar index passed to the method - X axis
    float xStart = chartControl.GetXByBarIndex(ChartBars, index);
    
    // gets the pixel coordinate of the price value passed to the method - Y axis
    float yStart = chartScale.GetYByValue(High.GetValueAt(index) + 2 * TickSize);
    
    float width = (float)chartControl.BarWidth * 2;
    
    
    // construct the rectangleF struct to describe the position and size the drawing
    //In order to centralise the rectangle over the bar, xStart-width/2
    SharpDX.RectangleF rect = new SharpDX.RectangleF(xStart-width/2, yStart, width, width);
    
    
    // define the brush used in the rectangle
    SharpDX.Direct2D1.SolidColorBrush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Blue);
    
    SharpDX.Direct2D1.SolidColorBrush outlineBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.Black);
    
    // if (Bars.GetClose(index)>Bars.GetOpen(index))
    if (closeGreaterThanOpen.GetValueAt(index) == true)
    {
    // The RenderTarget consists of two commands related to Rectangles.
    // The FillRectangle() method is used to "Paint" the area of a Rectangle
    // execute the render target fill rectangle with desired values
    RenderTarget.FillRectangle(rect, customDXBrush);
    
    // and DrawRectangle() is used to "Paint" the outline of a Rectangle
    RenderTarget.DrawRectangle(rect, outlineBrush, 1); //Added WH 6/5/2017
    }
    
    
    
    // always dispose of a brush when finished
    customDXBrush.Dispose();
    outlineBrush.Dispose();
    
    }
    
    // Default plotting in base class. Should be left Uncommented if indicators holds at least one plot you want displayed
    base.OnRender(chartControl, chartScale);
    
    }

    #2
    Hello r3n3v,

    It looks like you are only rendering one object.

    Do you mean to have an array of multiple objects rendered?

    Are you trying to render the single object and not have it update to a new bar?

    Below is a link to an example of a scrollable rendered object.
    https://ninjatrader.com/support/foru...906#post786906
    Last edited by NinjaTrader_ChelseaB; 08-15-2022, 03:15 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Trying to create multiple objects per candle. It does do them per candle on load of script. Once a new candle forms they disappear.

      Comment


        #4
        Hello r3n3v,

        This looks like it would loop through the visible chart bars..

        for (int index = ChartBars.FromIndex; index <= ChartBars.ToIndex; index++)

        What are the multiple objects? I only see one rectangle, used to draw a fill and outline.

        SharpDX.RectangleF rect = new SharpDX.RectangleF(xStart-width/2, yStart, width, width);
        RenderTarget.FillRectangle(rect, customDXBrush);
        RenderTarget.DrawRectangle(rect, outlineBrush, 1);

        What other objects?

        "Once a new candle forms they disappear."

        Can you provide an export demonstrating the issue?

        To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
        1. Click Tools -> Export -> NinjaScript...
        2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
        3. Click the 'Export' button
        4. Enter a unique name for the file in the value for 'File name:'
        5. Choose a save location -> click Save
        6. Click OK to clear the export location message
        By default your exported file will be in the following location:
        • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
        Below is a link to the help guide on Exporting NinjaScripts.
        http://ninjatrader.com/support/helpG...-us/export.htm


        "// always dispose of a brush when finished customDXBrush.Dispose(); outlineBrush.Dispose();"

        It doesn't look like you are finished with these brushes as they get re-used.. Perhaps you mean to create and dispose of these in OnRenderTargetChanged()?
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by f.saeidi, Yesterday, 02:09 PM
        3 responses
        18 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Jltarrau, Today, 05:57 AM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by kujista, Today, 06:23 AM
        0 responses
        2 views
        0 likes
        Last Post kujista
        by kujista
         
        Started by traderqz, Yesterday, 04:32 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by f.saeidi, Today, 05:56 AM
        1 response
        5 views
        0 likes
        Last Post Jltarrau  
        Working...
        X