Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing DrawRegion?

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

    Changing DrawRegion?

    Hi,

    I'm using the following to color the region between Bollinger Bands:

    DrawRegion("FLAT", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Empty, Color.Lime, 2);

    That works fine. My question is how do I dynamicaly change the coloring when I wish to? I've simply tried doing this:

    if(value == 1)
    {
    DrawRegion("FLAT", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Empty, Color.Lime, 2);
    }
    if(value == 2)
    {
    DrawRegion("FLAT", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Empty, Color.Empty, 2);
    DrawRegion("DOWN", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Empty, Color.Red, 2);
    }
    if(value == 3)
    {
    DrawRegion("FLAT", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Empty, Color.Empty, 2);
    DrawRegion("UP", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Empty, Color.Blue, 2);
    }



    But for some reason the color remains the original...why?

    #2
    Try naming each different color a different name and removing the prior region via RemoveDrawObject()

    http://www.ninjatrader-support.com/H...rawObject.html
    RayNinjaTrader Customer Service

    Comment


      #3
      Thanks, but it is still choosing only 1 color...here's the simple code:

      if(value == 1)
      {
      RemoveDrawObject("DOWN"); RemoveDrawObject("UP");
      DrawRegion("FLAT", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Empty, Color.Lime, 2);
      }
      if(value == 2)
      {
      RemoveDrawObject("FLAT"); RemoveDrawObject("UP");
      DrawRegion("DOWN", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Empty, Color.Khaki, 2);
      }
      if(value == 3)
      {
      RemoveDrawObject("FLAT"); RemoveDrawObject("DOWN");
      DrawRegion("UP", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Empty, Color.Lime, 2);
      }


      As you can see, I have different names for the 3 colors (FLAT, UP, DOWN)...not understanding why this is a problem?

      Comment


        #4
        Are you sure your if branches are being entered? I would add some Print() statements and debug.
        RayNinjaTrader Customer Service

        Comment


          #5
          Yes, I'm sure. Instead of Print statements I'm using "DrawDots" to accomplish the same thing, like so:

          MISC = Low[0] - (40 * TickSize); DrawDot("stop" + Time[0], 0, MISC, Color.Blue);


          So for example I have different colored "dots" in each of the "IF" statements...the dots appear on the chart just fine where they should be...so I know the IF statements are executing fine. It's just that the coloring for the region doesn't change...let me know if you want a screenshot.

          Comment


            #6
            You will have to debug your code. The following code works as expected on my PC. Must be something wrong in your code.

            Code:
            ///<summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            ///</summary>
            protectedoverridevoid Initialize()
            {
            CalculateOnBarClose = false;
            Overlay = true;
            PriceTypeSupported = false;
            }
            ///<summary>
            /// Called on each bar update event (incoming tick)
            ///</summary>
            protectedoverridevoid OnBarUpdate()
            {
            if (CurrentBar == 0)
            return;
            
            if (Close[0] > Open[0])
            DrawRegion("myRegion", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Blue, Color.Blue, 5);
            else
            DrawRegion("myRegion", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Lime, Color.Lime, 5);
            }
            

            RayNinjaTrader Customer Service

            Comment


              #7
              Hi

              There's nothing more to debug...if you reference the attached screenshot you can see that there are dots below various candles in different colors at various places. You can also see the "Region" stays colored as a light Khaki color.

              These "DrawDot" commands are within the IF statements...right along with the commands for "DrawRegion"...there are no other commands within the IF statements (other than those "RemoveDrawObject" commands I added in).

              Thus the code is debugged, the IF statements execute properly (as evidenced by the dots)...and, as previously stated, there are no other commands that need to be debugged besides "DrawRegion". I'm perfectly willing to accept there's something wrong with my code, that's why I posted originally to begin with...I'm just at a total loss to understand what it may be...why do the dots plot correctly but the region stays the same color? The idea is to have the region change color when the dots do...
              Attached Files

              Comment


                #8
                Unfortunately I can not take and test your code to see why it does not work as expected. I scripted a quick test which I posted to ensure that the method does work as you and I both expect.

                What I suggest from here is taking my code sample (since I know it works) and use this as a base point for your own code. Add layer by layer of code until you get it to do what you want. If it breaks, you know what you did that caused it not to work.

                Thanks for understanding.
                RayNinjaTrader Customer Service

                Comment


                  #9
                  Well this is getting interesting.

                  I "commented out" EVERY SINGLE LINE of code in my strategy (in the OnBarUpdate function). I then simply copied your code posted below into my strategy (added some brackets):


                  if
                  (Close[0] > Open[0]){DrawRegion("myRegion", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Blue, Color.Blue, 5);}
                  else{DrawRegion("myRegion", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Lime, Color.Lime, 5);}

                  The result is the attached screenshot #1, no change in the problem...remember ALL of my original code is gone and I have ONLY those couple of lines within the strategy now...

                  Upon additional testing it seems to be using both colors, I say this because if I change the colors to Blue and Yellow, it colors the region Purple (a combo of Blue and Yellow)...screenshot #2.

                  Possible bug?
                  Attached Files

                  Comment


                    #10
                    amendment, blue and yellow do not make purple...so ignore that part. However the original problem remains...

                    Comment


                      #11
                      In NT 6.5 Beta 10, the attached indicator works as expected.

                      What is expected is that -

                      When the close is greater than the open the region is blue otherwise it will turn lime.
                      Attached Files
                      RayNinjaTrader Customer Service

                      Comment


                        #12
                        Thanks for the response, that may answer the question. I'm using version 6.5.0.4, I downloaded that "test" indicator and saw no change again. I guess I've got to upgrade to a later version then...

                        Comment


                          #13
                          Well, I guess I officially throw my hands up in surrender on this one...I've upgraded to Beta 10, done MS .NET Framework updates, downloaded the indicator test Ray provided below, and still I see no difference on this at all. The attached screen is of Ray's test, and obviously the problem remains unresolved and I seriously doubt it ever will be at this point...is anybody actually successfully using this command?
                          Attached Files

                          Comment


                            #14
                            Not sure what you are finding that doesn't work. It works perfectly as it is designed. The whole paint region becomes lime when the bar is red and it turns blue when the bar is red. If you wanted different parts of the region colored differently then you will need to just run logic to separate the different sections for your region to color and submit DrawRegion()s for every color change section.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Thanks for the reply. In the last image I posted here is the code used to generate that coloring (taken from Ray's posting earlier):

                              if (Close[0] > Open[0])
                              DrawRegion(
                              "myRegion", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Blue, Color.Blue, 5);
                              else
                              DrawRegion("myRegion", CurrentBar, 0, Bollinger(2, 14).Upper, Bollinger(2, 14).Lower, Color.Lime, Color.Lime, 5);

                              Thus if the latest Close is greater than the open of that bar the region should color Blue, otherwise it should be Lime...thus that chart should have many "threads" of alternating Blue and Lime regions because the bars are constantly going up and down in price...so why is the chart all Lime?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by b16_aln, Today, 05:15 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post b16_aln
                              by b16_aln
                               
                              Started by sidlercom80, Today, 04:57 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post sidlercom80  
                              Started by patricia70, Today, 03:57 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post patricia70  
                              Started by pjsmith, Today, 03:25 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post pjsmith
                              by pjsmith
                               
                              Started by cincai, Today, 01:04 AM
                              1 response
                              14 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Working...
                              X