I need a little bit of help with the following code. The code is reading a text file and finds the next highest value when referenced against the private int num = 4800; It works as expected.
[Description("Displays Levels")]
public class MyCustomIndicator2 : Indicator
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
private string path = Cbi.Core.UserDataDir.ToString() + "PIn.txt";
private int[] levels;
private int count = 0;
private string readText = "";
private int num = 4800;
private int tmp, res = 0;
private int? diff = null;
#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()
{
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = false;
levels = new int[1000];
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
readText = File.ReadAllText("C:\\PIn.txt");
string [] split = readText.Split(new Char [] {';'});
foreach (string s in split)
{
count++;
tmp = int.Parse(s);
levels[count] = tmp;
if (tmp > num)
{
if(diff == null)
diff = num;
if ((tmp - num) < diff)
{
res = tmp;
diff = tmp - num;
}
}
}
Print(res);
}
#region Properties
#endregion
}
}
I want to use the Close[0] but I am getting the following error on lines 67 & 71;
Cannot implicitly convert type 'double' to 'int?'. An explicit conversion exists (are you missing a cast?)
#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;
using System.IO;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Displays Levels
/// </summary>
[Description("Displays Levels")]
public class MyCustomIndicator2 : Indicator
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
private string path = Cbi.Core.UserDataDir.ToString() + "PIn.txt";
private int[] levels;
private int count = 0;
private string readText = "";
private int tmp, res = 0;
private int? diff = null;
#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()
{
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = false;
levels = new int[1000];
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
readText = File.ReadAllText("C:\\PIn.txt");
string [] split = readText.Split(new Char [] {';'});
foreach (string s in split)
{
count++;
tmp = int.Parse(s);
levels[count] = tmp;
if (tmp > Close[0])
{
if(diff == null)
diff = Close[0];
if ((tmp - Close[0]) < diff)
{
res = tmp;
diff = tmp - Close[0];
}
}
}
Print(res);
}
#region Properties
#endregion
}
}
#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 MyCustomIndicator2[] cacheMyCustomIndicator2 = null;
private static MyCustomIndicator2 checkMyCustomIndicator2 = new MyCustomIndicator2();
/// <summary>
/// Displays Levels
/// </summary>
/// <returns></returns>
public MyCustomIndicator2 MyCustomIndicator2()
{
return MyCustomIndicator2(Input);
}
/// <summary>
/// Displays Levels
/// </summary>
/// <returns></returns>
public MyCustomIndicator2 MyCustomIndicator2(Data.IDataSeries input)
{
if (cacheMyCustomIndicator2 != null)
for (int idx = 0; idx < cacheMyCustomIndicator2.Length; idx++)
if (cacheMyCustomIndicator2[idx].EqualsInput(input))
return cacheMyCustomIndicator2[idx];
MyCustomIndicator2 indicator = new MyCustomIndicator2();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.SetUp();
MyCustomIndicator2[] tmp = new MyCustomIndicator2[cacheMyCustomIndicator2 == null ? 1 : cacheMyCustomIndicator2.Length + 1];
if (cacheMyCustomIndicator2 != null)
cacheMyCustomIndicator2.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheMyCustomIndicator2 = tmp;
Indicators.Add(indicator);
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>
/// Displays Levels
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.MyCustomIndicator2 MyCustomIndicator2()
{
return _indicator.MyCustomIndicator2(Input);
}
/// <summary>
/// Displays Levels
/// </summary>
/// <returns></returns>
public Indicator.MyCustomIndicator2 MyCustomIndicator2(Data.IDataSeries input)
{
return _indicator.MyCustomIndicator2(input);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Displays Levels
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.MyCustomIndicator2 MyCustomIndicator2()
{
return _indicator.MyCustomIndicator2(Input);
}
/// <summary>
/// Displays Levels
/// </summary>
/// <returns></returns>
public Indicator.MyCustomIndicator2 MyCustomIndicator2(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.MyCustomIndicator2(input);
}
}
}
#endregion
suprsnipes

Comment