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 The_Sec, Yesterday, 03:37 PM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by vecnopus, Today, 06:15 AM
            0 responses
            1 view
            0 likes
            Last Post vecnopus  
            Started by Aviram Y, Today, 05:29 AM
            0 responses
            5 views
            0 likes
            Last Post Aviram Y  
            Started by quantismo, 04-17-2024, 05:13 PM
            3 responses
            27 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by ScottWalsh, 04-16-2024, 04:29 PM
            7 responses
            36 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X