PDA

View Full Version : Why the error?


maxpi
08-02-2007, 05:44 PM
I am still fumbling with the basics of C#.... I have the following strategy code:

protectedoverridevoid OnBarUpdate()
{
int Sigval =FunctionShort();
if (Sigval =1)
EnterShort();

}

where FunctionShort is an indicator that I wrote using the wizard which works fine when applied to a chart. It has no inputs and it plots a bar whenever it encounters a pattern.

When I compile the above strategy I get the following errors and don't know why really.

Cannot implicitly convert type 'NinjaTrader.Indicator.FunctionShort' to 'int',Strategy\Strat86.cs,42,16,
Cannot implicitly convert type 'int' to 'bool',Strategy\Strat86.cs,43,8,

I can declare Sigval as any kind of variable, I tried them all, I always get the error message regarding FunctionShort.

Gumphrie
08-02-2007, 07:04 PM
You're doing it the wrong way round! You want Sigval to be an integer.

You've called FunctionShort like it is really a function whereas it is an indicator that needs input, even it doesn't take parameters it needs to know what data its dealing with. Use the code editor intellisense to tell you what FunctionShort expects, but I suspect you want to do something like "FunctionShort(Input)[0]"

Plus your next line is wrong too, you are specifying one equals sign, "=", for assignment where what you really want are two equals signs, "==", for comparison.

Welcome to programming in C style syntax!


(Pitty there are no pointers in managed C#, then we could have some real fun.)

maxpi
08-02-2007, 07:15 PM
I visited the local bookstore today and got a book on C++ ... I'm reading it and I don't feel any smarter yet... maybe in a week or two!!

NinjaTrader_Dierk
08-02-2007, 11:11 PM
>> got a book on C++
Please make sure you get a book about C#. NinjaScript is C# and not C++.

maxpi
08-03-2007, 09:20 AM
>> got a book on C++
Please make sure you get a book about C#. NinjaScript is C# and not C++.

are they that much different? I looked at all the books in the bookstore, one was on C# written by same author 1 year after his book on C++ and it looked like 99% rehash.

NinjaTrader_Ray
08-03-2007, 09:45 AM
Yes, they are different.