NexusFi: Find Your Edge


Home Menu

 





Trouble with multiple plots on an indicator


Discussion in NinjaTrader

Updated
    1. trending_up 5,072 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

Trouble with multiple plots on an indicator

  #1 (permalink)
eddd
St Louis, Missouri
 
Posts: 2 since May 2011
Thanks Given: 0
Thanks Received: 0

All help is, of course, greatly appreciated.

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;

protected override void Initialize()
{
Add(new Plot(Color.Orange, PlotStyle.Hash, "DayRange"));
Add(new Plot(Color.Green, PlotStyle.Hash, "CloseOpenRange"));
Add(new Plot(Color.Red, PlotStyle.Hash, "CloseOpenPCTofDay"));
Add(new Plot(Color.Blue, PlotStyle.Hash, "HighR"));
Add(new Plot(Color.Violet, PlotStyle.Hash, "LowRange"));

Plots[0].Pen.DashStyle = DashStyle.Solid;
Plots[4].Pen.DashStyle = DashStyle.Dash;

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];

RangesDailyEd indicator = new RangesDailyEd();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
Indicators.Add(indicator);
indicator.SetUp();

RangesDailyEd[] tmp = new RangesDailyEd[cacheRangesDailyEd == null ? 1 : cacheRangesDailyEd.Length + 1];
if (cacheRangesDailyEd != null)
cacheRangesDailyEd.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheRangesDailyEd = tmp;
return indicator;
}
}
}
}

// 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");

return _indicator.RangesDailyEd(input);
}
}
}
#endregion

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Deepmoney LLM
Elite Quantitative GenAI/LLM
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
23 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #3 (permalink)
 MooreTech 
Orlando, Florida
 
Experience: Advanced
Platform: NinjaTrader, TradeStation, MultiCharts, eSignal, MetaTrader
Trading: ES
Posts: 57 since Aug 2010
Thanks Given: 6
Thanks Received: 73


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.

private double DayRange = 0;
private double CloseOpenRange = 0;
private double CloseOpenPCTofDay = 0;
private double HighRange = 0;
private double LowRange = 0;

Because this data is of type double, there is no .Set() method. To set the values for the plots, you can use the Values[] array:

Values[0].Set(DayRange);
Values[1].Set(CloseOpenRange);
etc...

Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
eddd
St Louis, Missouri
 
Posts: 2 since May 2011
Thanks Given: 0
Thanks Received: 0

MooreTech,
It works.
I really appreciate your assistance.
Ed

Reply With Quote




Last Updated on May 31, 2011


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts