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 maybeimnotrader, Yesterday, 05:46 PM
            2 responses
            21 views
            0 likes
            Last Post maybeimnotrader  
            Started by adeelshahzad, Today, 03:54 AM
            5 responses
            32 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by stafe, 04-15-2024, 08:34 PM
            7 responses
            32 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by merzo, 06-25-2023, 02:19 AM
            10 responses
            823 views
            1 like
            Last Post NinjaTrader_ChristopherJ  
            Started by frankthearm, Today, 09:08 AM
            5 responses
            22 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Working...
            X