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 BarzTrading, Today, 07:25 AM
            2 responses
            14 views
            1 like
            Last Post BarzTrading  
            Started by devatechnologies, 04-14-2024, 02:58 PM
            3 responses
            19 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by tkaboris, Today, 08:01 AM
            0 responses
            3 views
            0 likes
            Last Post tkaboris  
            Started by EB Worx, 04-04-2023, 02:34 AM
            7 responses
            162 views
            0 likes
            Last Post VFI26
            by VFI26
             
            Started by Mizzouman1, Today, 07:35 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X