• 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

  • russ123
    started a topic Relative Strength Plot

    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

  • NinjaTrader_JessicaP
    replied
    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.

    Leave a comment:


  • russ123
    replied
    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.

    Leave a comment:


  • NinjaTrader_JessicaP
    replied
    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.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by RandanAL, 09-21-2019, 09:05 AM
1 response
10 views
0 likes
Last Post NinjaTrader_ChrisSch  
Started by afoschini, Today, 02:57 AM
0 responses
1 view
0 likes
Last Post afoschini  
Started by Newtrader101, Yesterday, 06:31 PM
1 response
9 views
0 likes
Last Post NinjaTrader_EricB  
Started by Tyler7498, Yesterday, 07:34 PM
0 responses
4 views
0 likes
Last Post Tyler7498  
Started by Woomera, Yesterday, 07:24 PM
2 responses
10 views
0 likes
Last Post Woomera
by Woomera
 
Working...
X