Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Help with ternary conditional operator (ie, "?:") not working!

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

    Help with ternary conditional operator (ie, "?:") not working!

    Hi there,

    I'm trying to do a ?: construction, and it just won't go! Here's a simplified boildown, I would truly appreciate your help with this.

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class TESTING : Strategy
    {

    private Series<double> test;


    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    ... THE USUAL STUFF HERE...
    }

    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    test = new Series<double>(this, MaximumBarsLookBack.Infinite);
    }

    else if (State == State.Transition)
    {
    double test = (Close[0] > Close[1]) ? High[0] : ((Close[0] == Close[1]) ? Close[0] : Low[0]);
    }
    }
    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (test[0] > test[1])
    {
    EnterLongLimit(Convert.ToInt32(DefaultQuantity), (Close[0] + (-2 * TickSize)) , "");
    }

    // Set 2
    if (test[0] < test[1])
    {
    ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
    }

    #2
    Originally posted by catinabag View Post
    I'm trying to do a ?: construction, and it just won't go! Here's a simplified boildown, I would truly appreciate your help with this.
    [snip]
    Code:
    double test = (Close[0] > Close[1]) ? High[0] : ((Close[0] == Close[1]) ? Close[0] : Low[0]);
    Is this the line you're referring to?
    The syntax of that C# code is correct.

    I even copied this single line into a test script and it compiles just fine ...

    Originally posted by catinabag View Post
    ...and it just won't go!
    What do you mean?
    Can you post a screenshot of the error message?

    Comment


      #3
      Thanks, bltdavid, for your response!

      So, the problem I get is when I run this code through the "Strategy Analyzer." It gives exactly zero trades over all time periods. I believe there is something wrong with they way I have entered the ternary conditional operator, or perhaps something else which may be structural in nature (like how and where I am defining the test variable).

      The code will compile fine, but it just won't give any Strategy Analyzer results.

      Obviously, this isn't an actual strategy, but it encapsulates the problem I am having. I would truly appreciate help with this!!!

      Comment


        #4
        Oh, now I see .. I think you're trying to populate test as a data Series ...

        This line,
        Code:
        double [COLOR=#FF0000]test[/COLOR] = (Close[0] > Close[1]) ? High[0] : ((Close[0] == Close[1]) ? Close[0] : Low[0]);
        is wrong, it should probably be this,

        Code:
        [COLOR=#FF0000]test[/COLOR][COLOR=#000000][0][/COLOR] = (Close[0] > Close[1]) ? High[0] : ((Close[0] == Close[1]) ? Close[0] : Low[0]);
        And you probably want this code inside OnBarUpdate -- not OnStateChange

        Comment


          #5
          Thank you very, very much! I truly appreciate your kind gesture of answering this question on a Saturday evening. You get the gold star for the day!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by gravdigaz6, Today, 11:40 PM
          0 responses
          3 views
          0 likes
          Last Post gravdigaz6  
          Started by MarianApalaghiei, Today, 10:49 PM
          3 responses
          9 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by XXtrader, Today, 11:30 PM
          0 responses
          3 views
          0 likes
          Last Post XXtrader  
          Started by love2code2trade, Yesterday, 01:45 PM
          4 responses
          28 views
          0 likes
          Last Post love2code2trade  
          Started by funk10101, Today, 09:43 PM
          0 responses
          9 views
          0 likes
          Last Post funk10101  
          Working...
          X