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

Why not get the same result?

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

    Why not get the same result?

    Hi in my first post
    My code is:

    if (Close[0] > Close[1]
    && Close[1] > Close[2]
    && Close[2] > Close[3])
    Tradicional.Set(1);
    else
    Tradicional.Set(-1);


    Compared with:

    if (CurrentBar < Period)
    return;

    for (int i = 0; i < Period; i++)
    {
    if (Close[i] > Close[i+1])
    Iterativos.Set(1);
    else
    Iterativos.Set(-1);
    }


    I do not get the same results.

    TIA. Best regards.

    #2
    pequemec,

    If you could describe what you see differently between the two then we could be able to help you understand why it would be different. Thank you.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      The plot obtained is different. Why? View image.
      Attached Files

      Comment


        #4
        The logic in the two are fundamentally different.

        In the first case, you require all 4 closes to be the greater than the previous close at the exact same time.

        In the second case, what you ultimately set your plot to only depends on the last run through of your for loop. You just override old settings with each new loop through instead of assuring that all 4 closes are > than previous simultaneously.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Correct, but the question is:

          Can represent case 1 with a similar logic to the case 2?
          What would be the logic using looping commands?

          Thank you.

          Comment


            #6
            You would need to keep track of each state during the loop and only at the end can you set the plot.
            Josh P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by kempotrader, Today, 08:56 AM
            0 responses
            6 views
            0 likes
            Last Post kempotrader  
            Started by kempotrader, Today, 08:54 AM
            0 responses
            4 views
            0 likes
            Last Post kempotrader  
            Started by mmenigma, Today, 08:54 AM
            0 responses
            2 views
            0 likes
            Last Post mmenigma  
            Started by halgo_boulder, Today, 08:44 AM
            0 responses
            1 view
            0 likes
            Last Post halgo_boulder  
            Started by drewski1980, Today, 08:24 AM
            0 responses
            3 views
            0 likes
            Last Post drewski1980  
            Working...
            X