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

Displaying a Count of the Number of Range Bars within the last 30mins

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

    Displaying a Count of the Number of Range Bars within the last 30mins

    Hello!

    I'm trying to simplify an aspect of my trading by displaying a Range Bar Count in the top right of my Range chart that shows the Count of Range bars within the last 30mins (and 60mins) from the current bar.

    Finding the Count
    I've read through a number of functions, but can't seem to find a simple way to grab this count.
    I figure I could cycle through all the bars going backwards from the current bar and check the time on each one, but this seems like excessive work for something so simple.

    Anyone know an easy way to work this out?

    Happy to just get it working as an OnBarUpdate() for the latest candle, but if possible I'd quite like it to work when scrolling the chart as well. So that, whenever you are looking back through the data, it always shows the count for 30min behind the currently displayed bar.

    I've had a look at the OnRender() function for chart scrolling but not sure if this is appropriate due to all the warnings about not attempting to do too many calculations within the OnRender() call.

    Help?

    Display
    In terms of display: I've sorted out the Text positioning with declaring these as Fonts:

    private NinjaTrader.Gui.Tools.SimpleFont BTFont = new NinjaTrader.Gui.Tools.SimpleFont("Arial", 12) { Size = 30, Bold = false };
    private NinjaTrader.Gui.Tools.SimpleFont BTSmallFont = new NinjaTrader.Gui.Tools.SimpleFont("Arial", 12) { Size = 20, Bold = false };

    Then adding this to OnBarUpdate() (currently just using integers with preset values):

    rangeString = "| " + int30minCount + " |";
    range60String = int60minCount + "<padding spaces here - not shown in forums> .";

    Draw.TextFixed(this, "30MinCount", rangeString, TextPosition.TopRight, myAlertBrush, BTFont, Brushes.Transparent, Brushes.Transparent, 0);
    Draw.TextFixed(this, "60MinCount", range60String, TextPosition.TopRight, myAlertBrush, BTSmallFont, Brushes.Transparent , Brushes.Transparent, 0);

    Which creates a large value (BTFont) closest to the right side, then some padding spaces to give a smaller number (BTSmallFont) which seems fine and produces this in the top right:

    Click image for larger version

Name:	Display.jpg
Views:	64
Size:	5.4 KB
ID:	1175337

    Although I'm curious if these is a simpler way to do this display as well.

    Thanks to all, and sorry this is so long.

    WeLoveTheLibrary

    #2
    Hello,

    Thanks for your post.

    I'm not aware of an existing indicator that does this and you are welcome to search through the NT user apps section of the NinjaTrader Ecosystem for anything that might get you close or give you further ideas. Here is a link to the NinjaTrader8 indicators section: https://ninjatraderecosystem.com/use...r-8-indicators Please note: The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

    Using Draw.TextFixed() is a good and simple method to use here.

    The current live Range bar has a close time that is constantly changing until the range condition has been met and then once the bar is closed, the bars time is then fixed.

    What you might consider doing is taking the time of the previous bar (Time[1]) which is closed and does not change and then adding a - 30 minute and a -60 minutes to it and use the method GetBar() where you supply the time of the bar to get. The method will return the bar number of the closest bar to that time (which should be good enough for what you are doing). You can then simply subtract the returned number from the current bar number and that will be the number of bars in the 30/60 minute periods. (see the help guide guide example: https://ninjatrader.com/support/help...tml?getbar.htm)

    Here is a quick example:

    protected override void OnBarUpdate()
    {
    if (CurrentBar < 20) return;

    int barsAgo30 = (CurrentBar - Bars.GetBar(Time[1].AddMinutes(-30)))+1; // adding 1 for the current bar
    int barsAgo60 = (CurrentBar - Bars.GetBar(Time[1].AddMinutes(-60)))+1;

    Draw.TextFixed(this, "test", "60: "+barsAgo60+" 30: "+barsAgo30, TextPosition.TopRight);
    }


    CurrentBar is the systems bar counter and points to the active bar: https://ninjatrader.com/support/help...currentbar.htm

    Note that this will only get you the bars from the current bar.

    If you want to scroll back and have that change then you can try using ChartBars.ToIndex instead of CurrentBar: https://ninjatrader.com/support/help...rs_toindex.htm

    But note that you would also have to use that in the Time[] to get the bar you are referencing from because Time is a series and the index must be a bars ago relative to the Currentbar. For example, if you scrolled back 50 bars then you would use Bars.GetBar(Time[CurrentBar - ChartBars.ToIndex].AddMinutes(-30))


    Paul H.NinjaTrader Customer Service

    Comment


      #3
      That's lovely. I'll have a play with those functions and see if I can get it working.

      Thank you so much for your help.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by joostb, Today, 04:40 AM
      0 responses
      4 views
      0 likes
      Last Post joostb
      by joostb
       
      Started by Johnny Santiago, Today, 03:11 AM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by pjsmith, Today, 12:44 AM
      2 responses
      20 views
      0 likes
      Last Post pjsmith
      by pjsmith
       
      Started by Liquidfusion, Yesterday, 10:51 PM
      3 responses
      45 views
      0 likes
      Last Post Liquidfusion  
      Started by jjanguda, Yesterday, 10:57 PM
      1 response
      33 views
      0 likes
      Last Post NinjaTrader_ChrisSch  
      Working...
      X