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

Drawing a rectangle from another series bar type.

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

    Drawing a rectangle from another series bar type.

    So as long as my BarsArray[0] is the same as my BarsArray[1], the rectangle plots correctly but that defeats the purpose of the multiple timeframes. I want to be able to change my DataSeries Type to tick, etc. and be able to plot the rectangle based upon the 1 min BarsArray[1] series.

    How do I calculate the barsAgo from 1 series to another? Compare timestamps on the bars Could be a heavy processing cost....

    #2
    Hello jalley,

    Thanks for your post.

    I would suggest using the Draw.Rectangle method overload where you specify the DateTime rather than the bars ago. That is how global draw objects are able to draw from one chart to another regardless of the bar-type/size, by using the price data and the date/time of the anchor points.

    Reference: https://ninjatrader.com/support/help..._rectangle.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      I actually tried that first and it went to barsAgo version and errored even though I used the method signature with the start/end times and the other parameters of that signature.

      Comment


        #4
        Hello jalley,

        Thanks for your reply.

        That does not sound right.

        Here is an example you can copy and test with:

        public class DrawrectanglebyTime : Indicator
        {
        private bool doitonce = true;


        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = @"Enter the description for your new custom Indicator here.";
        Name = "DrawrectanglebyTime";
        Calculate = Calculate.OnBarClose;
        IsOverlay = true;
        DisplayInDataBox = true;
        DrawOnPricePanel = true;
        DrawHorizontalGridLines = true;
        DrawVerticalGridLines = true;
        PaintPriceMarkers = true;
        ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
        //Disable this property if your indicator requires custom values that cumulate with each new market data event.
        //See Help Guide for additional information.
        IsSuspendedWhileInactive = true;
        }
        else if (State == State.Configure)
        {
        AddDataSeries(Data.BarsPeriodType.Minute, 1);
        }
        }
        protected override void OnBarUpdate()
        {
        if (State != State.Realtime) // wait for first real time bar close
        return;

        if (BarsInProgress != 0) return; // draw on the chart bars

        // draw a 3 minute long rectangle, once.
        if (doitonce)
        {
        Draw.Rectangle(this, "Test", Times[1][3], Lows[1][3], Times[1][0], Highs[1][0], Brushes.Gold);

        doitonce = false;
        }
        }


        With the code above I can draw a rectangle on any non-time based bars, such as tick, volume, range. See the screenshot below. I opened the rectangle property so you can see it is a 3 minute rectangle and if you look at where it starts and stops it does not line up with the center of the bar like it normally would when drawn using those chart bars.

        Click image for larger version

Name:	jailey-1.PNG
Views:	403
Size:	68.2 KB
ID:	1144246
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks!, That did the trick

          Comment


            #6
            So it is working great when the data series is not using tick replay. Only change that causes it to break but not display any errors (just doesn't show the rectangle) is to click tick replay on the dataseries. The code line:

            Draw.Rectangle(this, "IBRect" + DayofYear.ToString(), true, Times[1][x], DayIBLowPrice, Times[1][y], DayIBHighPrice, Brushes.Gray, Brushes.Gray, 30);

            What could be causing it not to paint this rectangle when tick replay is checked? The lines and text I plot are working fine with or without tick replay.

            Comment


              #7
              Hello jalley,

              Thanks for your reply.

              I would suggest debugging the code to find out why.

              You can add print statements to print out the conditions that would tell the draw statement to draw and then print statements to print out the values used by the draw statement to see if they align with your expectations.

              Please see the help guide debugging tips here: https://ninjatrader.com/support/help...script_cod.htm


              Paul H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by adeelshahzad, Today, 03:54 AM
              4 responses
              22 views
              0 likes
              Last Post adeelshahzad  
              Started by merzo, 06-25-2023, 02:19 AM
              10 responses
              823 views
              1 like
              Last Post NinjaTrader_ChristopherJ  
              Started by frankthearm, Today, 09:08 AM
              5 responses
              15 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              43 views
              0 likes
              Last Post jeronymite  
              Started by yertle, Today, 08:38 AM
              5 responses
              16 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Working...
              X