Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

PlotStyle.Triangle is not displayed

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

    PlotStyle.Triangle is not displayed

    Hi, I'm doing an indicator and it works, but it does not show the 2 PlotStyle.Triangle.


    Draw.TriangleDown(....); - If it shows it
    Sells[0] = Close[0]-(1*TickSize); - It shows nothing


    I think the problem is that I'm using it on OnRender.


    SharpDX.Direct2D1.Brush aBarBrushDX = AColor.ToDxBrush(RenderTarget);
    SharpDX.Direct2D1.Brush bBarBrushDX = BColor.ToDxBrush(RenderTarget);
    SharpDX.Direct2D1.Brush textBrush = TextColor.ToDxBrush(RenderTarget);
    SharpDX.DirectWrite.TextFormat textFormat = new SharpDX.DirectWrite.TextFormat(NinjaTrader.Core.Gl obals.DirectWriteFactory, "Arial", barHeight
    RenderTarget.DrawText(row, textFormat, rectText, textBrush);




    They know how I can make it look.





    The code is something like this.


    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////








    if (State == State.SetDefaults)
    {
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DrawOnPricePanel = true;
    PaintPriceMarkers = false;
    ArePlotsConfigurable = false;
    DisplayInDataBox = false;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    IsSuspendedWhileInactive = true;


    AddPlot(new Stroke(Brushes.OrangeRed, 6), PlotStyle.Dot, "down");
    AddPlot(new Stroke(Brushes.Blue, 6), PlotStyle.Dot, "uper");

    }



    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    SharpDX.Direct2D1.Brush aBarBrushDX = AColor.ToDxBrush(RenderTarget);
    SharpDX.Direct2D1.Brush bBarBrushDX = BColor.ToDxBrush(RenderTarget);
    SharpDX.Direct2D1.Brush textBrush = TextColor.ToDxBrush(RenderTarget);
    SharpDX.DirectWrite.TextFormat textFormat = new SharpDX.DirectWrite.TextFormat(NinjaTrader.Core.Gl obals.DirectWriteFactory, "Arial", barHeight);

    ..............................

    rectText = new SharpDX.RectangleF(x - barLength, yUpper, barLength, barHeight);
    RenderTarget.DrawText(row, textFormat, rectText, textBrush);
    }





    protected override void OnBarUpdate()
    {


    if (CurrentBar <5)
    return;

    if ((Close[1] > Open[1])&&(Close[0] < Open[0]))
    {
    Draw.TriangleDown(this,CurrentBar.ToString() + "KeyDown" + CurrentBar, true, 0, High[0] + (distancetext*TickSize), Brushes.Red);
    Sells[0] = Close[0]-(1*TickSize);
    }

    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Sells
    {
    get { return Values[1]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Buys
    {
    get { return Values[0]; }
    }

    #2
    Hello iradielt,

    Thanks for your post.

    Plot rendering is handled by the base class, so if we are overriding OnRender, we will also need to call base.OnRender(chartControl, chartScale); to be able to draw Plots.

    This may be excluded in what you copied, but another item I notice is that the code is not disposing of the DX brushes after render passes or on RenderTarget changes. It will be critical to take either of the following approaches to recreate device-dependent SharpDX resources as this can introduce memory leaks if unchecked.

    1. Create SharpDX resources at the beginning of a OnRender and dispose at the end of OnRender
    2. Dispose and recreate class level SharpDX resources in OnRenderTargetChanged()

    SharpDX Best Practices - https://ninjatrader.com/support/help...arpDXResources

    OnRenderTargetChanged - https://ninjatrader.com/support/help...getchanged.htm

    Please let us know if we can be of further assistance.

    Comment


      #3
      Add

      aBarBrushDX.Dispose();
      bBarBrushDX.Dispose();
      textFormat.Dispose();
      textBrush.Dispose();



      Hi, I get this error when I add the page OnRenderTargetChanged - https://ninjatrader.com/support/help...getchanged.htm




      |Indicator 'Test': Error on calling 'OnRenderTargetChanged' method: System.NullReferenceException: Object reference not set to an instance of an object.

      Comment


        #4
        Hello iradielt,

        The objects must not be null if you are going to dispose them.

        I have included some information on Object reference not set to an instance of an object errors below.

        Checking for Null References - https://ninjatrader.com/support/help...references.htm

        Here is a link to a Position Display Indicator that uses OnRenderTargetChange to dispose/recreate SharpDX brushes.

        This indicator provides a customizable text box which displays a position&#8217;s UnRealized PnL, Realized PnL of a selected account, and the overall cash value of the account.


        The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

        Please let us know if you have any questions.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        571 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 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
        548 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X