Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

RSI checks over 30 day period

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

    RSI checks over 30 day period

    Hi All,

    I would like to be able to create an indicator which checks a few conditions relating to the RSI value and share price of the stock.

    When the RSI value rises above 30 I want to be able to check that the next time it dips below 30 is within a 20 - 35 day time frame. So basically I want to find conditions where it dips down below the 30 mark and then again where the intervening period in which it is above the 30 mark is 20 - 35 days before it dips down again. I probably haven't explained it very well. Please let me know if you need me to clarify further.

    In addition to the above condition there is a further condition in that the price must have dropped by more than 5% in the period when it was above 30 i.e. between the 2 consecutive drops below the 30 line.

    I am pretty sure that the above is possible from a programming point of view but I thought I would get some advice on the best way to structure the code rather than having to write 35 if and else statements which I guess would do it, but would be rather clunky.

    I would like the output to produce a value of 1 on the day where it meets the condition and 0 if not. I would like to insert this custom indicator into the market analyser where I can use it to scan hundreds of stocks.

    I am a beginner in terms of coding experience so any references to similar code in other indicators would be most helpful. I should be able to use that to give me what I need.

    Many thanks,

    Evan

    #2
    Hello evan.hatch,

    Thanks for your post.

    You didn't say specifically so I am assuming you are looking at daily bars so my responses are based on that assumption.

    What you can do is to use bool variables (either true or false) to help you when you have identified the first condition and use the fact of daily bars to count bars until the other time. When the RSI goes above 30 you would set a bool true and also save the CurrentBar at the time and also the close price of the bar.

    Next you would check that the bool you have just set is true and if the RSI is now less than 30, if so you would check the number of bars from now to when you saved the bar number at the time RSI first when above 30. If the number of bars (days) is between your ranges then you have a valid signal and can then test if the current close price is 5% less.
    (Note: I may not have understood your conditions but the answer to your questions are to use bools variables and save values to compare later).

    Regarding the market analyzer, the best approach here is to add a transparent plot to your indicator. This will create a dataseries that you can set to be a zero or one. At the start of your OnBarUpdate() you would set the plot value to be zero, later in your code when all your conditions are true you would set the plot to a value of 1 which you can use in the market analyzer.

    References:
    http://ninjatrader.com/support/helpG...sic_syntax.htm
    http://ninjatrader.com/support/helpG...indicators.htm

    Comment


      #3
      Hi Paul,

      Many thanks for your quick response and comprehensive reply. Thanks for providing me with the reference material to help me with the code.

      Are there any indicators which you know use bools which you could point me to. Alternatively is there a way I can search through the Ninjascript code to find occurrences of the term bool in the various indicators. I could go through each one individually but I was wondering if there was a quicker way to find some actual code which might be easier for me to look at to understand how it works.

      To answer your question, yes I am using day data and so will be capturing the EOD data to be used in my code.

      I understand the last part about outputting a zero or one in my indicator so that I can highlight the positive conditions when they get met. It is just getting to that point which will be the challenge but I will give it a go.

      Many thanks,

      Evan

      Comment


        #4
        Hello evan.hatch,

        Thanks for your reply.

        You might review CurrentDayOHL indicator for an example of using bool variables. In this indicator they are used to enable/disable code execution if a particular plot is requested by the user or not.

        You can look through other code and look for a declaration like private bool nameofbool

        Regarding the plot, it might be easier for you to create a new indicator using the indicator wizard and name a plot and set it to transparent and then let the wizard create the rest of the structure for you. You can then either use that as is (to then create your indicator) or at least see what code is there specifically related to using a plot.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        566 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X