Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Indicator using RSI and different Data Series

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

    Custom Indicator using RSI and different Data Series

    Hi,

    Looking for any sample code of an RSI indicator that uses different data series. ie. RSI(Chaiken Oscillator), RSI(MACD), RSI(OBV)....

    similar to https://www.tradingview.com/blog/en/new-feature-8211-apply-an-indicator-to-another-indicator-1844/


    *******
    Goal:
    1. Create an indicator for RSI

    Do the following if Indicator values fall within a certain range on BAR CLOSE:
    i.e.
    If
    RSI(OBV) > 50
    AND
    RSI(Chaiken)>60
    AND
    RSI(Close) >40

    Highlight Bar Yellow

    *****






    #2
    Hi nguyenak, thanks for your note and welcome to the NinjaTrader forum.

    I attached a sample indicator that only processes on the secondary series added by AddDataSeries. Please see attached. To run this place it within Documents\NinjaTrader 8\bin\Custom\Indicators

    Please also review this page on multi time frame scripts:

    https://ninjatrader.com/support/help...nstruments.htm

    Please let me know if you have any further questions.
    Attached Files

    Comment


      #3
      Hi there,
      Thanks so much! Unfortunately, the file didn't open for me. I'm using Ninja Trader 8. Still learning process..but pretty cool.

      - I placed it in the directory you specified.
      - Tools --> Import --> Ninja Script Add-on

      Did I do it wrong?


      Another Goal
      1. Apply Indicator to Market Analyzer as a Column.

      Question:
      1. Will the indicator provide a value of 0 or 1 in Market Analyzer? or do I need to program that into the indicator?


      Again, thanks for the support!


      Comment


        #4
        Hello nguyenak,

        Thank you for your reply.

        Chris is out of the office at the moment, but I'm happy to help.

        If you placed the file Chris provided in Documents > NinjaTrader 8 > bin > Custom > Indicators, all you need to do from there is run a compile - you've already manually imported the file by putting it there yourself, so you don't need to import it through the Tools menu. Instead, go to New > NinjaScript Editor, then right click in the editor window and select "Compile". You should then be able to see the indicator in the list of available indicators.

        Note that the indicator Chris provided is just an example and will just print the RSI value of the secondary data series to a NinjaScript output window. If you added this to a Market Analyzer indicator column, no value would show as the indicator does not plot any values. You would need to adapt this example to add an exposed plot value that would then show up in the market analyzer.

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

        Comment


          #5
          Great!...so I got the indicator to compile and work based on the above example.

          That said, what do you mean as Plot to produce 0 or 1 for Market Analzyer.

          For the indicator, if the conditions are true, it paints the current bar and adds an arrow.

          If I'm not understanding correctly, if you could share with me an example, I'll try to incorporate it.


          again, thanks for the help.
          Attached Files

          Comment


            #6
            Hello nguyenak,

            Thank you for your reply.

            Your indicator does a few things with rendering, but it doesn't assign anything to a Plot. A Plot is what the Market Analyzer will display the value of - it doesn't have bars so it can't color the bar, and you can't use the drawing objects on it because it's not a chart. Basically, that part's all going to be ignored by the Market Analyzer.

            Here's a link to our help guide on AddPlot():


            I'd recommend adding a transparent plot so when you apply it to a chart the plotting doesn't mess with your other visuals, but then the Market Analyzer can still grab those values to display. Here's an edited version of yours that adds a transparent plot that will show 0 in the Market Analyzer unless your conditions are true, when it will show a 1:

            Code:
                public class MutlipleRSIRange : Indicator
                {
                    private RSI RSI1;
                    private ChaikinOscillator ChaikinOscillator1;
                    private RSI RSI2;
                    private OBV OBV1;
                    private RSI RSI3;
            
                    protected override void OnStateChange()
                    {
                        if (State == State.SetDefaults)
                        {
                            Description                                    = @"Enter the description for your new custom Indicator here.";
                            Name                                        = "MutlipleRSIRange";
                            Calculate                                    = Calculate.OnBarClose;
                            IsOverlay                                    = true;
                            DisplayInDataBox                            = true;
                            DrawOnPricePanel                            = true;
                            DrawHorizontalGridLines                        = true;
                            DrawVerticalGridLines                        = true;
                            PaintPriceMarkers                            = true;
                            ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                            //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                            //See Help Guide for additional information.
                            IsSuspendedWhileInactive                    = true;
            
                            AddPlot(Brushes.Transparent, "RSIRangeTrue");
                        }
                        else if (State == State.Configure)
                        {
            
                        }
                        else if (State == State.DataLoaded)
                        {                
                            RSI1                = RSI(Close, 14, 3);
                            ChaikinOscillator1    = ChaikinOscillator(Close, 3, 10);
                            RSI2                = RSI(ChaikinOscillator1, 14, 3);
                            OBV1                = OBV(Close);
                            RSI3                = RSI(OBV1, 14, 3);
                        }
                    }
            
                    protected override void OnBarUpdate()
                    {
                         if (BarsInProgress != 0) 
                            return;
            
                        if (CurrentBars[0] < 14)
                            return;
                        Value[0] = 0;
            
                         // Set 1
                            if ((RSI1[0] >= 30)
                             && (RSI1[0] <= 30)
                             && (RSI2[0] >= 35)    && (RSI3[0] <= 45) && (RSI3[0] >= 40))
                        {
            
                            BarBrush = Brushes.CornflowerBlue;
                            Draw.ArrowUp(this, @"My UP Arrow", true, 0, (Low[0] - (2 * TickSize)), Brushes.Lime);
                            Value[0] = 1;
                        }
            
                    }
            Please let us know if we may be of further assistance to you.

            Comment


              #7
              Nice!

              I added those 2 pieces of code. It works great! thanks so much!!

              I understand what you're referring but I keep getting errors when I try to add the code.
              Im a newbie programmer and still use the wizard so I don't really know how to debug.


              thanks again...


              Attached Files

              Comment


                #8
                Last question:

                Will alerts keep informing me for each candle where the conditions are met?

                ie. If I changed all the Conditions to RSI > 30 on 1 min.

                If not, is that done on indicator code or on the alerts section?

                I would like it to update me on each candle.

                Comment


                  #9
                  Hello nguyenak,

                  Thank you for your replies.

                  Looks like you have the indicator working in your Market Analyzer column there in your screenshot. You can then use that to set up Alerts based on whether the value in the column is 1 or 0. if it's a 1, the conditions in your indicator are true, if 0, they are false. Using this in the Market Analyzer, every time the column value changes to 1, you'll get an alert only when the value initially switches to 1. The Market Analyzer doesn't really have a concept of Bars so if you needed to have an alert every bar this is true, you'd likely need to set that up as a chart based indicator.

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

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by argusthome, Yesterday, 10:06 AM
                  0 responses
                  18 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  17 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  14 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  9 views
                  0 likes
                  Last Post TheRealMorford  
                  Started by Mindset, 02-28-2026, 06:16 AM
                  0 responses
                  38 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Working...
                  X