• 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

Help with shading regions.

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

    Help with shading regions.

    Hi, I have created a 3 EMA trend indicator. It works well and I have it saved. I then saved it as something else to start work on phase 2. Phase 2 is to shade the regions in between the plots. I am trying to get one region working properly first , then will tackle the second region. I have borrowed some code from an indicator that I already have that shades regions and adapted it to this one. However no shading appears on the indicator. I have read through all that I could in the reference manual, and played around with it and not succeeded in making it work. I have attached the file and a screen shot of the working phase 1 version. Looking at the pic the 0 line is the long term ema, the other 2 are the short and mid term ema's. I wish to shade the region between the long and mid term ema's. Once I have that working, I should be able to easily shade between the short and mid term ema's in a similar fashion. This is the piece of code that I think is the first to need a look at.... Draw.Region(this,"TrendMA33",CurrentBar, 0, MidEMA, LongEMA, Brushes.Transparent, ZoneColor, Zopacity);
    Please open the file and inspect the code, and advise me on what the problem is, and how I should approach fixing it.
    Attached Files

    #2
    Hello KennyK,

    If you want the drawing objects to appear on the indicator panel DrawOnPricePanel needs to be false.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea, that was simple.

      Comment


        #4
        Hi ChelseaB,
        I have added code now for the second shaded region. Please open up the attached file to view. What is happening is the regions shade properly if only one or the other is selected in the UI, but if both are selected only the first one shades. Is there a problem with my if statements? Or what? Thanks.
        Attached Files

        Comment


          #5
          Hello KennyK,

          Both drawing objects are using the same tag name. You are updating the first object with the tag name and you are not making a new object.

          See Note 2 at the bottom of the Drawing page in the help guide.

          https://ninjatrader.com/support/help...us/drawing.htm
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thanks again Chelsea, all fixed and working.
            I have now added more code in an attempt to have the shaded regions differ in color for up trend and downtrend as you will see if you open the attached file. I have added some commenting to make my intentions clearer. Can you please check it out and advise what I need to do to make it work? Presently everything looks right in the UI. The only problem is both colors draw simultaneously for the long trend and same for the short trend.
            Thanks, Ken.
            Attached Files

            Comment


              #7
              Hello KennyK,

              You will need to change the startBarsAgo and endBarsAgo to the bars you are wanting the region colored over.

              Currently, you are drawing all objects from first bar (CurrentBar) to the most recent bar (0) which is all of bars of the chart.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Got it all working now. Thanks for your help.
                However I want to make another change that I need some explanation for. I want to assign the Z-Order of the 4 regions that are drawing. Firstly do they draw in the order that they are coded as a default? Like the first regions draws on the chart, then the next region in the code draws on top of the previous, then the next region in the code draws on top of the previous, and so on?
                If so I can simply re-arrange the order of the code. However if that is not so. I want to know how to assign the Z-Order to each individual region please? I have only ever set the Z-Order of a whole indicator to plot behind the bars. As such.....
                if(State==State.Historical)
                {
                // Make sure our object plots behind the chart bars
                SetZOrder(-1);
                }
                Can you please shed some light on it for me?
                Cheers,
                Ken.

                Comment


                  #9
                  Hello KennyK,

                  Thanks for the reply.

                  That is correct, the z-order will be set in the order the drawing tools are made. The drawing tool that you want to be in the background must be added first, and for the drawing tool in the foreground, draw that one last.

                  Please let me know if I can assist further.
                  Chris L.NinjaTrader Customer Service

                  Comment


                    #10
                    I have sorted the Z-order, it's all working as it should. Thanks.
                    Only thing now is the indicator dosen't save with a template. Meaning when I have the indicator on a chart, save it as a chart template. then open a new chart, apply the saved template, all is there except this indicator. What would the problem be?

                    Comment


                      #11
                      Hello KennyK,

                      Thanks for the reply.

                      It sounds like the indicator is not serializing a specific property that your code is using. If you have public properties that are brushes, see this page on serializing brush objects so they can be saved:

                      https://ninjatrader.com/support/help...definedbrushes

                      For an example that serializes a TimeSpan object, please see this page:
                      https://ninjatrader.com/support/foru...pan-parameters

                      Please let me know if this does not resolve your inquiry.

                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Chris, I looked into what you said, tried a few things unsuccessfully, as you will see some commented out code in the properties. Please have a look at the uploaded file and see what the problem is and please advise on how to go about fixing it. I am only a novice coder, so please explain as such.
                        Thanks.
                        Attached Files

                        Comment


                          #13
                          Hi Chris, Since the previous reply I have tried something else. In the User defined properties sections "ColorZoneUp & ColorZoneDown", I added "[XmlIgnore]", to each of the properties. This worked apart from the region shading, the indicator was saved with the template, but the region shading was not there, because the check box in the UI was blank, instead of ticked. So I changed the default from false to true to make it work. Shouldn't the UI selections be saved in the template? I am assuming when [XmlIgnore] is used, when the property gets reloaded it is only reloaded as default? Is that right? Maybe there is another problem in my code? I looked at similar code of another indicator, it didn't have [XmlIgnore] applied to it's UI properties. So I am thinking there is another problem with my code?

                          Comment


                            #14
                            Hello KennyK,

                            Thanks for the reply.

                            Adding [XmlIgnore] will do the trick for your public brush objects. I made a simple script that has a bool property and the template saved properly for me. Here is the property I used:

                            Code:
                            [NinjaScriptProperty]
                            [Display(Name="MyBool", Order=1, GroupName="Parameters")]
                            public bool MyBool
                            { get; set; }
                            I wasn't able to find the section of code you refer to in your last post. If the above does not resolve your inquiry, could you please point out the specific area of code that is not saving properly?

                            I look forward to hearing of your results.
                            Chris L.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Chris,
                              My Bool property looks like yours.
                              I have attached the MACrossBuilder indicator that I got from here. This is one indicator I have been copying snippets from and studying in terms of layout.
                              Please firstly look at the attached pics, in my TrendMA35 properties as shown, you will see a sub-region "ColorZoneUp"', this where I asked you to look in the last message. Also in comparison, check the MACrossBuilder properties " FastMA" section. You will see no [XMLIgnore] in there. I have attached the MACrossBuilder indicator for your reference.
                              Thanks Ken.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by yeshujbp, Today, 08:10 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post yeshujbp  
                              Started by backtester831, Today, 06:54 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post backtester831  
                              Started by frayrengytrader, Today, 06:03 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post frayrengytrader  
                              Started by JustAFish, Today, 05:29 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post JustAFish  
                              Started by TraderCAD, Today, 04:27 PM
                              1 response
                              8 views
                              0 likes
                              Last Post TraderCAD  
                              Working...
                              X