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

Draw.Region - Not plotting

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

    Draw.Region - Not plotting

    Hi, I have an indicator that is coloring the area between 2 averages.

    I have several problems

    1. It was working on all charts that were in the minutes time frame but would not draw on the daily chart. I'm not sure why.
    2. I upgraded to the latest version of NT8 and it won't draw on any chart for me.
    3. I would like to put the upper and lower band of the moving averages to be shown in the databox. I'm not sure how to do this.
    4. When this indicator is loaded I would like to offset the right margin of the chart so that I can put text markers on the right such that they do not interfere with the chart.

    I have attached my indicator zip file.

    Thanks for any help you can give me.
    Attached Files

    #2
    Hello cp.trader,
    Thanks for your post and welcome to the NinjaTrader forum.

    1. It was working on all charts that were in the minutes time frame but would not draw on the daily chart. I'm not sure why.
    How many days of data are you loading on your chart?
    2. I upgraded to the latest version of NT8 and it won't draw on any chart for me.
    Are there any errors on the 'Logs' tab of your Control Center?
    3. I would like to put the upper and lower band of the moving averages to be shown in the data box. I'm not sure how to do this.
    Just set the upper and lower bands to a Value to get them to appear in the data box. For example, to set the primary value of the indicator you would set your calculation to Value[0].This would appear in the data box with your plots name. Additionally, you can go on to assign multiple values to your indicator to display in the data box using Value[1], Value[2], etc.
    4. When this indicator is loaded I would like to offset the right margin of the chart so that I can put text markers on the right such that they do not interfere with the chart.
    You should be able to do this with ChartControl.Properties.BarMarginRight
    I would set this in State.DataLoaded
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your response, I tried to sort the issues out but couldn't achieve the desired result.

      I had a look.

      Originally posted by NinjaTrader_JoshG View Post
      Hello cp.trader,
      Thanks for your post and welcome to the NinjaTrader forum.


      How many days of data are you loading on your chart?
      365 days which should be more than enough. If I chart just the moving averages, they show no problem.


      Are there any errors on the 'Logs' tab of your Control Center?
      Yes

      Indicator 'MDI': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

      I can't see in the code where I'm accessing outside the array bounds.


      Just set the upper and lower bands to a Value to get them to appear in the data box. For example, to set the primary value of the indicator you would set your calculation to Value[0].This would appear in the data box with your plots name. Additionally, you can go on to assign multiple values to your indicator to display in the data box using Value[1], Value[2], etc.
      I'm using Value[0] and Value[1]. I was assuming there must be an option that I need to change to put them in the databox.

      You should be able to do this with ChartControl.Properties.BarMarginRight
      I would set this in State.DataLoaded
      Thank you this worked properly for me.

      If I comment Draw.Region out it appears to plot the 2 moving averages for me with no problems.

      as long as draw.region is comment out I will see
      Draw region is as follows


      //Draw.Region(this, regionName, CurrentBar - trendStartBar + 1, 0, MDI1, MDI2, null, fillBrush, 20);

      Comment


        #4
        I agree that's plenty of days being loaded. I think you may have an issue with the 'MDI' indicator. Did you create that indicator or did you get it from somewhere?

        The error you are seeing on your log is a very common NinjaScript error. Please see the tip at the following link for information on resolving this error.


        Once that error is fixed I would expect for you to be able to use Draw.Region without issue.
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          My first go at writing one myself. Basically it is just 2 moving averages with the region colored between them.
          I wasn't able to find an example of this for NT8. Do you know of any examples

          Comment


            #6
            I wasn't able to find an example of this specifically. I will leave this post open for anyone else that wants to offer suggestions on where to find something like this.
            Josh G.NinjaTrader Customer Service

            Comment


              #7
              Thanks Josh,

              I have it working at the moment, but I had to use a try catch to get rid of the exception.

              I've attached a code snippet that is causing the problem. I can't see how to apply your previous suggestion to fix this. I can't see what is causing the problem any further insight would be appreciated.

              The update bar is

              protected override void OnBarUpdate()
              {
              try
              { //Add your custom indicator logic here.

              MDI0[0] = emaValues[0]; // Plot the selected MA fast
              MDI1[0] = wmaValues[0]; // Plot the selected MA slow

              TrendDirection mdi0TrendDirection = IsRising(MDI0) ? TrendDirection.Rising : IsFalling(MDI0) ? TrendDirection.Falling : TrendDirection.Neutral;
              TrendDirection mdi1TrendDirection = IsRising(MDI1) ? TrendDirection.Rising : IsFalling(MDI1) ? TrendDirection.Falling : TrendDirection.Neutral;

              TrendDirection trend;
              if (mdi0TrendDirection == TrendDirection.Rising && mdi1TrendDirection == TrendDirection.Rising)
              {
              trend = TrendDirection.Rising;
              trendBrush = PanelColorTrendRising;
              }
              else if (mdi0TrendDirection == TrendDirection.Falling && mdi1TrendDirection == TrendDirection.Falling)
              {
              trend = TrendDirection.Falling;
              trendBrush = PanelColorTrendFalling;
              }
              else
              {
              trend = TrendDirection.Neutral;
              trendBrush = PanelColorTrendNeutral;
              }


              if (currentTrendDirection != trend)
              {
              currentTrendDirection = trend;
              trendChangeStartBar = CurrentBar;
              regionName = "trend" + CurrentBar.ToString();
              }

              Draw.Region(this, regionName, CurrentBar - trendChangeStartBar + 1, 0, MDI0, MDI1, Brushes.Transparent, trendBrush, TrendOpacity, 0);
              }
              catch (System.Exception ex)
              {
              }
              }

              Where
              emaValues = EMA(Close, Period).Value;
              wmaValues = WMA(Close, Period).Value;

              and
              [XmlIgnore]
              [Browsable(false)]
              public Series<double> MDI0
              {
              get { return Values[0]; }
              }

              [XmlIgnore]
              [Browsable(false)]
              public Series<double> MDI1
              {
              get { return Values[1]; }
              }
              I can't see what is happening to cause the error I described before

              Comment


                #8
                Hello cp.trader,

                Thank you for your response.

                The main item here is the use of the SolidColorBrushes. I would recommend not only reviewing our materials on brushes at the following link but downloading my edited version of your indicator and reviewing the changes I made. Specifically I am using Brushes in place of SolidColorBrushes.

                Working with Brushes: https://ninjatrader.com/support/help...th_brushes.htm

                Please let me know if you have any questions.
                Attached Files

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by sephichapdson, Today, 11:36 PM
                0 responses
                1 view
                0 likes
                Last Post sephichapdson  
                Started by bortz, 11-06-2023, 08:04 AM
                47 responses
                1,612 views
                0 likes
                Last Post aligator  
                Started by jaybedreamin, Today, 05:56 PM
                0 responses
                9 views
                0 likes
                Last Post jaybedreamin  
                Started by DJ888, 04-16-2024, 06:09 PM
                6 responses
                19 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by Jon17, Today, 04:33 PM
                0 responses
                6 views
                0 likes
                Last Post Jon17
                by Jon17
                 
                Working...
                X