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

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.

          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:



                      For an example that serializes a TimeSpan object, please see this page:


                      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 gentlebenthebear, Today, 01:30 AM
                              2 responses
                              13 views
                              0 likes
                              Last Post gentlebenthebear  
                              Started by Kaledus, Today, 01:29 PM
                              2 responses
                              7 views
                              0 likes
                              Last Post Kaledus
                              by Kaledus
                               
                              Started by frankthearm, Yesterday, 09:08 AM
                              13 responses
                              45 views
                              0 likes
                              Last Post frankthearm  
                              Started by PaulMohn, Today, 12:36 PM
                              2 responses
                              16 views
                              0 likes
                              Last Post PaulMohn  
                              Started by Conceptzx, 10-11-2022, 06:38 AM
                              2 responses
                              56 views
                              0 likes
                              Last Post PhillT
                              by PhillT
                               
                              Working...
                              X