PDA

View Full Version : Operator Error Message


Mike Winfrey
08-03-2007, 05:55 PM
I am writing an indicator that is a variation of the CCI. The CCI normally uses typical which is (high + low + close) / 3. I want to redefine typical to be
myTypical = (Max(High, 3)+Min(Low, 3)+Close) / 3

Simple enough but I don't know how to work around the strongly typed C#.

These are the code snippets where I attempt to do this.
Variable Declaration...
private DataSeries myTypical;

protected void RedefineTypical()
{
myTypical.Set((Math.Max(High[0], 3)+Math.Min(Low[0], 3)+Close[0]) / 3);
}
Ok I know you know what's coming next. I get a compile error stating Operator '+' cannot be applied to operands of type 'NinjaTrader.Data.lDataSeries' and 'NinjaTrader.Data.lDataSeries'

Also I get an error "the best overloaded method match for system.math.mas(sbyte,sbyte) has some invalid arguments. argument '1' cannot convert from ninjatrader.dat.idataseries to sbyte.
Thank you for your help.
Mike

NinjaTrader_Dierk
08-03-2007, 11:35 PM
Code line below has no error. Just click on the error message, it will bring you to the erroneous code line.

Mike Winfrey
08-04-2007, 05:53 AM
Thank you for the timely reply, especially at midnight. Holy cow...don't you sleep? Incredible. Anyway, I know about double clicking on the error message which is how I found out where the error is and the error is just as I described. However, I notice that I sent you the wrong code. That error was accurate for that code but obviously doesn't apply now. Don't know what I was thinking but anyway can we please start over.

Here's the real code that I want to work...a screen shot of this code and the error are attached. The screen shot also shows how I want to use this method and is at the bottom of the code.

#region Variables
private int period = 14;
private DataSeries myTypical;
#endregion

protected void RedefineTypical()
{
myTypical.Set((Math.Max(High, 3)+Math.Min(Low, 3)+Close) / 3);
}

protected override void OnBarUpdate()
{
if (CurrentBar == 0)
Value.Set(0);
else
{
double mean = 0;
for (int idx = Math.Min(CurrentBar, Period - 1); idx >= 0; idx--)
mean += Math.Abs(myTypical[idx] - SMA(myTypical, Period)[0]);
Value.Set((myTypical[0] - SMA(myTypical, Period)[0]) / (mean == 0 ? 1 : (0.015 * (mean / Math.Min(Period, CurrentBar + 1)))));
}
}

NinjaTrader_Ray
08-04-2007, 09:39 AM
Here is one problem, you as passing in a DataSeries object of high prices (High) to Math.Max() instead of a double value.

Math.Max(High[0], 3)

instead of

Math.Max(High, 3)

Mike Winfrey
08-04-2007, 02:24 PM
Thank you...i made the change as you suggested which looks like this.

myTypical.Set((Math.Max(High[0], 3)+Math.Min(Low[0], 3)+Close[0]) / 3);

and now it successfully compiles. I have other issues now but i'll work on them a bit before I bother anyone with it.

Thanks,
Mike