• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Last value above or below in arrays

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

    Last value above or below in arrays

    I am looking for a method or sample code to show in a RSI array if the value was above 80 or below 20. which is was the RSI above 80 or below 20 the last time it moved to extremes.
    Which came last.

    #2
    Hello fatbat,

    Thanks for your post and welcome to the NinjaTrader forums!

    If I understand correctly you are looking for a way to have a signal to show which last occurred, either RSI > 80 or RSI < 20. The easist way would be to use a bool variable (either true or false) that is set by checking for the conditions. For example, you can create bool called rsiFlag that is set true when RSI goes above 80 and then is set false when RSI is less than 20:

    Code:
    if (RSI(14, 3)[0] > 80)
    {
    rsiFlag = true; 
    }
    else if (RSI(14, 3)[0] < 20)
    {
    rsiFlag = false;
    }
    Your code can then use the bool condition to identify what last occurred.

    If you wanted to know when the last occurrence was you could save the bar number into an int variable for example called savedBar that you can then use like CurrentBar - SavedBar = barsago of the last occurrence.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thx so much for the code but what I should have mentioned is where and how do you declare the flag variable that would act more like a global var and not get reset on every new bar.

      Comment


        #4
        Hello fatbat,

        Thanks for your reply.

        You can declare the bool in the area called #region variables, for example:

        private bool rsiFlag = false;

        In the onBarUpdate() method, the code example previously provided will only change the state of the bool if either of the RSI conditions are met. It would not change on every bar unless the RSI went from <20 to >80 or vice versa from one bar to the next.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by uiwislth, Yesterday, 11:25 PM
        0 responses
        4 views
        0 likes
        Last Post uiwislth  
        Started by Steve L, Yesterday, 10:04 PM
        0 responses
        3 views
        0 likes
        Last Post Steve L
        by Steve L
         
        Started by marianfed, Yesterday, 09:47 PM
        0 responses
        4 views
        0 likes
        Last Post marianfed  
        Started by hir04068, Yesterday, 09:29 PM
        0 responses
        2 views
        0 likes
        Last Post hir04068  
        Started by iq200, 03-11-2018, 07:49 PM
        24 responses
        1,017 views
        0 likes
        Last Post mrlucky1x  
        Working...
        X