Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Brush filling

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

    Brush filling

    I am trying to figure out the following but after quite some time have got nowhere:

    Take the Donchian Channel:

    If condition X

    paint a backcolor only between the Donchians (something which can be done for sure)

    else

    Don't paint anything.

    I have samples of brush filling but both involve continuously painting between two Values but alternating colors based on a crossover. I am simply too dense to extrapolate the basic brush filling commands from the crossover conditions. (The samples are Slingshot and IchiCloud from the shared section).

    I would be very grateful is someone could provide an example of brushfilling between the Donchians with a condition. From there I can figure it out - and also share the results.

    The goal is to create a trading range fill when the range narrows and stabilizes. I can already do this fine with back color but I would prefer to have it painted only between the Donchians rather than the whole screen. Small thing, but nice to get right and also opportunity to learn more about coding in Ninja.

    Thanks in advance.

    #2
    cclsys, unfortunately I'm not aware of sample code for this. Have you tried setting the fillcolor to transparent when there's no range being formed according to your conditions?

    You could also play around with different opacity settings for this.

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      cclsys, unfortunately I'm not aware of sample code for this. Have you tried setting the fillcolor to transparent when there's no range being formed according to your conditions?

      You could also play around with different opacity settings for this.

      http://www.ninjatrader-support.com/H...rawRegion.html
      Bernard: you are way ahead of me. I can't figure out how to set the fill color between two points in the first place. I can do a back color for the whole screen easily enough, but trying to do a fill I got nowhere. I couldn't find anything in the help menus, even referencing the brush code. My only samples are for filling in two lines and changing when the crossover, which in the coding is quite complex. I am unable to figure out which part of the code is the simple brush fill aspect and which deals only with the crossover conditions. So I am hoping for an example of simple fill code, i.e. filling between two MA's, or as I have suggested: two Donchian lines (i.e. the upper and lower plots). From there I am sure I can figure it out.

      Opacity is a later issue but of course one can simply choose pale colors if necessary. Thxs.

      Not that it means much, but I attach a pic of the back color trading range formulation in operation (back color is Salmon). I would prefer that the color remain within, and change along with, the upper and lower Donchians which is one aspect of the code used to determine whether or not the mkt is in trading range type action.
      Attached Files
      Last edited by cclsys; 08-17-2009, 01:06 PM.

      Comment


        #4
        cclsys, it's perhaps best when you check out the Standard Error Bands indicator I posted some time ago to the sharing, it's filling the areas betweens the different bands - http://www.ninjatrader-support2.com/...id=150&catid=1

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          cclsys, it's perhaps best when you check out the Standard Error Bands indicator I posted some time ago to the sharing, it's filling the areas betweens the different bands - http://www.ninjatrader-support2.com/...id=150&catid=1
          Thanks. I could not find the DrawRegion by looking for things like 'brush', 'fill', 'color' etc. So that is very helpful.

          Now I have added it in but it ignores my condition - which works fine in an above section of code as shown in an attached pic - and simply paints between Upper and Lower for long periods of time, or not at all for some reason, but neither spot seems to have anything to do with the code.

          Again, the condition
          if ((ExtendUp[0] >= ExtendDown[0]) )

          works fine (I have been using it for months). But DrawRegion doesn't regard it as kosher for some reason.

          Also changing it to:

          "if (lRoption && ExtendUp[0] < ExtendDown[0])
          return;
          if (lRoption && ExtendUp[0] >= ExtendDown[0])

          {DrawRegion("Trading Range", CurrentBar, 0, Upper, Lower, Color.Empty, Color.Salmon, 5);}
          "

          makes no difference. It just fills all the time between the Donchians.
          Attached Files
          Last edited by cclsys; 08-17-2009, 03:13 PM.

          Comment


            #6
            From the chart you posted it seems like the condition works properly but the upper and lower values you enter as boundaries are not properly used. Please check those and ensure the correct ones are entered in the DrawRegion call.

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              From the chart you posted it seems like the condition works properly but the upper and lower values you enter as boundaries are not properly used. Please check those and ensure the correct ones are entered in the DrawRegion call.
              I am not sure I understand but all I can say in reply is that Upper and Lower are two Plot Series that represent the Upper and Lower Donchians and plot accurately. They are Upper.Set and Lower.Set, they plot fine etc.

              Is that not correct, therefore? Also, when it does plot, it plots those values perfectly. The problem is that it does not start or stop plotting based on the condition. The values seem not to be the issue.

              Comment


                #8
                For example, I have made a new version of your St Error Smooth and added the following at the end:

                //assign plotted values to the DataSeries objects
                Middle.Set(lrSeries[0]);
                Upper.Set(lrSeries[0] + WidthMiddle * erSmo);
                Lower.Set(lrSeries[0] - WidthMiddle * erSmo);
                Upper2.Set(lrSeries[0] + WidthOuter * erSmo);
                Lower2.Set(lrSeries[0] - WidthOuter * erSmo);

                //fill the 2 sets of bands with color and allow for custom opacity level for both
                //DrawRegion("StdErrorSmooth1", CurrentBar, 0, Lower2, Lower, Color.Empty, LowerColor, OpacityOuter);
                //DrawRegion("StdErrorSmooth2", CurrentBar, 0, Lower, Upper, Color.Empty, MiddleColor, OpacityMiddle);
                //DrawRegion("StdErrorSmooth3", CurrentBar, 0, Upper, Upper2, Color.Empty, UpperColor, OpacityOuter);

                if ( (DLR(2000,true,27).ExtendUp[0]) >= (DLR(2000,true,27).ExtendDown[0]))
                DrawRegion("StdErrorSmooth1", CurrentBar, 0, Upper2, Lower2, Color.Empty, Color.Salmon, OpacityOuter);
                //else
                //DrawRegion("StdErrorSmooth1", CurrentBar, 0, Upper2, Lower2, Color.Empty, Color.Empty, OpacityOuter);
                //RemoveDrawObject("StdErrorSmooth1");

                ++++++++

                Even if I write it this way it still plots all the time no matter what:

                if ( (DLR(2000,true,27).ExtendUp[0]) >= (DLR(2000,true,27).ExtendDown[0]))
                DrawRegion("StdErrorSmooth1", CurrentBar, 0, Upper2, Lower2, Color.Empty, Color.Salmon, OpacityOuter);
                if ( (DLR(2000,true,27).ExtendUp[0]) < (DLR(2000,true,27).ExtendDown[0]))
                DrawRegion("StdErrorSmooth1", CurrentBar, 0, Upper2, Lower2, Color.Empty, Color.Empty, OpacityOuter);

                In all cases, the result is that it plots between your Upper2 and Lower2 all the time and ignores the condition. It's exactly the same problem I have with my Donchian one. Can't get it to respond to condition. Adding in RemoveDrawObject makes not the slightest difference even though I know for a fact that the condition is not always true. Also, clearly the values work since the plots are accurate (in both indicators), just not their on-offing.
                Last edited by cclsys; 08-17-2009, 04:07 PM.

                Comment


                  #9
                  cclsys, if you refer to the chart you posted, it does seems to respect the condition you have set...it would be easiest if you can attach the full source code so I can plot this on my end here to check, thanks

                  Comment


                    #10
                    Originally posted by NinjaTrader_Bertrand View Post
                    cclsys, if you refer to the chart you posted, it does seems to respect the condition you have set...it would be easiest if you can attach the full source code so I can plot this on my end here to check, thanks
                    Sorry. I thought I had attached code earlier. Here it is again.
                    Attached Files

                    Comment


                      #11
                      If you prefer, here is your standard error with fill and with my conditions for my Donchians. But if you can insert any simple condition that turns the filling-in on and off, that would be most helpful.
                      Attached Files

                      Comment


                        #12
                        In my inbox I received the following msg from Bertrand but don't see it on the thread:

                        "cclsys, unfortunately I'm not aware of sample code for this. Have you tried setting the fillcolor to transparent when there's no range being formed according to your conditions?"

                        In the StdErrorFill code above I have:

                        if ( (DLR(2000,true,27).ExtendUp[0]) >= (DLR(2000,true,27).ExtendDown[0]))
                        DrawRegion("StdErrorSmooth1", CurrentBar, 0, Upper2, Lower2, Color.Empty, Color.Salmon, OpacityOuter);
                        if ( (DLR(2000,true,27).ExtendUp[0]) < (DLR(2000,true,27).ExtendDown[0]))
                        DrawRegion("StdErrorSmooth1", CurrentBar, 0, Upper2, Lower2, Color.Empty, Color.Empty, OpacityOuter);

                        It plots always between the two lines ExtendUp and ExtendDown correctly, but does not plot empty when the condition is nullified, just keeps plotting.

                        I also tried:
                        else
                        DrawRegion("StdErrorSmooth1", CurrentBar, 0, Upper2, Lower2, Color.Empty, Color.Empty, OpacityOuter);

                        and also tried:
                        else
                        RemoveDrawObject("StdErrorSmooth1");

                        The result is always the same: it plots between the two lines all the time.

                        Comment


                          #13
                          cclsys, please check the attached file out, it shows how to achieve this with an opacity setting of 0.
                          Attached Files

                          Comment


                            #14
                            Well it paints one way (the first condition), but not the other. This is better, but similar to my problem except mine paints all the time versus only painting during the first condition whereas yours doesn't paint the second condition but at least stops painting the first condition. I tried moving the lingo over but now I get no painting all of the time. But before when it painted, it was painting the correct values, so I know the values are correct. Mystery!

                            Then I remembered the log!

                            The log error reads:

                            Error on calling the 'OnBarUpdate' method for indicator 'StdErrFill' on bar 0: StdErrFill.DrawRegion: startBarsAgo out of valid range 0 through 0
                            I don't know what this means but I added in the condition
                            if (CurrentBar < Period) return;
                            that was the problem.

                            Now it works fine.

                            I have learned a lesson: always check the log. This has been suggested before but since most of the time when I have problems there are no log errors, I have not got in the habit of checking it. Lesson learned.
                            Last edited by cclsys; 08-18-2009, 10:14 AM.

                            Comment


                              #15
                              cclsys, what this script does it this, if the Condition is true it paints a DrawRegion with opacity of 10, if it's not true it paints another DrawRegion with opacity of 0 > so essentially it's not displaying. So I believe you can create your 'range' coloring with this workaround.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              591 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              343 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              556 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              553 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X