• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 test = (Close[0] > Close[1]) ? High[0] : ((Close[0] == Close[1]) ? Close[0] : Low[0]);
        is wrong, it should probably be this,

        Code:
        test[0] = (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 Oliver81594, Today, 04:09 AM
          0 responses
          2 views
          0 likes
          Last Post Oliver81594  
          Started by Nate G, Yesterday, 05:27 PM
          1 response
          12 views
          0 likes
          Last Post MojoJojo  
          Started by Mindset, Yesterday, 10:35 PM
          1 response
          6 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by habibalex, Yesterday, 08:19 PM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Marco  
          Started by lakersfan, Yesterday, 07:53 PM
          0 responses
          10 views
          0 likes
          Last Post lakersfan  
          Working...
          X