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

GDI problem - Ehlers Corona Indicators

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

    GDI problem - Ehlers Corona Indicators

    I am trying to port Ehlers Corona Indicators to NT, have them very near complete but I cannot get the coronas to draw properly.

    The problem is that it always draws the most recent bars corona on all past bars. I have tried several different methods of drawing it with no success so I figured I would post the code here and see if anyone with more custom drawing experience can figure it out.
    Attached Files

    #2
    Hello,

    Please post the zip file via File>Utilities>Export, or post a code snippet for us to look at.
    DenNinjaTrader Customer Service

    Comment


      #3
      here is the relevant drawing code from plot override.

      Code:
                      int bars = ChartControl.BarsPainted, index;
                      bars = CalculateOnBarClose ? (ChartControl.BarsPainted - 2) : (ChartControl.BarsPainted - 1);
                      double x1, y1, y2;
                      double vscale = bounds.Height / ChartControl.MaxMinusMin(max, min);
                      Exception caughtException;
                      while (bars >= 0)
                      {
                          //index = ChartControl.LastBarPainted - ChartControl.BarsPainted + 1 + bars;
                          index = ((ChartControl.LastBarPainted - ChartControl.BarsPainted) - 1) + bars;
                          if (ChartControl.ShowBarsRequired || ((index - base.Displacement) >= base.BarsRequired))
                          {
                              try
                              { 
                                  x1 = // horizontal position of bar to plot
                                      (((ChartControl.CanvasRight - ChartControl.BarMarginRight) - (barPaintWidth / 2))
                                      - ((base.ChartControl.BarsPainted - 1) * base.ChartControl.BarSpace))
                                      + (bars * (base.ChartControl.BarSpace));
                                  for (int i = 11; i < 60; ++i)
                                  {
                                      double v = (i+1)/2;
                                      y1 = (bounds.Y + bounds.Height) - (int)((v + 1.5 - min) * vscale + 0.5);
                                      y2 = (bounds.Y + bounds.Height) - (int)((v - min) * vscale + 0.5);
                                      SolidBrush brush = new SolidBrush(_colors[(int) Math.Round(_filters[index-1][i].dB[0])]);
                                      graphics.FillRectangle(brush, new Rectangle((int)x1 - barPaintWidth / 2, (int)y2, barPaintWidth, (int)Math.Abs(y1 - y2)));
                                      
                                  }
                              }
                              catch (Exception exception) { caughtException = exception; }
                          }
                          bars--;
                      }
                      graphics.SmoothingMode = smoothingMode;
      this is what it looks like, as you can see the corona changes properly but it paints the same corona across the entire chart rather than leaving the past values. I have used very similar drawing code before to draw lines, etc and it worked fine but in this case I have tried several methods with no luck. Perhaps NT handles drawing the background differently?


      Comment


        #4
        Hello,

        What exactly are you trying to achieve? Do you want one column of color per bar? If so, you should use:
        DenNinjaTrader Customer Service

        Comment


          #5
          No there is 48 horizontal colored lines per bar, they are plotting correctly.

          The issue is that once the bar changes, all past bars on the chart show the 48 colors assigned to the CurrentBar, rather than the colors that go with that bar.

          I have tried adding 48 plot objects which all contain horizontal lines and coloring them in the plot method but couldn't get that to work either, and it is much more resource intensive than using graphics.FillRectangle() so it wouldn't be a good solution anyways.

          On this pdf you can see how it is supposed to look:

          Comment


            #6
            I am sorry, but graphic.FillRectangle() is beyond the level of support we provide I believe.

            I'm not sure how praticle it is but maybe try DrawRectangle()?:


            I will have someone else take a look at this and see if they can come up with anything more useful.
            DenNinjaTrader Customer Service

            Comment


              #7
              sefstrat, did you already take at look at this from the sharing section? http://www.ninjatrader-support2.com/...endline&desc=1
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Hi sefstrat,

                are you sure it is the rectangle drawing and not the filters class? Looking at your _filters[index-1][i].dB[0], when assigning colors, it does not seem to change for any lower values of index.

                Cheers,
                Tomas

                Comment


                  #9
                  Tomas, sorry the code is somewhat convoluted because I have been experimenting with different drawing techniques but I am pretty certain it is correct.

                  Bertrand, yes I have seen TLFit and consulted it while writing this drawing code. Unfortunately however, TLFit does not draw properly on my computer either (it has the exact same problem, all bars show the fit of currentbar).

                  That is one thing I find confusing since obviously TLFit worked before (based on the screenshot from when it was posted), has there been any changes to NT drawing code since then that would affect this?

                  Can you try TLfit on your machine and see if it works properly?

                  Comment


                    #10
                    Hi sefstrat,

                    it seems that i was right. The problem appeared during clonning. When changing line

                    _filters[CurrentBar] = (FilterBank[])_filters[CurrentBar - 1].Clone();

                    to

                    FilterBank[] b = new FilterBank[60];
                    for (int n = 11; n < 60; n++)
                    b[n] = (FilterBank)_filters[CurrentBar - 1][n].Clone();
                    _filters[CurrentBar] = b;

                    it starts to work as expected.

                    Tomas

                    Comment


                      #11
                      Thanks Tomas, sefstrat the TLFit still works for me on daily data as the author used in his posted screenshot.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Very cool looking indicator when you change the line color to yellow.
                        eDanny
                        NinjaTrader Ecosystem Vendor - Integrity Traders

                        Comment


                          #13

                          Thanks Tomas, you are the man.

                          I implemented ICloneable to make it easier to debug the drawing code, apparently that didn't work out so well.

                          The fact that TLFit was doing the same thing made me a little too certain the problem wasn't with my code, still not sure why TLFit doesn't work for me but no matter.

                          Later this afternoon I will finish the rest of the corona indicators and post them here. =)

                          (And yes I will use the correct line color in the final product eDanny )

                          Comment


                            #14
                            sefstrat, that would be absolutely brilliant.

                            Tomas

                            Comment


                              #15
                              Hello, I also need help on CoronaSRN indicator. I want to fire an alarm if the light cyan will appear. I have attached a sample image wherein the light cyan appears.
                              Attached Files
                              Last edited by luxurious_04; 02-21-2011, 09:06 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by LawrenHom, Today, 10:45 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post LawrenHom  
                              Started by love2code2trade, Yesterday, 01:45 PM
                              4 responses
                              28 views
                              0 likes
                              Last Post love2code2trade  
                              Started by funk10101, Today, 09:43 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post funk10101  
                              Started by pkefal, 04-11-2024, 07:39 AM
                              11 responses
                              37 views
                              0 likes
                              Last Post jeronymite  
                              Started by bill2023, Yesterday, 08:51 AM
                              8 responses
                              44 views
                              0 likes
                              Last Post bill2023  
                              Working...
                              X