• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

PRC2 coloring the zone

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

    PRC2 coloring the zone

    PRC is the Polynomial Regression channel indicator which I believe is known. I have amended this to my liking and use with the coloring not only of the high and low bands but also the zone between the bands.

    I now would like to color this last zone based on whether one of the two (low or high) is sloping up or down. I.E. let's say the higher band is sloping up then the zone between the two is colored blue; if the higher band is sloping down then the zone is colored red. It would end up looking like in the attached photo shopped picture.

    Question: Is that actually possible to do within the PRC2 indicator? Or would it be more feasible to use the more simple Colored Region indicator and define the region within that code with the (rather complex) sqhi and sqlo values from the PRC2 indicator (thus ending up with a separate 2nd indicator)?

    sandman
    Attached Files

    #2
    Hello sandman,

    Thank you for your post.

    If you can call the plots of the PRC indicator then another indicator would likely be easier using the Falling() and Rising() methods: http://ninjatrader.com/support/helpG...properties.htm
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Patrick. Thanks. I need a bit of help to be able to proceed. I stripped down the PRC2 indicator leaving me with a high and low line and the zone in between the two lines.

      It does not change color when the LinReg changes direction and when it does change color it changes it all the way back.

      I have a similar multi time fame indicator which changes the background color depending on the LinRegs and that works totally fine. The difference that I can see lies in the OnBarUpDate section of the code. But I don't know how to change it.

      What I am trying to achieve is to color the region based on a rising or falling LinReg. See picture (the colored green/black line is the LinReg) which also contains part of the code. In case you would like to or need to look at the full code I have attached the indicator (I think that's easier to look at than a .cs file).

      sandman
      Attached Files

      Comment


        #4
        Hello sandman,
        I have included an example below of code that accomplishes this.
        This is an example of using DrawRegion() to color the area under your price data when your linear regression plot is rising and falling.

        Code:
           if(Rising(LinRegSlope( 20))) {
                    DrawRegion( "UpZone" + CurrentBar, 0 , 1 , LinRegSlope(20), High[0], Color.Empty, Color.Lime, 2);
                     }
                     if(Falling(LinRegSlope( 20)))
                     {
                     DrawRegion( "DownZone" + CurrentBar, 0 , 1 , LinRegSlope(20), High[0], Color.Empty, Color.Purple, 2);
                     }
        Shawn B.NinjaTrader Customer Service

        Comment


          #5
          Shawn. Using "LinRegSlope" instead of simple "LinReg" is what did it. Attached is the result. Beautiful.
          Thanks very much for your time to look this over. Much appreciated.

          sandman
          Attached Files

          Comment


            #6
            I now want to add access to a higher time frame into this PRC indicator but run into problems with the OnBarUpDate section.

            The PRC indicator requires "(CurrentBar < period)" (and the lowest period setting I am using is "68" but it can go up to "105"). See attached. Left side shows what's in the code right now and that works but without using an additional timeframe.

            From other multi time frame indicators I am used to using
            "(CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired)" to add another time frame. I tried different variations but none sofar worked. See attached image, right side.

            Can someone knowledgeable on this topic help with sorting this out for me?

            sandman
            Attached Files

            Comment


              #7
              Hello sandman,

              Thanks for your post.

              What is the base period that you are applying the indicator to?

              Is 15 minute the higher time frame?
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Paul. Yes, 15Min would be the higher time frame. Base/primary data base could be a 5Min Data Series.

                Just to be clear: I would want this indicator to plot the PRC lines using the primary data series e.g. 5Min but color the zone between the high and low bands based on the LinReg of a higher time frame e.g. 15Min. Sofar my attempts yielded a mixture of results none of it correct thus far. I hope you can help.

                sandman

                Comment


                  #9
                  Hello sandman,

                  Thanks for your reply.

                  The best help I can suggest is to review the helpguide section on Multi Time Frame as this details many concepts you have to follow to be successful. It is not an easy read but if you go through each section in order you will have a better understanding of what needs to be done. Here is the link: http://ninjatrader.com/support/helpG...nstruments.htm

                  Basically you need to remove the if(CurrentBar<... statement and use the statement you have below that. BarsRequired I think, could be wrong, defaults to 20, so that would say that 20 15 minute bars would need to pass before the code below would execute. That 300 minutes translates to 60 - 5 minute bars. If you need more then you can set the bars required in the initialize section: http://ninjatrader.com/support/helpG...rsrequired.htm

                  For the reset of your code you will want to only execute on the primary bars, so below the CurrentBars statement you could add: if(BarsInProgress==1) return; which says not to execute your code if the 15 minute bars has an onbarUpdate event.

                  If you want to reference the 15 minute data in your linreg then you will need to code it so that it points to the correct bars array object. http://ninjatrader.com/support/helpG...?barsarray.htm
                  LinReg(BarsArray[1], 20)[0] - points to the current LinReg value of the 15 minute bar.
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    (Got it. I will look further into that).
                    Meantime I have another question. Coloring the zone based on the primary data series works alright but is not perfect yet.

                    Let's say the LinReg is rising, then the zone color is painted light blue. But when the LinReg changes direction within the same bar it then paints the zone color light red OVER the light blue instead of replacing it. See attached image. The circled area in the top chart shows the "dirty" coloring; the bottom one is the clean one after I refreshed the chart. Enclosed is also the simple code I am using to color/draw the region.

                    How would I need to go about it so that it basically removes the light blue and replaces it with the light red when the direction of the LinReg changes? Is that even possible to do code wise? Is there perhaps something like "RemoveDrawRegion"?

                    sandman
                    Attached Files
                    Last edited by sandman; 11-04-2015, 02:25 PM.

                    Comment


                      #11
                      Hello sandman,

                      Thanks for your reply.

                      You could handle this by using some logic that is set when one drawregion or the other colors in a given bar and then using RemoveDrawObject("tagname").

                      You would save the CurrentBar number into an int variable when you draw the region. The next time you draw the region, if CurrentBar == saveBar, then you could remove the previously drawn region to remove the prior color and keep your regions pure.

                      A lot of work but it is what you would need to do to remove one object.
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks Paul. I think I'll pass on that one. (It's way beyond my current abilities.)

                        What's the fastest way to "refresh" a chart. Currently I open the indicator menu of the chart, then simply click on "Close". Is there a faster way?

                        sandman

                        Comment


                          #13
                          Hello sandman,

                          Thanks for your post.

                          You could click on the chart (to bring it into "focus") and press the F5 key to reload ninjascript. Or right mouse click on the chart and select "reload Ninjascript".
                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            PRC2 Indicator

                            Hey guys, where do i find this indicator and load it onto my charts on my platform thanks,,

                            Comment


                              #15
                              Hello Btrez,

                              Thanks for your post and welcome to the NinjaTrader forums.

                              The thread starter posted in code in the 3rd post on this thread. you can click on it to download the zip file. Once downloaded (do not unzip) you can import to NT7 via File>Utilities>Import Ninjascript . Note Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No':
                              Paul H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by danitralla, Yesterday, 03:33 AM
                              1 response
                              18 views
                              0 likes
                              Last Post NinjaTrader_ShawnB  
                              Started by ninjo, Yesterday, 11:54 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post ninjo
                              by ninjo
                               
                              Started by deblanka, Yesterday, 08:56 AM
                              0 responses
                              13 views
                              0 likes
                              Last Post deblanka  
                              Started by Boonfly8, 03-22-2019, 12:30 PM
                              7 responses
                              24 views
                              0 likes
                              Last Post sledge
                              by sledge
                               
                              Started by Sohal, Yesterday, 05:02 AM
                              2 responses
                              19 views
                              0 likes
                              Last Post techmint  
                              Working...
                              X