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

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.



    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 Jimmyk, 01-26-2018, 05:19 AM
        6 responses
        835 views
        0 likes
        Last Post emuns
        by emuns
         
        Started by jxs_xrj, 01-12-2020, 09:49 AM
        6 responses
        3,291 views
        1 like
        Last Post jgualdronc  
        Started by Touch-Ups, Today, 10:36 AM
        0 responses
        10 views
        0 likes
        Last Post Touch-Ups  
        Started by geddyisodin, 04-25-2024, 05:20 AM
        11 responses
        62 views
        0 likes
        Last Post halgo_boulder  
        Started by Option Whisperer, Today, 09:55 AM
        0 responses
        8 views
        0 likes
        Last Post Option Whisperer  
        Working...
        X