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

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()

    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:
            [FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]<summary>
            [/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000] This method is used to configure the indicator and is called once before any bar data is loaded.
            [/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]</summary>
            [/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Initialize()
            {
            CalculateOnBarClose = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];
            Overlay = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];
            PriceTypeSupported = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];
            }
            [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]<summary>
            [/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000] Called on each bar update event (incoming tick)
            [/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080]</summary>
            [/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] OnBarUpdate()
            {
            [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (CurrentBar == [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])
            [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];
            
            [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (Close[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] > Open[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]])
            DrawRegion([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"myRegion"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], CurrentBar, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], Bollinger([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]14[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]).Upper, Bollinger([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]14[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]).Lower, Color.Blue, Color.Blue, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]5[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
            [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]else
            [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]DrawRegion([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"myRegion"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], CurrentBar, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], Bollinger([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]14[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]).Upper, Bollinger([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]14[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]).Lower, Color.Lime, Color.Lime, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]5[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
            }
            [/SIZE][/FONT]

            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 WeyldFalcon, 08-07-2020, 06:13 AM
                              11 responses
                              1,422 views
                              0 likes
                              Last Post jculp
                              by jculp
                               
                              Started by RubenCazorla, Today, 09:07 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post RubenCazorla  
                              Started by BarzTrading, Today, 07:25 AM
                              2 responses
                              29 views
                              1 like
                              Last Post BarzTrading  
                              Started by devatechnologies, 04-14-2024, 02:58 PM
                              3 responses
                              21 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by tkaboris, Today, 08:01 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post tkaboris  
                              Working...
                              X