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
}
Comment