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

Filling area or perhaps histogram

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

    Filling area or perhaps histogram

    What I am looking for is a way to "fill" (or perhaps just use a histogram) for an "overbought"/"oversold" area on an indicator like CCI/RSI... for example, when the CCI crosses under -100 I would like to fill that area until it comes back up above -100 or vice versa (i.e. crosses up over 100 and then down under 100).

    I attached an example from StockCharts - I am trying to make the CCI fill in in the overbought/oversold area. Is there a way to do this? I could simply just do a histogram like MACD and plot it once the value gets to a certain level but I'd like to put it only in the overbought/oversold area (which I guess I could plot another hist over a hist that is the same as the background color...)

    Any help is appreciated. I am 100% comfortable programming this stuff as I am a C# developer but I don't know if there is already a good way to do this.

    Lastly, on an unrelated note, how do I sort the forum threads so the latest is at the bottom?

    Thanks!!
    Attached Files

    #2
    I think DrawRegion() method might do the trick?



    For post sort order, check the "User CP" link at the top left of the page, I beleive there are some settings in there you can tweak.
    RayNinjaTrader Customer Service

    Comment


      #3
      Thanks!

      Can I say I have just started using this software this weekend, and I am already overwhelmed with how great the support is. Thank you for the fast response!!!!

      Comment


        #4
        I tried DrawRegion but it draws it on the chart area. Any way to draw it on the indicator area?

        Comment


          #5
          In the Initialize() method add:
          Code:
          DrawOnPricePanel = false;
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Great, that fixed that.

            However, I am having a problem now. This code is supposed to fill in the region between the overbought/oversold line and the current indicator when it goes above it. This is on the CCI, and here is my code:

            Code:
                            if(CCI[0] >= 100)
                            {
                                DrawRegion("Overbought1",CurrentBar,0,CCI,100,Color.FromKnownColor(KnownColor.Orange),Color.FromKnownColor(KnownColor.Orange),1);
                            }
                            else if(CCI[0] <= -100)
                            {
                                DrawRegion("Oversold1",CurrentBar,0,CCI,-100,Color.FromKnownColor(KnownColor.Orange),Color.FromKnownColor(KnownColor.Orange),1);
                            }
            What happens is attached.

            This is a custom indicator but all I did was take the standard CCI indicator, add some simple code to put in moving averages on it, and then add this drawregion stuff.

            Any assistance is appreciated.
            Attached Files

            Comment


              #7
              Well, let's look at what DrawRegion expects for parameters and what it does.

              DrawRegion(string tag, int startBarsAgo, int endBarsAgo, IDataSeries series, double y, Color outlineColor, Color backColor, int opacity)

              string tag = if not unique you draw object will be recycled when you call with the same string tag. To avoid this try using | "tagname" + CurrentBar | as the string tag.

              int StartBarsAgo = how many bars ago do you want it to start drawing. Passing it CurrentBars tells it to start drawing CurrentBars back - meaning the start of the chart. Try a value of 1 since Ninja isn't so good at filling the space a bar takes up and instead draws from midpoint of bar to midpoint of bar.

              int endBarsAgo = when do you want it to stop drawing. 0 means this bar.

              IDataSeries series = any IDataSeries object. This can be one of your own making or something like CCI(14) or SMA(9)

              double y = fixed y value.

              colors, color and opacity are pretty self explanatory.

              so, in short, you want something like

              Code:
                          if(CCI(14)[0] > 100)
                              {
                                  DrawRegion("Overbought1" + CurrentBar, 1, 0, CCI(14), 100,Color.FromKnownColor(KnownColor.Orange),Color.FromKnownColor(KnownColor.Orange),1);
                              }
              and from the look of things you have your own idataseries object called CCI which you can substitute into this example code in place of the CCI(14) if you want.

              Comment


                #8
                tradinginzen,

                You need to adjust your DrawRegion startBarsAgo and endBarsAgo. Right now, whenever your condition is met you are going back to the very first bar of the chart and drawing it all the way to the last bar. If you want selective regioning you need to code it so it draws only in the region you want.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks y'all... I was under the impression that CurrentBar was the "current bar" and not the start of the chart.

                  Newshues I want to keep the same object so I don't have a draw object for each bar on the chart... so it sounds like instead I need to have an overbought and oversold dataset that keeps track of when the indicator crosses overbought. If you all have a better idea, please let me know, but this seems to work now. If I use a 10 for barsago and a zero, it will do the last 10 bars perfectly.

                  Comment


                    #10
                    Bleh, not dataset, sorry... I meant it generically. I'm thinking of just keeping a member variable of a System.Collections.List<int>... however, maybe I do need an individual drawing object for each. I will play with it.

                    Comment


                      #11
                      Sorry for the barrage of posts but Newshues your suggestion worked perfectly... I will just stick with that.

                      Comment


                        #12
                        CurrentBar does indeed mean the current bar being drawn.

                        Problem is when something like DrawRegion is looking for how many bars ago you want to start drawing and you pass it CurrentBar.

                        Do the math. If CurrentBar is 1000 and you tell DrawRegion to start drawing CurrentBar ago, just where do you think it is going to start drawing?

                        And while you might not want to have a draw object for every instance of the CCI crossing 100/-100 the alternative you suggest requires rending back to the start of the chart at every instance of the CCI being above 100 or below -100.

                        and if it "seems" to be working with a value of 10 bars ago ending on the current bar it's just that, it only "seems" to be working because of the current conditions of the chart.

                        But you can do this however you want. Enjoy.

                        Comment


                          #13
                          Doh! You are exactly right.

                          I really appreciate the help you all... your suggestion is better Newshues b/c I can wrap this and put it in the user defined functions as I use it on several indicators.

                          Thanks again.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by algospoke, Yesterday, 06:40 PM
                          2 responses
                          19 views
                          0 likes
                          Last Post algospoke  
                          Started by ghoul, Today, 06:02 PM
                          3 responses
                          14 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by jeronymite, 04-12-2024, 04:26 PM
                          3 responses
                          45 views
                          0 likes
                          Last Post jeronymite  
                          Started by Barry Milan, Yesterday, 10:35 PM
                          7 responses
                          20 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by AttiM, 02-14-2024, 05:20 PM
                          10 responses
                          181 views
                          0 likes
                          Last Post jeronymite  
                          Working...
                          X