• 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

Relative Strength Plot

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

    Relative Strength Plot

    Hello,

    I have developed a relative strength indicator that plots the 5 day relative strength vs. the spy. I want to plot the 20 day on it also. How do I add the second plot for the 20 day relative strength on the same pane as the 5 day relative strength ?

    public class relativestrength : Indicator
    {
    #region Variables
    int period =5; // this is for the 5 day relative strength. For the 20 day, it would be 20
    private DataSeries RelStr;
    double rs =0;
    #endregion

    protected override void Initialize()
    {
    Add("SPY", PeriodType.Day, 1);
    Overlay = false;

    // adding a 0 line. when the plot is above this line, stock is stronger than spy for the //specified period. When the plot is below this line, stock is weaker than the spy for the //specified period (eg 5 day -20 day etc.)
    Add(new Line(Color.FromKnownColor(KnownColor.DarkOliveGree n), 0, "Zero"));

    RelStr= new DataSeries(this);
    CalculateOnBarClose=true;


    }

    protected override void OnBarUpdate()
    {

    if (CurrentBar <period){return;}
    if(BarsInProgress==0)
    {

    // this is the relative strength formula
    rs = ((Close[0]/Closes[1][0])-(Close[period]/Closes[1][period]))/(Close[period]/Closes[1][period]);

    RelStr.Set(rs);
    Value.Set(SMA(RelStr,3)[0]);
    }

    }

    #region Properties

    [Description("Numbers of bars used for calculations")]
    [GridCategory("Parameters")]
    public int Period
    {
    get { return period; }
    set { period = Math.Max(1, value); }
    }
    #endregion
    }
    Last edited by russ123; 06-17-2016, 02:13 PM. Reason: added comments

    #2
    Hello russ123, and thank you for your question.

    I am including a link to the Help Guide section on working with multiple time frames (as is your case) and instruments.

    http://ninjatrader.com/support/helpG...2Btime%2Bframe

    When you add your 20 day time series, I would recommend adding it like this :

    Add("SPY", PeriodType.Day, 20);

    I would add a Plot for relative strength (which will plot in the same panel as your indicator), like this,

    Add(new Plot(Color.Orange, "RelativeStrength"));

    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Extending relative strength 5 to relative strength 5 and 20

      Any body know the code to add to this indicator to allow for both plots - relative strength 5 and relative strength 20. Appreciate the feedback.

      Comment


        #4
        Hello russ123,

        Can I ask, what was the result when you added the two lines of code I sent you to your initialize routine? If you can provide us with a stripped down version of your code I would be happy to return you a tested copy with that code added, which will allow both data series to plot in the same panel.
        Jessica P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by mreanuzlazx, Today, 01:30 AM
        0 responses
        1 view
        0 likes
        Last Post mreanuzlazx  
        Started by xinepev, Today, 12:33 AM
        0 responses
        4 views
        0 likes
        Last Post xinepev
        by xinepev
         
        Started by sun0781, Yesterday, 05:02 PM
        0 responses
        7 views
        0 likes
        Last Post sun0781
        by sun0781
         
        Started by ronhb107, 09-12-2019, 10:09 AM
        4 responses
        44 views
        0 likes
        Last Post Mr.Trader  
        Started by rwilliam, Yesterday, 03:55 PM
        0 responses
        4 views
        0 likes
        Last Post rwilliam  
        Working...
        X