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

Question about RSI and Candlestick Range

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

    Question about RSI and Candlestick Range

    Hi!

    I'm trying to make an indicator, it's like a WMA but i'm trying to give more weight to those candlesticks with the farthest RSI 50...

    I know it's a bit strange....

    Thank you!

    #2
    Pablo,

    Do you have a calculation method or example that you can share to help with this?
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Now I'm trying to put the RSI indicator with bars and I have a problem with the code that i don't understand...

      public class RSIBARS : Indicator
      {
      #region Variables
      private DataSeries avgUp;
      private DataSeries avgDown;
      private DataSeries down;
      private int period = 14;
      private int smooth = 3;
      private DataSeries up;
      #endregion

      /// <summary>
      /// This method is used to configure the indicator and is called once before any bar data is loaded.
      /// </summary>
      protected override void Initialize()
      {
      Add(new Plot(Color.Green,PlotStyle.Bar, "RSI"));
      Add(new Plot(Color.Orange, PlotStyle.Bar, "Avg"));

      Add(new Line(System.Drawing.Color.DarkViolet, 30, "Lower"));
      Add(new Line(System.Drawing.Color.YellowGreen, 70, "Upper"));

      avgUp = new DataSeries(this);
      avgDown = new DataSeries(this);
      down = new DataSeries(this);
      up = new DataSeries(this);

      The problem is in the 23 line

      The rest of the code it's exactly the same as the RSI of the ninja trader

      Comment


        #4
        Pablo,

        Which one is line 23?

        What is the problem that you are having?
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          private DataSeries avgUp

          the program doesn't tell me wich error is

          Comment


            #6
            Could you please attach the whole cs file for us to give it a run? Thanks,
            BertrandNinjaTrader Customer Service

            Comment


              #7
              #region Using declarations
              using System;
              using System.ComponentModel;
              using System.Diagnostics;
              using System.Drawing;
              using System.Drawing.Drawing2D;
              using System.Xml.Serialization;
              using NinjaTrader.Cbi;
              using NinjaTrader.Data;
              using NinjaTrader.Gui.Chart;
              #endregion

              // This namespace holds all indicators and is required. Do not change it.
              namespace NinjaTrader.Indicator
              {
              /// <summary>
              /// RSI con Barras
              /// </summary>
              [Description("RSI con Barras")]
              public class RSIBARS : Indicator
              {
              #region Variables
              private DataSeries avgUp;
              private DataSeries avgDown;
              private DataSeries down;
              private int period = 14;
              private int smooth = 3;
              private DataSeries up;
              #endregion

              /// <summary>
              /// This method is used to configure the indicator and is called once before any bar data is loaded.
              /// </summary>
              protected override void Initialize()
              {
              Add(new Plot(Color.Green,PlotStyle.Bar, "RSI"));
              Add(new Plot(Color.Orange, PlotStyle.Bar, "Avg"));

              Add(new Line(System.Drawing.Color.DarkViolet, 30, "Lower"));
              Add(new Line(System.Drawing.Color.YellowGreen, 70, "Upper"));

              avgUp = new DataSeries(this);
              avgDown = new DataSeries(this);
              down = new DataSeries(this);
              up = new DataSeries(this);
              }

              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate(){
              if (CurrentBar == 0)
              {
              down.Set(0);
              up.Set(0);

              if (Period < 3)
              Avg.Set(50);
              return;
              }

              down.Set(Math.Max(Input[1] - Input[0], 0));
              up.Set(Math.Max(Input[0] - Input[1], 0));

              if ((CurrentBar + 1) < Period)
              {
              if ((CurrentBar + 1) == (Period - 1))
              Avg.Set(50);
              return;
              }

              if ((CurrentBar + 1) == Period)
              {
              // First averages
              avgDown.Set(SMA(down, Period)[0]);
              avgUp.Set(SMA(up, Period)[0]);
              }
              else
              {
              // Rest of averages are smoothed
              avgDown.Set((avgDown[1] * (Period - 1) + down[0]) / Period);
              avgUp.Set((avgUp[1] * (Period - 1) + up[0]) / Period);
              }

              double rsi = avgDown[0] == 0 ? 100 : 100 - 100 / (1 + avgUp[0] / avgDown[0]);
              double rsiAvg = (2.0 / (1 + Smooth)) * rsi + (1 - (2.0 / (1 + Smooth))) * Avg[1];

              Avg.Set(rsiAvg);
              Value.Set(rsi);
              }

              #region Properties
              /// <summary>
              /// </summary>
              [Browsable(false)]
              [XmlIgnore()]
              public DataSeries Avg
              {
              get { return Values[1]; }
              }

              /// <summary>
              /// </summary>
              [Browsable(false)]
              [XmlIgnore()]
              public DataSeries Default
              {
              get { return Values[0]; }
              }

              /// <summary>
              /// </summary>
              [Description("Numbers of bars used for calculations")]
              [GridCategory("Parameters")]
              public int Period
              {
              get { return period; }
              set { period = Math.Max(1, value); }
              }

              /// <summary>
              /// </summary>
              [Description("Number of bars for smoothing")]
              [GridCategory("Parameters")]
              public int Smooth
              {
              get { return smooth; }
              set { smooth = Math.Max(1, value); }
              }
              #endregion

              }
              }

              Here it is!

              Comment


                #8
                Pablo,

                I'm not receiving a compile error for the script.

                Can you please explain more into what kind of error you are running into?

                Where do you see this error and when?
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  Is another way to insert an image that is only in my pc without a URL?

                  Another question... do you know how can i relate a candlestick with other values like Volume price or RSI
                  to make a WMA choosing the highest values ​​first and leaving last the lowest... for example if i'm making a WMA with 21 periods, I want to take first the candlestick with the highest range.

                  thank you again for all

                  Comment


                    #10
                    Hello Pablo GJ,

                    Thank you for your patience.

                    To add an image from your PC you will need to override the Plot() method and then use the DrawImage() method with Image.FromFile() for example:
                    Code:
                    		public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
                    		{
                    			graphics.DrawImage(Image.FromFile(@"C:\Users\yourUserNameForWindows\Desktop\imageName.jpg"),bounds.X, bounds.Y, bounds.Width, bounds.Height);
                    		}
                    For information on overriding the plot take a look at the CustomPlotSample under Tools > Edit NinjaScript > Indicator > CustomPlotSample.

                    For DrawImage please visit the following link: http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx

                    For your second item, can you provide further details on what you by "I want to take first the candlestick with the highest range"?
                    Are you referring to the highest volume bar within that 21 period?

                    Comment


                      #11
                      Ok I will try that for the image!
                      I will also try to make better that question... i'm not english and it's a bit difficult for me to express some things about this...

                      Thank you again for your help i'm very grateful!!

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by algospoke, Yesterday, 06:40 PM
                      2 responses
                      19 views
                      0 likes
                      Last Post algospoke  
                      Started by ghoul, Today, 06:02 PM
                      3 responses
                      14 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by jeronymite, 04-12-2024, 04:26 PM
                      3 responses
                      45 views
                      0 likes
                      Last Post jeronymite  
                      Started by Barry Milan, Yesterday, 10:35 PM
                      7 responses
                      21 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by AttiM, 02-14-2024, 05:20 PM
                      10 responses
                      181 views
                      0 likes
                      Last Post jeronymite  
                      Working...
                      X