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

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
    Paul H.NinjaTrader Customer Service

    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.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,605 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        8 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        4 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        13 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X