Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

StringSeries issue

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

    #16
    thanks for the assistance.
    I am still getting errors but it's been a long day and I think I am making simple mistakes. Can't see wood for trees.
    Will revisit this tomorrow when I am fresh.

    Comment


      #17
      ok crawling there.
      i have a solidcolor brush series but it never changes in OnBarUpdate?
      Code:
          myBrushSeries = new Series<System.Windows.Media.SolidColorBrush>(this);
      
              if(Close[0] >= Open[0])
              {               
                  myBrushSeries[0] = Brushes.ForestGreen;// #FF008B8B
              }    
                          
              else if(Close[0] < Open[0])
              { 
                  myBrushSeries[0] = Brushes.Crimson;    
              }
              else
                
      myBrushSeries[0] = Brushes.Blue;
      
      
      // in OnTargetChange I am using
      
                      if(greenDXBrush != null)
                      greenDXBrush.Dispose();
                  if(RenderTarget != null)
                      greenDXBrush = Brushes.ForestGreen.ToDxBrush(RenderTarget);
                  
                      if(redDXBrush != null)
                      redDXBrush.Dispose();
                  if(RenderTarget != null)
                      redDXBrush = Brushes.Crimson.ToDxBrush(RenderTarget);
      
      //In On Render
      n = (int)RHS_Font.TextFormatHeight;
      
      
          if(myBrushSeries[0] == Brushes.ForestGreen)
                      dxBrush = greenDXBrush;
                      if(myBrushSeries[0] == Brushes.Crimson)
                      dxBrush = redDXBrush;
      
                   TextLayout RHS1 = new TextLayout(Globals.DirectWriteFactory,volone,,
                  RHS_Font.ToDirectWriteTextFormat(), 130, 25);
      
                    XPosition =  chartControl.CanvasRight-(float)(RHS0.Metrics.Width*1.5);
                  SharpDX.Vector2 StartLive1 = new SharpDX.Vector2(XPosition, ChartPanel.Y+n);
      
                     
                      RenderTarget.DrawTextLayout(StartLive1,RHS1,dxBrush);​​​​
      if I use just a normal SolidBrushColor eg brushColor as a variable it all works fine and the colors change,

      Comment


        #18
        Hello Mindset,

        Your code doesn't show that myBrushSeries[0] is being used anywhere after it is assigned. Was there code that was not included?

        Try using the method I suggested in post # 15.


        In OnRender() if the brushColor variable is equal to green, then the dxBrush variable is assigned the greenDXBrush value, and dxBrush is supplied as the color to the render object.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          Hi Chelsea
          I am using myBrushSeries in OnRender
          as in
          if(myBrushSeries[0] == Brushes.ForestGreen)
          dxBrush = greenDXBrush;​

          Comment


            #20
            Hello Mindset,

            Have you checked if the condition is becoming true?

            It may be failing when trying to compare the brush against another brush for equality.

            Comment


              #21
              The color is changed in OnBarUpdate - if I use brushColor for example as a brush variable - my text changes color with each change of color from the OBU method. I am not understanding why a BrushSeries doesn't do the same?

              Comment


                #22
                Hello Mindset,

                Its not clear what the problem may be from the given information, have you used a Print to confirm your conditions in OnRender are becoming true? Comparing a brush against another brush variable may not work so that condition may not be true.

                Comment


                  #23
                  Ok here is the basic code.
                  I believe it's self explanatory.
                  One version works but the other version - the BrushSeries - does not change color although it does in OnBarUpdate

                  Code:
                  //Two ways to get the brushColor - brushcolour works, myBrushSeries doesn't change
                  private Series<System.Windows.Media.SolidColorBrush>               myBrushSeries;
                  private System.Windows.Media.SolidColorBrush brushColour; // used to determine the color of the brush conditionally
                  ​
                  
                  
                              if(Close[0] >= Open[0])
                          {
                              BarState = 1;
                              UpVolume[0] = Volume[0];
                              DownVolume.Reset();
                              myBrushSeries[0] = Brushes.ForestGreen;// #FF008B8B
                          
                              //brushColour = Brushes.ForestGreen;
                          }    
                                      
                          else if(Close[0] < Open[0])
                          {
                              BarState = -1;
                              DownVolume[0] = Volume[0];
                              UpVolume.Reset();
                              myBrushSeries[0] = Brushes.Crimson;
                            
                              //brushColour = Brushes.Crimson;// a NON series Brush works just fine
                      Print("OBU  Brush  "+(myBrushSeries[0].ToString());// here the color is changing correctly with either brushColor or myBrushSeries[0]
                          }​
                  
                              #region OnRender
                          public override void OnRenderTargetChanged()
                          {
                  
                          
                              {
                              //    if(myBrushSeries[0] != null)//memory error
                                  {
                                  if(greenDXBrush != null)
                                  greenDXBrush.Dispose();
                              if(RenderTarget != null)
                                  greenDXBrush = Brushes.ForestGreen.ToDxBrush(RenderTarget);
                                  //printing mybrushseries[0] here causes null ref error
                                  if(redDXBrush != null)
                                  redDXBrush.Dispose();
                              if(RenderTarget != null)
                                  redDXBrush = Brushes.Crimson.ToDxBrush(RenderTarget);
                              
                   
                              
                                      if(whiteDXBrush != null)
                                  whiteDXBrush.Dispose();
                              if(RenderTarget != null)
                                  whiteDXBrush = Brushes.White.ToDxBrush(RenderTarget);
                              
                  
                              }
                              }
                          }
                  
                          
                          
                          protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                          {
                          
                              base.OnRender(chartControl, chartScale);
                  
                                  n = (int)RHS_Font.TextFormatHeight;
                    
                          
                              SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode;
                              RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;
                  
                          // with this I simply get the last color added( white in this case) - if I use brushColor instead of the series the color changes correctly as in OnBarUpdate
                                  if(myBrushSeries[0] == Brushes.ForestGreen)
                                  
                                  dxBrush = greenDXBrush;
                                  
                                  if(myBrushSeries[0] == Brushes.Crimson)
                                  dxBrush = redDXBrush;
                                  
                                  if(myBrushSeries[0] == Brushes.White)
                                  dxBrush = whiteDXBrush;
                                  Print("On Render   "myBrushSeries[0].ToString()) + "   ");
                  
                                  
                                          TextLayout RHS0 = new TextLayout(Globals.DirectWriteFactory,volzero,//livetext.ToString(),
                              RHS_Font.ToDirectWriteTextFormat(), 130, 25);// 15 is font size, 60 is text width
                  
                          
                                                  XPosition =  chartControl.CanvasRight-(float)(RHS0.Metrics.Width*1.5);//-3
                  
                                      
                              SharpDX.Vector2 StartLive0 = new SharpDX.Vector2(XPosition, ChartPanel.Y + n * 1);
                        
                  
                                      RenderTarget.DrawTextLayout(StartLive0,RHS0, dxBrush);
                                
                              #endregion
                  ​

                  Comment


                    #24
                    Hello Mindset,

                    Series are not able to be used with bars ago in OnRender, OnRender does not use BarsAgo. You would have to specify the exact index in the series that you wanted by using GetValueAt() on the series. A series is generally not a good choice for the given use case with the given example. You only use 1 value ever and are not using more than 1 bars ago, you likely just need to use a Brush variable instead of a series.

                    Comment


                      #25
                      Thanks will have a look at that.
                      I want to use a series as in the end I will use approximately 8 values going back but I will look at GetValueAt and see how I get on.
                      thanks for the headsup.
                      My alternative of course is just to use 8 versions of the brush color but that seems a bit Flintstone :-)

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      607 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      353 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      105 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      560 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      561 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X