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 crossing 50 line does not give me arrows

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

    RSI crossing 50 line does not give me arrows

    OK, what am I doing wrong on this one?
    I just want the indicator to give an arrow up or down as RSI crosses the 50 midline.
    It plots OK, but no arrows.
    I got the arrow conditions piece from strategy wizard.
    The only code difference in the RSI indicator itself is I eliminated plotting the Avg line and overbot/oversold lines. so all I draw is RSI and the 50 midline.
    HTML Code:
    #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>
    /// The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg 
    /// </summary>
    [Description("The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg ")]
    public class RSImine1 : Indicator
    {
    #region Variables
    // Wizard generated variables
    private int RSI = 14; // Default setting for MyInput0
     
    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.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "RSI"));
    Add(new Line(System.Drawing.Color.DarkViolet, 50, "Mid"));
    CalculateOnBarClose = false;
    avgUp = new DataSeries(this);
    avgDown = new DataSeries(this);
    down = new DataSeries(this);
    up = new DataSeries(this);
    PriceTypeSupported = true;
    } 
    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (CurrentBar == 0)
    {
    down.Set(0);
    up.Set(0);
    return;
    }
    down.Set(Math.Max(Input[1] - Input[0], 0));
    up.Set(Math.Max(Input[0] - Input[1], 0));
    if ((CurrentBar + 1) < RSI)
    {
    if ((CurrentBar + 1) == (RSI - 1))
    // Avg.Set(50);
    return;
    }
    if ((CurrentBar + 1) == RSI) 
    {
    // First averages 
    avgDown.Set(SMA(down, RSI)[0]);
    avgUp.Set(SMA(up, RSI)[0]);
    } 
    else 
    {
    // Rest of averages are smoothed
    avgDown.Set((avgDown[1] * (RSI - 1) + down[0]) / RSI);
    avgUp.Set((avgUp[1] * (RSI - 1) + up[0]) /RSI);
    }
    double rs = avgUp[0] / (avgDown[0] == 0 ? 1 : avgDown[0]);
    double rsi = 100 - (100 / (1 + rs));
    //double rsiAvg = (2.0 / (1 + Smooth)) * rsi + (1 - (2.0 / (1 + Smooth))) * Avg[1];
    //Avg.Set(rsiAvg);
    Value.Set(rsi);
     
    //**********************
    // Condition set 1
    if (CrossAbove(RSImine(14).Plot0, 50, 1))
    {
    DrawArrowUp("My up arrow" + CurrentBar, false, 0, 0, Color.Lime);
    }
    // Condition set 2
    if (CrossBelow(RSImine(14).Plot0, 50, 1))
    {
    DrawArrowDown("My down arrow" + CurrentBar, false, 0, 0, Color.Red);
    }
    //*************************************
    }
     
    #region Properties
    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries Plot0
    {
    get { return Values[0]; }
    }
    [Description("")]
    [Category("Parameters")]
    public int MyInput0
    {
    get { return RSI; }
    set { RSI = Math.Max(1, value); }
    }
    #endregion
    }
    }
    #region NinjaScript generated code. Neither change nor remove.
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    public partial class Indicator : IndicatorBase
    {
    private RSImine1[] cacheRSImine1 = null;
    private static RSImine1 checkRSImine1 = new RSImine1();
    /// <summary>
    /// The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg 
    /// </summary>
    /// <returns></returns>
    public RSImine1 RSImine1(int myInput0)
    {
    return RSImine1(Input, myInput0);
    }
    /// <summary>
    /// The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg 
    /// </summary>
    /// <returns></returns>
    public RSImine1 RSImine1(Data.IDataSeries input, int myInput0)
    {
    checkRSImine1.MyInput0 = myInput0;
    myInput0 = checkRSImine1.MyInput0;
    if (cacheRSImine1 != null)
    for (int idx = 0; idx < cacheRSImine1.Length; idx++)
    if (cacheRSImine1[idx].MyInput0 == myInput0 && cacheRSImine1[idx].EqualsInput(input))
    return cacheRSImine1[idx];
    RSImine1 indicator = new RSImine1();
    indicator.BarsRequired = BarsRequired;
    indicator.CalculateOnBarClose = CalculateOnBarClose;
    indicator.Input = input;
    indicator.MyInput0 = myInput0;
    indicator.SetUp();
    RSImine1[] tmp = new RSImine1[cacheRSImine1 == null ? 1 : cacheRSImine1.Length + 1];
    if (cacheRSImine1 != null)
    cacheRSImine1.CopyTo(tmp, 0);
    tmp[tmp.Length - 1] = indicator;
    cacheRSImine1 = tmp;
    Indicators.Add(indicator);
    return indicator;
    }
    }
    }
    // This namespace holds all market analyzer column definitions and is required. Do not change it.
    namespace NinjaTrader.MarketAnalyzer
    {
    public partial class Column : ColumnBase
    {
    /// <summary>
    /// The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg 
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.RSImine1 RSImine1(int myInput0)
    {
    return _indicator.RSImine1(Input, myInput0);
    }
    /// <summary>
    /// The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg 
    /// </summary>
    /// <returns></returns>
    public Indicator.RSImine1 RSImine1(Data.IDataSeries input, int myInput0)
    {
    return _indicator.RSImine1(input, myInput0);
    }
    }
    }
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    public partial class Strategy : StrategyBase
    {
    /// <summary>
    /// The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg 
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.RSImine1 RSImine1(int myInput0)
    {
    return _indicator.RSImine1(Input, myInput0);
    }
    /// <summary>
    /// The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg 
    /// </summary>
    /// <returns></returns>
    public Indicator.RSImine1 RSImine1(Data.IDataSeries input, int myInput0)
    {
    if (InInitialize && input == null)
    throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
    return _indicator.RSImine1(input, myInput0);
    }
    }
    }
    #endregion

    #2
    Simpletrades, have you tried this with the standard RSI indicator? I noticed in your code that you're using a custom dataseries to determine a cross (if (CrossBelow(RSImine(14).Plot0, ...) and depending on the data (I don't see where RSImine is .Set), that could be throwing things off.

    Try adapting the following code to your situation:
    Code:
    if (CrossAbove(RSI(14, 1), 50, 1))
        DrawArrowUp("rsi up" + CurrentBar, false, 0, Low[0], Color.Green);
    else if (CrossBelow(RSI(14, 1), 50, 1))
        DrawArrowDown("rsi down" + CurrentBar, false, 0, High[0], Color.Red);
    Let us know if you have any other questions.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Austin View Post
      Simpletrades, have you tried this with the standard RSI indicator? I noticed in your code that you're using a custom dataseries to determine a cross (if (CrossBelow(RSImine(14).Plot0, ...) and depending on the data (I don't see where RSImine is .Set), that could be throwing things off.

      Try adapting the following code to your situation:
      Code:
      if (CrossAbove(RSI(14, 1), 50, 1))
          DrawArrowUp("rsi up" + CurrentBar, false, 0, Low[0], Color.Green);
      else if (CrossBelow(RSI(14, 1), 50, 1))
          DrawArrowDown("rsi down" + CurrentBar, false, 0, High[0], Color.Red);
      Let us know if you have any other questions.
      Thanks, it works, except I thought the arrows were going on my indicator itself not the candles.
      Is there a way to either move the arrows an 'input' distance above the high or below the low (since ES is .25 but FESX is 1.00 and EC is 4 decimals)?
      Also, I tried switching the word Diamond for Arrow in the phrase DrawArrowUp but it gave an error.

      Comment


        #4
        You can offset draw objects using TickSize, which is just a variable that stores the instrument's minimum price fluctuation.

        Just multiply TickSize by some integer and you'll get an object offset by that much. Hopefully this will answer your diamond question as well:
        Code:
        // DrawDiamond(string tag, bool autoScale, int barsAgo, double y, Color color)
        DrawDiamond("my diamond" + CurrentBar, false, 0, High[0] + 3 * TickSize, Color.Black);
        AustinNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Austin View Post
          You can offset draw objects using TickSize, which is just a variable that stores the instrument's minimum price fluctuation.

          Just multiply TickSize by some integer and you'll get an object offset by that much. Hopefully this will answer your diamond question as well:
          Code:
          // DrawDiamond(string tag, bool autoScale, int barsAgo, double y, Color color)
          DrawDiamond("my diamond" + CurrentBar, false, 0, High[0] + 3 * TickSize, Color.Black);
          Thanks but that looks really confusing--I did just learn how to switch ArrowUp to Diamond--I was leaving the word Up in so it was reading DiamondUp which doesnt work.

          I tried adding just this code below to Properties that I saw in another indicator, but was told showArrows does not exist in the current context. Turning the arrows off would be just as useful.

          [Description("Show Arrows")]
          [Category(
          "Plots")]
          publicbool ShowArrows
          {
          get { return showArrows; }
          set { showArrows = value; }
          }
          Last edited by simpletrades; 08-30-2009, 03:17 PM.

          Comment


            #6
            Originally posted by NinjaTrader_Austin View Post
            Try adapting the following code to your situation:
            Code:
            if (CrossAbove(RSI(14, 1), 50, 1))
                DrawArrowUp("rsi up" + CurrentBar, false, 0, Low[0], Color.Green);
            else if (CrossBelow(RSI(14, 1), 50, 1))
                DrawArrowDown("rsi down" + CurrentBar, false, 0, High[0], Color.Red);
            Let us know if you have any other questions.
            It worked on RSI and now I tried to make it work on my TwoEMACross which I wanted as an indicator but have only been able to make the 2 EMAs plot correctly using Close on one and Open for the other if I do a strategy. The indicator version wont allow Open and Close.

            As a strategy, I tried your RSI wording and it works perfectly--I still am ready to give up on the ticksize thing--does it replace part of the DrawDiamond(orArrowUp) wording you supplied or is it in addition to it?
            Either way, after weeks of bouncing at least the strategy works although I dont use it as such. I just want to see when the EMAs and RSI both cross close together. Also, frequent cross/recross yells out sideways movement even on a 1 min chart.

            But thanks for at least getting me this far.

            Comment


              #7
              Originally posted by simpletrades View Post
              It worked on RSI and now I tried to make it work on my TwoEMACross which I wanted as an indicator but have only been able to make the 2 EMAs plot correctly using Close on one and Open for the other if I do a strategy. The indicator version wont allow Open and Close.

              As a strategy, I tried your RSI wording and it works perfectly--I still am ready to give up on the ticksize thing--does it replace part of the DrawDiamond(orArrowUp) wording you supplied or is it in addition to it?
              Either way, after weeks of bouncing at least the strategy works although I dont use it as such. I just want to see when the EMAs and RSI both cross close together. Also, frequent cross/recross yells out sideways movement even on a 1 min chart.

              But thanks for at least getting me this far.
              Just switched live from demo and since i dont use the package upgrade for $180, i cant use a strategy period.
              Now I need to figure out why i could code the strategy to draw 2 different EMAs with different price types and the diamonds but not with my indicator version.

              Comment


                #8
                Using the TickSize offset is in addition to what Austin provided. You can offset the value the dots/arrows are plotted at by adding it to the Low or High value as in Austin's demo code.
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by algospoke, Yesterday, 06:40 PM
                2 responses
                24 views
                0 likes
                Last Post algospoke  
                Started by ghoul, Today, 06:02 PM
                3 responses
                15 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                46 views
                0 likes
                Last Post jeronymite  
                Started by Barry Milan, Yesterday, 10:35 PM
                7 responses
                23 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