Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I created the following indicator by copy and paste and modify an existing one and adding my own formulas. My goal is simply to make some calculations and show those in the data box on a daily chart. I don't have to show any plots but it's okay if that's necessary in order to show the values in the data box.
The problem I'm having is that I don't understand how to show the multiple values as plots. See the note shown as "(More Important Problem)" to see the error messages I get.
Here's the Indicaor code:
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Calculates Ed's custom ranges of a bar.
/// </summary>
[Description("Calculates the range of a bar.")]
public class RangesDailyEd : Indicator
{
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
private double DayRange = 0;
private double CloseOpenRange = 0;
private double CloseOpenPCTofDay = 0;
private double HighRange = 0;
private double LowRange = 0;
CalculateOnBarClose = true;
AutoScale = true;
Overlay = false; // Does not plot the indicator on top of price
}
/// <summary>
/// NOTE: (Less Important Problem) Called on each bar update event (incoming tick) but I only need to calculate upon BarClose,
/// and close must be based on data series time frame, e.g. if bar ends at 4:15 pm ET then that's bar close
/// and calculated values should show in data box for the last bar on the chart which it isn't doing now
/// </summary>
protected override void OnBarUpdate()
{
/// Up Day or Close = Open
if (Close[0] >= Open[0])
{
DayRange = (High[0] - Low[0]);
CloseOpenRange = Close[0] - Open[0]; /// will be Positive for an Up day
CloseOpenPCTofDay = CloseOpenRange/DayRange * 100; /// express as positive % to indicate an Up day
HighRange = High[0] - Close[0];
LowRange = Open[0] - Low[0];
/// write the above values in the data box for an Up Day
}
/// Down Day
if (Open[0] > Close[0])
{
DayRange = (High[0] - Low[0]);
CloseOpenRange = Close[0] - Open[0]; /// will be Negative for a Down day
CloseOpenPCTofDay = CloseOpenRange/DayRange * 100; /// express as negative % to indicate a Down day
HighRange = High[0] - Open[0];
LowRange = Close[0] - Low[0];
/// write the above values in the data box for a Down Day
}
/// NOTE: (More Important Problem) How do I set the appropriate values for each variable? Right now it gives this error message
/// for each of the following:
/// 'double' does not contain a definition for 'Set' and no extension method 'Set' accepting a first argument of type 'double'
/// could be found (are you missing a using directive or assembly reference?)
DayRange.Set(DayRange);
CloseOpenRange.Set(CloseOpenRange);
CloseOpenPCTofDay.Set(CloseOpenPCTofDay);
HighRange.Set(HighRange);
LowRange.Set(LowRange);
}
}
}
#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private RangesDailyEd[] cacheRangesDailyEd = null;
private static RangesDailyEd checkRangesDailyEd = new RangesDailyEd();
/// <summary>
/// Calculates the range of a bar.
/// </summary>
/// <returns></returns>
public RangesDailyEd RangesDailyEd()
{
return RangesDailyEd(Input);
}
/// <summary>
/// Calculates the range of a bar.
/// </summary>
/// <returns></returns>
public RangesDailyEd RangesDailyEd(Data.IDataSeries input)
{
if (cacheRangesDailyEd != null)
for (int idx = 0; idx < cacheRangesDailyEd.Length; idx++)
if (cacheRangesDailyEd[idx].EqualsInput(input))
return cacheRangesDailyEd[idx];
lock (checkRangesDailyEd)
{
if (cacheRangesDailyEd != null)
for (int idx = 0; idx < cacheRangesDailyEd.Length; idx++)
if (cacheRangesDailyEd[idx].EqualsInput(input))
return cacheRangesDailyEd[idx];
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// Calculates the range of a bar.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.RangesDailyEd RangesDailyEd()
{
return _indicator.RangesDailyEd(Input);
}
/// <summary>
/// Calculates the range of a bar.
/// </summary>
/// <returns></returns>
public Indicator.RangesDailyEd RangesDailyEd(Data.IDataSeries input)
{
return _indicator.RangesDailyEd(input);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Calculates the range of a bar.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.RangesDailyEd RangesDailyEd()
{
return _indicator.RangesDailyEd(Input);
}
/// <summary>
/// Calculates the range of a bar.
/// </summary>
/// <returns></returns>
public Indicator.RangesDailyEd RangesDailyEd(Data.IDataSeries input)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
Your first problem (less important problem) is controlled by the CalculateOnBarClose setting. In your code, it appears you have this defaulted to true, which means the code should only run on the close of a bar, not every single tick.
The other issue (more important problem) is a data type issue.