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

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.
    JimNinjaTrader Customer Service

    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.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        1 view
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        238 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        383 views
        1 like
        Last Post Gavini
        by Gavini
         
        Started by oviejo, Today, 12:28 AM
        0 responses
        1 view
        0 likes
        Last Post oviejo
        by oviejo
         
        Started by pechtri, 06-22-2023, 02:31 AM
        10 responses
        125 views
        0 likes
        Last Post Leeroy_Jenkins  
        Working...
        X