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

50+ Plots set to transparent- does it consume resources?

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

    50+ Plots set to transparent- does it consume resources?

    Hi,
    I've got 50+ plots in my indicator, where most of them will be set to transparent, for a specific template

    i dont the option to switch them on or off.

    But my question is, when they are set to transparent like this, do they consume high amounts of recourses & what can be done to optimize this?

    Thanks.


    Code:
                    AddPlot(!Custom_Check ? Brushes.Chartreuse : Brushes.Transparent, "Plot 1");
                    AddPlot(!Custom_Check ? Brushes.Red : Brushes.Transparent, "Plot 2");
                    AddPlot(!Custom_Check ? Brushes.Orange : Brushes.Transparent,"Plot 3");
                    AddPlot(!Custom_Check ? Brushes.Cyan : Brushes.Transparent, "Plot 4");
                    AddPlot(!Custom_Check ? Brushes.Blue : Brushes.Transparent, "Plot 5");
                    AddPlot(!Custom_Check ? Brushes.White : Brushes.Transparent,"Plot 6");
                    AddPlot(!Custom_Check ? Brushes.Pink : Brushes.Transparent, "Plot 7");​

    #2
    Hello yertle,

    Even transparent the plot and Series<double> must be constructed and filled with data which require cpu and memory resources.

    No resources will be spent on rendering, however.

    "what can be done to optimize this?"

    I'm not sure there is much to do. You want to store values in the plot series, is this correct? If so, storing information requires memory..
    If you have nothing to store, don't call AddPlot() to add the plot and series.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the response.

      My understanding is that for every Values[i] series, there must be a plot object for it to show up in the databox and be plot the indicator stroke in the panel.


      I am trying to optimize this so i am ow working with sharpDX

      For plotting the SharpDX stroke objects, I am following 'SharpDX stroke style' here:
      https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?using_sharpdx_for_cu stom_chart_rendering.htm

      the help guide example keeps the plot
      Code:
      if (State == State.SetDefaults)
      {
      Name = "Custom StrokeStyle";
      
      AddPlot(Brushes.Blue, "Custom StrokeStyle");
      }
      And then overrides it
      Code:
      protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
      {
      // override the appearance of the default plot style
      Plots[0].StrokeStyle = dxStrokeStyle;
      base.OnRender(chartControl, chartScale);​
      I am having problems getting this to work with multiple dataseries
      > this is what i have for it::

      *right now its not overriding the default plot, with the shardx stroke

      Code:
      // This namespace holds Indicators in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Indicators.SharpDXSnippets
      {
          public class SharpDXStrokeMulti : Indicator
          {
              // SharpDX stroke style and brushes
              private SharpDX.Direct2D1.StrokeStyle dxStrokeStyle1;
              private SharpDX.Direct2D1.StrokeStyle dxStrokeStyle2;
              private SharpDX.Direct2D1.StrokeStyle dxStrokeStyle3;
      
      
              //private SharpDX.Direct2D1.SolidColorBrush dxBrush1;
              //private SharpDX.Direct2D1.SolidColorBrush dxBrush2;
              //private SharpDX.Direct2D1.SolidColorBrush dxBrush3;
      
              //// WPF brushes for the signals, configurable from the UI
              //private System.Windows.Media.Brush signal1_Color;
              //private System.Windows.Media.Brush signal2_Color;
              //private System.Windows.Media.Brush signal3_Color;
      
              // Series to store signal values
              [Browsable(false)]
              [XmlIgnore]
              public Series<double> Signal1
              {
                  get { return Values[0]; }
              }
      
              [Browsable(false)]
              [XmlIgnore]
              public Series<double> Signal2
              {
                  get { return Values[1]; }
              }
      
              [Browsable(false)]
              [XmlIgnore]
              public Series<double> Signal3
              {
                  get { return Values[2]; }
              }
              [Browsable(true)] // false will not show it in the UI / front end
              [XmlIgnore]
              [Display(Name = "Signal1 color ", GroupName = "color", Order = 6, Description = "...")]
              public System.Windows.Media.Brush Signal1_color
              { get; set; }
              [Browsable(false)]
              public string Plot_CummulativeSpreadSearialize
              {
                  get { return Serialize.BrushToString(Signal1_color); }
                  set { Signal1_color = Serialize.StringToBrush(value); }
              }
      
              // Initialization and state change handling
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      // Set default indicator properties
                      Name = "Custom StrokeStyle";
                      Description = @"Enter the description for your new custom Indicator here.";
                      Calculate = Calculate.OnEachTick;
                      IsOverlay = false; // Draw in a separate panel
                      DisplayInDataBox = true;
                      DrawOnPricePanel = false; // Draw in a separate panel
                      DrawHorizontalGridLines = true;
                      DrawVerticalGridLines = true;
                      PaintPriceMarkers = true;
                      ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                      IsSuspendedWhileInactive = true;
      
                      // Add plots with default colors
                      AddPlot(Signal1_color, "Signal1");
                      AddPlot(Brushes.Cyan, "Signal2");
                      AddPlot(Brushes.Magenta, "Signal3");
                  }
                  else if (State == State.Configure)
                  {
                      // create a custom stroke style when configured
                      SharpDX.Direct2D1.StrokeStyleProperties dxStrokeStyleProperties = new SharpDX.Direct2D1.StrokeStyleProperties
                      {
                          // set the dash style to "Custom" define the dash pattern
                          DashStyle = SharpDX.Direct2D1.DashStyle.Custom,
                  
                          // set further custom/optional StrokeStyle appearances
                          DashCap = CapStyle.Round,
                          EndCap   = CapStyle.Flat,
                          StartCap = CapStyle.Square,
                          LineJoin = LineJoin.Miter,
                  
                          // offset in the dash sequence
                          DashOffset = 10.0f,
                      };
                      
                          // define the an array of floating-point values
          float[] dashes = { 100.0f, 20.0f, 200.0f, 300.0f, 20.0f, 20.0f };
       
                      dxStrokeStyle1 = new SharpDX.Direct2D1.StrokeStyle(NinjaTrader.Core.Globals.D2DFactory, dxStrokeStyleProperties, dashes);
                      dxStrokeStyle2 = new SharpDX.Direct2D1.StrokeStyle(NinjaTrader.Core.Globals.D2DFactory, dxStrokeStyleProperties, dashes);
                      dxStrokeStyle3 = new SharpDX.Direct2D1.StrokeStyle(NinjaTrader.Core.Globals.D2DFactory, dxStrokeStyleProperties, dashes);
                  }
                  else if (State == State.DataLoaded)
                  {
                      // Initialize SharpDX brushes when data is loaded
                      //InitializeBrushes();
                  }
                  else if (State == State.Terminated)
                  {
      
                      // make sure to dispose of stroke style when finished
                      if (dxStrokeStyle1 != null)
                      {
                          if (!dxStrokeStyle1.IsDisposed)
                              dxStrokeStyle1.Dispose();
                      }                
                      if (dxStrokeStyle2 != null)
                      {
                          if (!dxStrokeStyle2.IsDisposed)
                              dxStrokeStyle2.Dispose();
                      }                
                      if (dxStrokeStyle3 != null)
                      {
                          if (!dxStrokeStyle3.IsDisposed)
                              dxStrokeStyle3.Dispose();
                      }
                  }
              }
      
      
      
              // Update signal values on each bar update
              protected override void OnBarUpdate()
              {
                  if (CurrentBar < 40)
                      return;
      
                  Signal1[0] = SMA(Close, 5)[0];
                  Signal2[0] = SMA(Close, 20)[0];
                  Signal3[0] = SMA(Close, 40)[0];
              }
      
              // Custom rendering using SharpDX
              protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
              {
                  if (BarsArray[0] == null || CurrentBar < 40)
                      return;
                  // [ ] chec i thiis is actually th stroke, or if its just the add plot showing.
      
                  // override the appearance of the default plot style
                  Plots[0].StrokeStyle = dxStrokeStyle1;
                  Plots[1].StrokeStyle = dxStrokeStyle2;
                  Plots[2].StrokeStyle = dxStrokeStyle3;
      
                  base.OnRender(chartControl, chartScale);
              }
      
          }
      }​
      Thanks
      Last edited by yertle; 06-17-2024, 11:20 AM.

      Comment


        #4
        Hello yertle,

        Yes, a plot series in the Values collection must have values to plot.

        Can clarify what you are trying to optimize?

        I would recommend that Plots[0].StrokeStyle be set from State.DataLoaded.

        If you want to custom render, its fine to do so. Calling base.OnRender(chartControl, chartScale);​ from OnRender() causes the plots added with AddPlot() to be rendered. Not calling this will prevent the plots from being rendered.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          i am trying to save recourses that are currently being used by the 50 Values[i] Series.

          So i am assuming that rendering the plots using SharpDX is more efficient than simply leaving the AddPlot method to draw the default indicator lines.


          So i'm trying to draw the plots with this

          Code:
          Plots[0].StrokeStyle = dxStrokeStyle;
          base.OnRender(chartControl, chartScale);

          rather than the default
          Code:
          AddPlot(Brushes.Blue,

          The problems I am getting is that it will draw either none or both.

          but i need some more time to explain the issue better.

          Comment


            #6
            Hello yertle,

            Which resources?

            Are you trying to save memory resources? (If you are not needing to store values in a series, then don't call AddPlot() to add a series)

            Are you trying to save GPU resources on rendering? (If so, setting plots to transparent will not render them and will not cost GPU resources)

            "So i'm trying to draw the plots with this
            Plots[0].StrokeStyle = dxStrokeStyle;
            base.OnRender(chartControl, chartScale);​"

            Setting the plot style does not change anything.
            This is would be the same as doing nothing in OnRender(). You would just be calling base.OnRender(chartControl, chartScale); so that the default rendering is done by NinjaTrader core. There wouldn't be any difference here.


            "rather than the default
            Code:AddPlot(Brushes.Blue,"

            It would still be the default. The core is rending the plot added with AddPlot() in the base.OnRender()..
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I'm trying to work through the indicator and save on both memory & gpu resources where possible.

              I assume there is a GPU resource saving, for changing the Default drawing objects , to custom rendering (SharpDX).

              i am only drawing stroke objects like this
              Click image for larger version  Name:	image.png Views:	0 Size:	9.4 KB ID:	1307519


              but is there benefit to drawing them with something like this, instead of default ?
              Code:
              private void RenderSignal(ChartControl chartControl, ChartScale chartScale, Series<double> signal, SharpDX.Direct2D1.SolidColorBrush brush, SharpDX.Direct2D1.StrokeStyle strokeStyle)
              {
              for (int i = ChartBars.FromIndex; i < ChartBars.ToIndex; i++)
              {
              if (i + 1 >= signal.Count)
              continue;
              
              float x1 = chartControl.GetXByBarIndex(ChartBars, i);
              float y1 = chartScale.GetYByValue(signal.GetValueAt(i));
              float x2 = chartControl.GetXByBarIndex(ChartBars, i + 1);
              float y2 = chartScale.GetYByValue(signal.GetValueAt(i + 1));
              
              RenderTarget.DrawLine(new Vector2(x1, y1), new Vector2(x2, y2), brush, 1, strokeStyle);
              
              }
              }
              
              
              
              //-------------------------------------------------------->
              
                      protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                      {
              
                          RenderSignal(chartControl, chartScale, Custom_signal, dxBrushes[0], dxStrokeStyles[0])
              
                          base.OnRender(chartControl, chartScale);
                      }​​
              ​​


              Doing it this way would help when i extend the functionality so i can have a list of sperate stroke objects (ie. 1 separate object for each each day/ session)
              Last edited by yertle; 06-17-2024, 12:23 PM.

              Comment


                #8
                Hello yertle,

                Drawing lines is fine to do.

                Not running base.OnRender() would prevent the plots from being rendered which would save a minimal amount of GPU.
                (Rending plots does not require much GPU resources)
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  My reason for trying to draw the lines with the OnRender() were these 2 comments

                  Quote #1
                  Click image for larger version  Name:	image.png Views:	0 Size:	12.9 KB ID:	1307531

                  Quote #2
                  Click image for larger version  Name:	image.png Views:	0 Size:	6.3 KB ID:	1307532

                  But from this conversation i understand that, the 'timestamp information and related info in memory' is taking about the default Series<T> that the stores the values in the first place (that i need anyway). a new timestamp series is not being created to simply render the default line on the chart.

                  So there is nothing to gain by Drawing the lines with OnRender() instead.​
                  Last edited by yertle; 06-17-2024, 12:37 PM.

                  Comment


                    #10
                    Hello yertle,

                    This is referring to drawing tool objects and not plots. Plots are rendered in the Base.OnRender() by the core NinjaTrader (in the same script thread). Drawing tools are separate scripts that have to instantiate instances, which creates overhead.

                    If you calling a lot of Draw tool methods, yes, custom rendering them would be more efficient.
                    This does not apply to plots added with AddPlot().

                    This is not related to the Series<double> objects. This is only related to the overhead caused by generating a large amount of drawing tool script instances.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thank you

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by joseph_kuruvilla12, Today, 01:01 AM
                      0 responses
                      6 views
                      0 likes
                      Last Post joseph_kuruvilla12  
                      Started by joseph_kuruvilla12, Today, 12:40 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post joseph_kuruvilla12  
                      Started by joseph_kuruvilla12, Today, 12:13 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post joseph_kuruvilla12  
                      Started by stafe, 07-19-2024, 01:32 PM
                      3 responses
                      40 views
                      0 likes
                      Last Post stafe
                      by stafe
                       
                      Started by joseph_kuruvilla12, Yesterday, 10:29 PM
                      0 responses
                      5 views
                      0 likes
                      Last Post joseph_kuruvilla12  
                      Working...
                      X