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

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.
    Emily C.NinjaTrader Customer Service

    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.​
        Emily C.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by iceman2018, Today, 11:46 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by Torontobluejays, Yesterday, 08:43 AM
        4 responses
        23 views
        0 likes
        Last Post Torontobluejays  
        Started by Ticks_66, Today, 09:50 AM
        2 responses
        14 views
        0 likes
        Last Post Ticks_66  
        Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
        7 responses
        27 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by akuntysh, 05-18-2018, 03:39 AM
        11 responses
        810 views
        0 likes
        Last Post Leeroy_Jenkins  
        Working...
        X