Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to compare indicator value being the same reading over x bars back

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

    #16
    Hello tkaboris,

    Thank you for your reply.

    Yes, your loop does check the value of TrendMagicModified1 for the current bar with the values from 1, 2, 3, 4, and 5 bars ago. If any of those values do not equal the current bar's value, 1 is added to notEqual. If notEqual is 0, that means the value has been the same for the current bar and the 5 bars before it.

    notEqual is only one part of your condition. Your condition is checking for 3 different things to be true all at the same time. Not only does notEqual need to be 0, it is also checking that TrendMagicModified1.BullOrBear[1] is 0 and TrendMagicModified1.BullOrBear[2] is 1. If all three of those things are not met at the same time, the logic of that condition will not be executed. From your prints and the screenshots you have shared, it does not appear that all three parts of the condition have all been met at the same time.

    You will need to evaluate your condition and determine if it makes logical sense for all three parts of the condition to be true at the same time or not. So far, in the examples you have shown with prints, all three parts of the condition have not been met.

    Please let us know if we may be of further assistance.

    Comment


      #17
      hi i think i know what the issue is, notEqual needs to be offset by 2 bars. Currently below condition will never be true, becausee notEqual was prior the entry bar, and before line changes from red to green. So how can we offset this notEqual == 0 occurence to couple of bars back?

      ((TrendMagicModified1.BullOrBear[1] == 0) && (TrendMagicModified1.BullOrBear[2] == 1)

      && (notEqual == 0)
      )​

      Comment


        #18
        Hello tkaboris,

        Thank you for your reply.

        You will need to consider the logic inside of your loop and which bars you would like to have it compare:

        for (int i = 1; i <=5; i++)
        {
        // Print(string.Format("{0}TrendMagicModified1[0]: {1} TrendMagicModified1[{2}]: {3}", CurrentBar, TrendMagicModified1[0], i, TrendMagicModified1[i]));
        // This condition checks if the value of TrendMagicModified1 for the current bar does not equal the TrendMagicModified1 value from the barsAgo values looped through with i. You will need to decide how many bars back you want to offset this and adjust the barsAgo indexes used and the values for i in the loop
        if (TrendMagicModified1[0] != TrendMagicModified1[i])
        {
        notEqual++;
        }
        }

        Thank you for using NinjaTrader.​

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        64 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        139 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        75 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X