• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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

                    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 morrnel, Today, 01:13 PM
                      1 response
                      8 views
                      0 likes
                      Last Post NinjaTrader_Jim  
                      Started by babouin77, Today, 12:41 PM
                      6 responses
                      16 views
                      0 likes
                      Last Post babouin77  
                      Started by punkiy2111, Today, 12:17 PM
                      1 response
                      9 views
                      0 likes
                      Last Post NinjaTrader_Tabor  
                      Started by GLFX005, Today, 11:22 AM
                      7 responses
                      32 views
                      0 likes
                      Last Post GLFX005
                      by GLFX005
                       
                      Started by mintxom, Today, 10:25 AM
                      1 response
                      11 views
                      0 likes
                      Last Post NinjaTrader_Melissa  
                      Working...
                      X