Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Counting Up vs Down Bars
Collapse
X
-
Hello brucelevy,
Thank you for writing in and thank you for your patience. While I am not aware of an indicator like this, you could write your own. Here is a basic idea of how the code would work:
]Code:#region Variables private int barsBackToCount = 5; // Default setting for BarsBackToCount #endregion protected override void Initialize() { Add(new Plot(Color.FromKnownColor(KnownColor.GreenYellow), PlotStyle.Line, "UpBars")); Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "DownBars")); Overlay = false; } protected override void OnBarUpdate() { int upBarCount = 0, downBarCount = 0; if(CurrentBar > barsBackToCount) { for(int i = 0; i < barsBackToCount; i++) { if(Input[i] > Input[i + 1]) { //Up Bar upBarCount++; } else if(Input[i] < Input[i + 1]) { //Down Bar downBarCount++; } else if (Input[i] == Input[i + 1]) { //Equal Bar //Do nothing } } UpBars.Set(upBarCount); DownBars.Set(downBarCount); } } #region Properties [Browsable(false)] [XmlIgnore()] public DataSeries UpBars { get { return Values[0]; } } [Browsable(false)] [XmlIgnore()] public DataSeries DownBars { get { return Values[1]; } } [Description("Number of bars back to count up and down bars for")] [GridCategory("Parameters")] public int BarsBackToCount { get { return barsBackToCount; } set { barsBackToCount = Math.Max(1, value); } } #endregion
I have attached this indicator to my post as a reference which you can use if you would like to design your own version.
Please let me know if I may be of further assistance.Attached FilesMichael M.NinjaTrader Quality Assurance
-
Thank you so much this is helping a lot. I have one more question, how can I plot text in the upper left corner without plotting the panel?
I am using the following to display the up bar and down bar in text on the screen, but when I remove the plots in Initialize the text dissapears.:
{
DrawTextFixed("CompanyName", "Up Bar",TextPosition.TopLeft);
}
Comment
-
Hello brucelevy,
Thank you for the update. Could you please show me the full code you are using right now so I can better assist? If you do not want to plot the data but instead have text counters fixed in the upper left corner of the chart, the code will be different.
Thank you in advance.Michael M.NinjaTrader Quality Assurance
Comment
-
Hello brucelevy,
Here is an updated version of the code that does what you want:
The changes I made are as follows:Code:#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; #endregion // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { /// <summary> /// Enter the description of your new custom indicator here /// </summary> [Description("The Buy Sell Profile measures up bars verse down bars to gauge direction. Buy pullbacks on Buy Profile, Sell Pullbacks on Sell Profile.")] public class FTRBuySellProfile : Indicator { #region Variables // Wizard generated variables private int barsBackToCount = 20; //Default setting private int areaOpacity = 10; // User defined variables (add any user defined variables below) #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { Overlay = true; DrawOnPricePanel = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { int upBarCount = 0, downBarCount = 0; if(CurrentBar > barsBackToCount) { for(int i = 0; i < barsBackToCount; i++) { if(Input[i] > Input[i + 1]) { //Up Bar upBarCount++; } else if(Input[i] < Input[i + 1]) { //Down Bar downBarCount++; } else if (Input[i] == Input[i + 1]) { //Equal Bar //Do nothing } } if (upBarCount > downBarCount) { //DrawTextFixed("CompanyName", "Buy Profile",TextPosition.TopLeft); DrawTextFixed("tag1", "FTR Buy Profile",TextPosition.TopLeft, Color.Black, ChartControl.Font, Color.Gray, Color.Lime, areaOpacity); } else if (upBarCount < downBarCount) { //DrawTextFixed("CompanyName", "FTR Sell Profile",TextPosition.TopLeft); DrawTextFixed("tag1", "Sell Profile",TextPosition.TopLeft, Color.Black, ChartControl.Font, Color.Gray, Color.Red, areaOpacity); } else if (upBarCount == downBarCount) { DrawTextFixed("tag1", "Balanced Profile",TextPosition.TopLeft, Color.Black, ChartControl.Font, Color.Gray, Color.Yellow, areaOpacity); } //Logo DrawTextFixed("tag2", "www.FuturesTradeRoom.com",TextPosition.BottomLeft , Color.Black, ChartControl.Font, Color.Gray, Color.White, areaOpacity); } } #region Properties [Description("Number of bars back to count up and down bars for")] [GridCategory("Parameters")] public int BarsBackToCount { get { return barsBackToCount; } set { barsBackToCount = Math.Max(1, value); } } #endregion } }
1) Removed the data series we originally used to plot from the initialize, on bar update, and properties areas
2) Set Overlay to true and set DrawOnPricePanel to true
Please let me know if I may be of further assistance.Michael M.NinjaTrader Quality Assurance
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
558 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
545 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment