Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8 - Button - ForceRefresh - not refreshing chart

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

    NT8 - Button - ForceRefresh - not refreshing chart

    I have two indicators, both with buttons.

    One is '2xEmas' plotted on the first panel. It uses AddPlot and OnRender to plot the Emas and the band between. The button uses the code below to make IsVisible true/false:

    Code:
            protected void btn_Click(object sender, RoutedEventArgs rea)
            {
                IsVisible     = IsVisible == true ? false : true;
                ForceRefresh();
            }
    This works great. The plots 'disappear'/reappear from the chart when the button is clicked.
    This is similar to my indicator posted here:


    The other indicator is the MacdBB in the second panel. It does not use OnRender. The button uses the code below to make my bool paintBars true/false:

    Code:
            protected void btn_Click(object sender, RoutedEventArgs rea)
            {
                paintBars    = paintBars == true ? false : true;
                ForceRefresh();
                Print(paintBars);
            }
    The btn_Click works fine since 'paintBars' prints correctly.

    The paintBars code is below, simplified:

    Code:
    if (paintBars)    
    {
            BarBrush = Brushes.Green;
            BarBrush.Freeze();
     }
    This code itself works fine. When I click the button 'paintBars' switches true/false perfectly, but the BarBrush still continues to paint unless I refresh the chart manually with 'F5' to reinitialize the indicator.

    Any ideas how to fix this? I will upload to the downloads section when it's finished.

    I'd prefer not to upload the entire indicator since it contains several .cs files. However if you feel it necessary I can do so.

    Thank you,

    Simon.
    Attached Files
    Last edited by Sim22; 12-13-2015, 11:39 PM.

    #2
    Hello,

    Is your paintBars condition running continually, or only intermittently? If only intermittently, you might try placing ForceRefresh() directly in that condition, right after freezing BarBrush, so that you are forcing a chart refresh right after changing the bar color, within the same block.

    If it runs continually, does your debugging show that paintBars' value does indeed change before the existing call to ForceRefresh? Meaning that you clearly see paintBars update before the chart reloads, after the button is clicked.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Hello Dave. Thanks for your reply. I thought this might have been a simple process .....maybe it still is.

      The 'paintBars' condition runs continually.

      Here is an expansion of the code:

      Code:
      MACD         BMACD;
      
      ///---------------------- etc etc
      protected override void OnBarUpdate()
      {
                       if (IsRising(BMACD))
                      {
                          if (BMACD[0] <= UpperBollinger[0])
                          {
                              PlotBrushes[9][0]     = upBrushIn; // Plots[9] is BB dots
                          }
                          else
                          {
                              PlotBrushes[9][0]     = upBrushOut;
                          }
                      }
                      else
                      {
                          if (BMACD[0] >= LowerBollinger[0])
                          {
                              PlotBrushes[9][0]     = dnBrushIn;
                          }
                          else
                          {
                              PlotBrushes[9][0]     = dnBrushOut;
                          }
                      }
                      
                      if (paintBars)    
                      {
                          BarBrush                 = PlotBrushes[9][0];
                          BarBrush.Freeze();
                      }
      }
      Does 'ForceRefresh' only work with 'OnRender' or 'AddPlot' ? I can understand why it's not repainting but I can't put a finger to it.

      I experimented by placing in the button click code:

      Code:
                  BarBrush = BarBrush != null ? null: Brushes.Yellow; 
                  ForceRefresh();
      Which I think just worked for the CurrentBar.....but did not paint the past bars.

      I also wrote a print statement, timing the milliseconds between the click and the onRender refresh and it just ended up confusing me more.

      If you don't think this is a fairly simple idea to fix then I am happy to revisit this at a later date, since I already have my work cut out converting my NT7 indicators........

      Thanks for your time

      Comment


        #4

        Comment


          #5
          habibalex may have pinpointed the issue, as it looks like he's run into the same thing. Since ForceRefresh() essentially ques up another call to OnRender(), you may have better luck using ChartControl.InvalidateVisual() in this instance, instead.
          Dave I.NinjaTrader Product Management

          Comment


            #6
            I've tried that already, thank you. The original button code from @Edge included that and I have played with the sample code already, but at least I know more now about ChartControl.InvalidateVisual().

            The chart does seem to be refreshing via Print but the bars are just changing in realtime, not repainting the entire chart.

            Here's something for thought. I had experimented before using a on/off switch for OnRender:

            Code:
            protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
            {
                            if( Bars == null || ChartControl == null || Bars.Instrument == null || [COLOR=Red]!IsVisible[/COLOR] ) 
                            {
                                return;
                            }
            }
            Now when '!IsVisible', the visual is switched off. Works fine. Fine if you don't want the complete indicator to disappear, as per my paintBar macdbb. I had tried therefore in the past a bool switch like 'paintBar' in place of '!IsVisible' in which it does not work, as per my current issue. So it seems to me that the inbuilt NT bool 'IsVisible' is wired differently, to say it in an amateur way But 'IsVisible' is just not that flexible.

            I have also tried placing the macdbb and button in the same panel as the chart bars to see if that was the issue, but nothing different.

            As for the paintbars, here are some ideas floating in my cranial cavity....

            1. Should I experiment with BarBrushes instead, meaning an indexed BarBrush?

            2. Should I dump the bool 'paintBars' and directly change the BarBrush between null and a Brush value?

            3. I can do an 'OnRender' version of the paintbars creating basically a new 'chartstyle' on top of the bars, but that seems messy and maybe unecessary. But that might be easier to switch visuals on/off.

            4. I could create another parallel indicator called MacdBBPaintbars' in the first panel, just plotting macdbb values as paintbars and then use 'IsVisible' as a switch. That will work perhaps, but who wants the mess of 2 same indicators using up twice as much resources per chart?

            Just my 2 'fiat' cents.

            Any further ideas would be good.........

            Thanks again Dave.
            Last edited by Sim22; 12-15-2015, 04:40 PM.

            Comment


              #7
              Definitely some good ideas to try there. I am gravitating towards Idea # 2, as long as you are not actually instantiating Brushes each time you assign them, but are just re-assigning existing objects. From my understanding, a change in a BarBrushes index should properly force a refresh of all bars.
              Dave I.NinjaTrader Product Management

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Mongo, Yesterday, 11:05 AM
              6 responses
              27 views
              0 likes
              Last Post Mongo
              by Mongo
               
              Started by ct, 05-07-2023, 12:31 PM
              7 responses
              206 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by wzgy0920, Yesterday, 09:53 PM
              1 response
              13 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by Rapine Heihei, Yesterday, 07:51 PM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by kaywai, Today, 06:26 AM
              1 response
              6 views
              0 likes
              Last Post kaywai
              by kaywai
               
              Working...
              X