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!
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
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:
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 traderqz, Yesterday, 09:06 AM
|
3 responses
21 views
0 likes
|
Last Post Today, 10:36 AM | ||
Started by f.saeidi, Today, 10:19 AM
|
1 response
5 views
0 likes
|
Last Post Today, 10:31 AM | ||
Started by kujista, Today, 06:23 AM
|
5 responses
15 views
0 likes
|
Last Post
by kujista
Today, 10:26 AM
|
||
Started by traderqz, Today, 12:06 AM
|
3 responses
6 views
0 likes
|
Last Post Today, 09:41 AM | ||
Started by RideMe, 04-07-2024, 04:54 PM
|
5 responses
28 views
0 likes
|
Last Post Today, 08:48 AM |
Comment