Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

RSI indicator from TC2000

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

    RSI indicator from TC2000

    Looking for how to code an indicator I currently have on TC2000. The indicator checks the RSI14 against the RSI14 from 3 bars ago, making sure there was a crossover and that the current value is less than 30..

    In TC2000 the implementation is :
    IIF( rsi14>=rsi14.3 and rsi14.1.1<rsi14.3.1 and rsi14<30 , 100, 0)

    This will print a bar where the condition happens, otherwise is blank.

    Any easy way to code this in NinjaTrader? Appreciate your help

    #2
    Hello axjurado,

    Welcome to the NinjaTrader forums!

    Below is a link to a forum post with helpful resources on getting started with NinjaScript and C#.

    Please watch the training videos 'Automate Your Trading with NinjaTrader's Strategy Builder' and 'NinjaScript Editor 401'.



    Then after watching the videos try generating this code using the Strategy Builder. Select Indicator -> RSI and set the Bars Ago to 3.

    Then click View Code to view the generated code.

    Below are links to the help guide on how Series work, as well as the RSI.



    The code to compare the RSI from 3 bars ago would appear as:

    if (CurrentBar > 3)
    {
    if ( RSI(14)[0] >= RSI(14)[3] )
    {
    }
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      thanks but still having problems.

      I took the RSI code and modified as follows:

      added:
      AddPlot(new Stroke(Brushes.Lime, 100), PlotStyle.Bar, "RSI_sginal");

      if ( (RSI(14,3)[0] >=Avg[0]) && (RSI(14,3)[1] < Avg[1]) && (RSI(14,3)[0] < 30) )
      {
      RSI_signal[0] = 100;
      }

      [Browsable(false)]
      [XmlIgnore]
      public Series<double> RSI_signal
      {
      get { return Values[0]; }
      }​

      But it is not plotting anything on the RIS graph panel. Any clue as of what is wrong here?​
      Last edited by axjurado; 01-12-2023, 08:19 PM.

      Comment


        #4
        Hi axjurado,

        Try this:

        RSI1= RSI(Close, 14, 3);

        if ( (RSI1.Default[0] >= (RSI1.Avg[0]) && (RSI1.Default[1] < (RSI1.Avg[1]) && (RSI1.Default[0] < 30) )
        {
        RSI_signal[0] = 100;
        }​
        Last edited by KonstantinosNT; 01-13-2023, 01:57 AM.

        Comment


          #5
          Hello axjurado,

          Is there an error appearing on the Log tab of the Control Center?

          Note, in the code sample I have provided, there is a check that CurrentBar is greater than 3 before allowing a barsAgo index of [3] to be used.

          I see that you have RSI(14,3)[1] in the condition. May I confirm there is a check that CurrentBar is greater than 1 before this to ensure there are at least 2 bars so that you can look back 1 bar?
          https://ninjatrader.com/support/foru...13#post1048513

          Next, what is the Avg[0] series? Is this a custom series you have added, or were you intending to use the RSI(14, 3).Avg[0] plot series that is part of the RSI?
          https://ninjatrader.com/support/help..._index_rsi.htm

          Last, how do you know this condition is evaluating as true? The plot value will only be assigned for this bar if the condition evaluates as true. The plot will only be visual if there are two bars in a row with a value assigned.

          Add prints to understand the behavior. Print the time of the bar, print the values used in the condition with labels for each value and comparison operator.
          Below is a link to a forum post that demonstrates using prints to understand behavior.
          https://ninjatrader.com/support/foru...121#post791121
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thanks Chelsea. LEt me explain exactly what i need....

            What i want is to take the 2 lines from the RSI and check if there is crossover of the 2 lines while the gold line to be below 30.

            I took the RSI code as is and created my new indicator form it. Looking into the code, the 2 lines that draw the blue and golden lines are:
            AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meRSI);
            AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.NinjaScriptIndicatorAv g);​

            That is where the Avg came from.

            What would be the right comparison to find the cross form both values while the gold line is under 30?

            creating my RSI_signal series will accomplish taht. put 1 or 100 if true otherwise is 0. Then how do you plot just that bar?

            I'd appreciate your help. I am new to ninja programming is a bit of a hassle tbh. Thanks
            Last edited by axjurado; 01-13-2023, 11:23 AM.

            Comment


              #7
              Hello axjurado,

              Indicator plots are properties of the indicator object.

              You would need to use RSI(14, 3).Avg[0] instead of Avg[0] if you want the plot that comes from the indicator.

              "What would be the right comparison to find the cross form both values while the gold line is under 30?"

              What do you mean by "the cross form both values"?
              Do you mean the RSI(14, 3) default plot (the RSI plot) is crossing above the RSI(14, 3).Avg plot?

              if ( CrossAbove( RSI(14, 3), RSI(14, 3).Avg, 1) )

              What you mean by "the gold line"?
              Do you mean the RSI(14,3).Avg plot?

              if ( RSI(14, 3).Avg[0] < 30 )

              "Then how do you plot just that bar?"

              Add a plot with AddPlot().

              Set the Value[0] to the value you want the plot to have for that bar.

              Value[0] = 100;

              I'm trying to expose my variables to the strategy builder so everyone can have better use of the WaveTrend indicator (it has a lot of code). Explain this to me like I am 5 because this isnt the first time I've tried to figure it out and hit a wall. What is Series? I know its like an array that stores bars. Why not just call it


              Below is a link to a forum post with helpful resources on getting started with C# and NinjaScript.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thanks. I think i implemented it but nothing is showing.

                Here is the OnStateChange code. I added the parts in bold.

                if (State == State.SetDefaults)
                {
                Description = @"Bottom finder";
                Name = "RSIBottom";
                IsSuspendedWhileInactive = true;
                BarsRequiredToPlot = 20;
                Period = 14;
                Smooth = 3;

                AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meRSI);
                AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.NinjaScriptIndicatorAv g);
                AddPlot(new Stroke(Brushes.Lime, 2), PlotStyle.Bar, "RSI_signal");

                AddLine(Brushes.DarkCyan, 30, NinjaTrader.Custom.Resource.NinjaScriptIndicatorLo wer);
                AddLine(Brushes.DarkCyan, 70, NinjaTrader.Custom.Resource.NinjaScriptIndicatorUp per);
                }​


                in the onbarupdate section i have this. The part I added is in bold as well.
                else
                {
                // Rest of averages are smoothed
                avgDown[0] = (avgDown[1] * constant3 + down[0]) / Period;
                avgUp[0] = (avgUp[1] * constant3 + up[0]) / Period;

                if ( CrossAbove( RSI(14, 3), RSI(14, 3).Avg, 1) && RSI(14,3)[0]<30)
                {
                RSI_signal[0]=100;
                }


                }

                Also the def for the series:
                [Browsable(false)]
                [XmlIgnore]
                public Series<double> RSI_signal
                {
                get { return Values[0]; }
                }​


                And prints the RSI as is, but it does not print the bar. There should be 3 bars showing yesterday at the bottom of the drop ~9:50AM.

                Thanks for your help Chelsea.​

                Comment


                  #9
                  Hello axjurado,

                  Is the condition evaluating as true on two bars or more in a row?

                  Add prints to understand the behavior. Print the time of the bar, print the values used in the condition with labels for each value and comparison operator.

                  Below is a link to a forum post that demonstrates using prints to understand behavior.
                  https://ninjatrader.com/support/foru...121#post791121

                  Values[0] would be the first plot added with AddPlot(). This is using the resource dictionary for the string NinjaScriptIndicatorNameRSI, You have made your 3rd added plot bold using "RSI_signal" as the string, which would be Values[2], which is not being assigned any value. This means the plot would be a line and would be colored DodgerBlue. This plot will only be visible if there are two bars a in a row.

                  Were you intending to use Values[2] for the RSI_signal getter?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    thanks, that was the problem! appreciate your help

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    56 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    133 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    73 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    45 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    49 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X