Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why the error?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Why the error?

    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.

    #2
    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.)

    Comment


      #3
      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!!

      Comment


        #4
        >> got a book on C++
        Please make sure you get a book about C#. NinjaScript is C# and not C++.

        Comment


          #5
          Originally posted by NinjaTrader_Dierk View Post
          >> 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.

          Comment


            #6
            Yes, they are different.
            RayNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            603 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            349 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            104 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            560 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            560 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X