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

Using Draw objects on Mutiple Time Frames?

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

    Using Draw objects on Mutiple Time Frames?

    I know how to write a MTF indicator. However, for some reason, I'm having a tough time figuring out how to use draw objects and multiple time frames. Could someone show me an example of one and explain how it works?

    #2
    Hello jamestrader21x,

    Thank you for your post.

    Drawing objects can either be drawn on the price panel of the primary data series or in an indicator panel. Bars ago values used will be synced with the primary data series. What is the use case you're having an issue with?

    Thanks in advance; I look forward to assisting further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      I have an support and resistance indicator that plots rectangles. As long as I combing two time frames on one window, and plot the higher time frame indicator on the lower time frame, it works fine. However, when I try to convert the indicator to a multiple time frame indicator, it doesn't plot right. Here are two pictures to show what I mean. I'll also send a copy of my work.




      Click image for larger version

Name:	picture01.png
Views:	103
Size:	103.8 KB
ID:	1186324


      Click image for larger version

Name:	picture02.png
Views:	98
Size:	77.7 KB
ID:	1186325




      Attached Files

      Comment


        #4
        Here is a copy of the indicator. MTFDSRLevels.zip

        Comment


          #5
          Hello jamestrader21x,

          Thank you for your reply.

          When using AddDataSeries, no additional series are visually added but the BarsAgo would represent the series calling OnBarUpdate. If you call the Draw syntax during one of the other BarsInProgress updates, the BarsAgo would relate to that series. If you are trying to draw on the primary series with a BarsAgo you would need to execute that logic from BarsInProgress 0.

          The issue is that the series may not be identical intervals or time. 10 bars ago to the primary may mean a completely different point in the chart from the secondary series. You can access the values of the secondary series, but you'll actually want to draw the rectangles on the primary series.

          I look forward to being of further assistance.
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            So, you're saying that a rectangle drawn at a certain point in time can be offset if plotted on a lower time frame? I'm not using time as a reference. The indicator plots based on Open, High, Low, Close. Based on the picture2 that I posted, the plot isn't even remotely close. I've seen this done before on Ninja Trader 7.

            Comment


              #7
              Hello jamestrader21x,

              Thank you for your reply.

              You're not plotting the rectangles by time, you're plotting them by number of bars ago of the secondary data series. Since that number of bars likely took place within a smaller time frame on the smaller tick series, the times at which the rectangles would get plotted would appear different since they are plotted on the primary series.

              You'd want to use the overloads which allow you to plot by time, for example:

              Draw.Rectangle(NinjaScriptBase owner, string tag, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush)

              You can use Bars.GetTime() to get the time the bars you would have wanted it to plot on the secondary series are at and use the returned times for the start and end time anchors for the rectangle:

              https://ninjatrader.com/support/help...t8/gettime.htm

              For example:

              Code:
              //instantiate StartTime at class level
              private DateTime StartTime;
              
              //if 3rd bar in 7 has 3 lower highs to the right and left, draw a rectangle from swing highest high to swing highest close
              if(swingHigh && swingHighStart)
              {
              mystartBar = CurrentBar - highestHigh; // pick a startpoint
              rect_high = MAX(High,myLookBack)[0]; // pick a high level
              rect_close = MAX(Close,myLookBack)[0]; // pick a close for highest bar level
              StartTime = Bars.GetTime(mystartBar);
              
              if(DoItOnce)
              {
              Draw.Rectangle(this, myRect, false, StartTime, rect_high, Times[0][0], rect_close, BearishOut, BearishBod, Opacity, false);
              swingHighStart = false;
              keepDrawing = true;
              swingHighStart1 = true;
              }
              }
              
              else if (keepDrawing)
              {
              Draw.Rectangle(this, myRect, false, StartTime, rect_high, Times[0][0], rect_close, BearishOut, BearishBod, Opacity, false); // redraw (extend) rectangle to current bar
              }
              
              
              if (CrossAbove(Close, rect_high, 1)) //If a break and close above swing, rectangle stops being drawn
              {
              keepDrawing = false;
              }
              This way they get drawn based on the time and not the primary series bar slots.

              Please let us know if we may be of further assistance to you.
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Kate View Post
                Hello jamestrader21x,

                Thank you for your reply.

                You're not plotting the rectangles by time, you're plotting them by number of bars ago of the secondary data series. Since that number of bars likely took place within a smaller time frame on the smaller tick series, the times at which the rectangles would get plotted would appear different since they are plotted on the primary series.

                You'd want to use the overloads which allow you to plot by time, for example:

                Draw.Rectangle(NinjaScriptBase owner, string tag, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush)

                You can use Bars.GetTime() to get the time the bars you would have wanted it to plot on the secondary series are at and use the returned times for the start and end time anchors for the rectangle:

                https://ninjatrader.com/support/help...t8/gettime.htm

                For example:

                Code:
                //instantiate StartTime at class level
                private DateTime StartTime;
                
                //if 3rd bar in 7 has 3 lower highs to the right and left, draw a rectangle from swing highest high to swing highest close
                if(swingHigh && swingHighStart)
                {
                mystartBar = CurrentBar - highestHigh; // pick a startpoint
                rect_high = MAX(High,myLookBack)[0]; // pick a high level
                rect_close = MAX(Close,myLookBack)[0]; // pick a close for highest bar level
                StartTime = Bars.GetTime(mystartBar);
                
                if(DoItOnce)
                {
                Draw.Rectangle(this, myRect, false, StartTime, rect_high, Times[0][0], rect_close, BearishOut, BearishBod, Opacity, false);
                swingHighStart = false;
                keepDrawing = true;
                swingHighStart1 = true;
                }
                }
                
                else if (keepDrawing)
                {
                Draw.Rectangle(this, myRect, false, StartTime, rect_high, Times[0][0], rect_close, BearishOut, BearishBod, Opacity, false); // redraw (extend) rectangle to current bar
                }
                
                
                if (CrossAbove(Close, rect_high, 1)) //If a break and close above swing, rectangle stops being drawn
                {
                keepDrawing = false;
                }
                This way they get drawn based on the time and not the primary series bar slots.

                Please let us know if we may be of further assistance to you.
                Hi Kate,

                I have a similar situation:

                I have a 1-min chart and I have added a 30-min AddDataSeries. Want to plot on the 1-min chart a vertical line and a horizontal line at the close of the 30-min data series on clock 30 minutes intervals just for the current session. The vertical lines seem to work but the horizontal lines are too many, I assume lines are drawn as the 30 min bar is developing. How do you assign Time indexing in this situation?

                Here is what I have done:

                Code:
                else if (State == State.Configure)
                {
                // Adds a secondary bar object to the indicator
                AddDataSeries(BarsPeriodType.Minute, 30);
                }
                
                }
                
                protected override void OnBarUpdate()
                {
                // Draw horizintal and vertical lines on 30 minutes bars
                if (BarsInProgress == 1 )
                {
                
                Draw.HorizontalLine(this, "PriceLevel"+ CurrentBar, Close[0], Brushes.Goldenrod, DashStyleHelper.Dash, 2, true);
                
                Draw.VerticalLine(this, "PriceInterval"+ CurrentBar, 0, Brushes.GreenYellow, DashStyleHelper.Dash, 2, true);
                }
                Many thanks.

                Comment


                  #9
                  Hello aligator,

                  Thank you for your reply.

                  If it's the horizontal lines that are the issue, what's discussed in the earlier posts in this thread wouldn't really be relevant since horizontal lines are placed based on price, not time.

                  To clarify, are you running this OnBarClose? What do you mean by "the horizontal lines are too many"? Are you looking to only have one horizontal line on the chart that updates to the close of the latest 30 minute bar? What you have now would plot a horizontal line that would continue across the chart and remain there so as you have more 30 minute bars close, more lines would appear on the chart. If you want to just have a single line that shows the latest 30 minute bar's close, don't add the CurrentBar to the tag so it's not unique and will be updated to the new close price when a new 30 minute close occurs:

                  Draw.HorizontalLine(this, "PriceLevel", Close[0], Brushes.Goldenrod, DashStyleHelper.Dash, 2, true);

                  Thanks in advance; I look forward to assisting you further.
                  Kate W.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by set2win, Today, 04:11 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post set2win
                  by set2win
                   
                  Started by trader3000a, Today, 02:18 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post trader3000a  
                  Started by Tavor, Today, 02:06 PM
                  0 responses
                  11 views
                  0 likes
                  Last Post Tavor
                  by Tavor
                   
                  Started by WalterSkinner, 07-01-2022, 03:14 PM
                  2 responses
                  26 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by vitaly_p, Today, 10:13 AM
                  0 responses
                  17 views
                  0 likes
                  Last Post vitaly_p  
                  Working...
                  X