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 DanielTynera, Today, 01:14 AM
            0 responses
            2 views
            0 likes
            Last Post DanielTynera  
            Started by yertle, 04-18-2024, 08:38 AM
            9 responses
            40 views
            0 likes
            Last Post yertle
            by yertle
             
            Started by techgetgame, Yesterday, 11:42 PM
            0 responses
            11 views
            0 likes
            Last Post techgetgame  
            Started by sephichapdson, Yesterday, 11:36 PM
            0 responses
            2 views
            0 likes
            Last Post sephichapdson  
            Started by bortz, 11-06-2023, 08:04 AM
            47 responses
            1,615 views
            0 likes
            Last Post aligator  
            Working...
            X