I have created 2 indicators (A and B) which each have a DrawText line that send computations to my chart, and both work fine. I have attempted to bring them into a third indicator C, with the intention of deducting the calculations as follows (IndicatorA + IndicatorB). Indicator B is already a negative. I have compiled an indicator C, but am not sure how to go about achieving this computation and having it appear on the chart.
1. Do I need to do a new DrawText line in Indicator C to calculate and display A+B? Currently I don’t even see the original texts from A or B when I load C (is this because the indicator values are not a plot and so I have to do DrawText again in C).
2. The parameters in Indicators A and B do not show up in the properties for Indicator C when it is loaded. Is there a way for me to access them other than loading A and B?
I have copied the relevant sections of Indicators A to C below.
Thanks for the help.
IndicatorA – important sections:
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
private DataSeries myIndicatorA;
#endregion
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
Overlay = true;
CalculateOnBarClose = true;
//to set the input type when added to a chart. False means setting cannot be changed
PriceTypeSupported = false;
//Now create the objects that hold the data
myIndicatorA = new DataSeries(this);
}
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
if (CurrentBar == 0)
{
return;
}
{
DataSeries
// class is used to set the value of the current location, or bar.
myIndicatorA.Set(diffVol);
}
if ((Open[0] == Close[0]) && (Math.Abs(High[0] - Open[0]) > Math.Abs(Low[0] - Open[0]))
{
DrawText (TagdiffVol1 + CurrentBar, diffVol.ToString(), 0, Low[0] - 2 * TickSize, Color.Red);
}
IndicatorB:
public class IndicatorB : Indicator
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
// These will hold DataSeries variables that can be accessed by
// other indicators and strategies
private DataSeries myIndicatorB;
//A parameter/variable that could have been generated by the wizard
private string TagwTSum1 = "wTSum"; //The tag for the DrawText
#endregion
protected override void Initialize()
{
//This indicator only used to build other indicators and strategies
// so nothing placed on the price chart, so
Overlay = false;
// Indicator to update when the bar closes, so
CalculateOnBarClose = true;
//Now create the objects that hold the data, i.e.
// the DataSeries created under variables above
myIndicatorB = new DataSeries (this);
}
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each - need at least 2 bars for calculation
if (CurrentBar == 0)
{
return;
}
if (wTSum < 15)
{
DrawText (TagwTSum1 + CurrentBar, wTSum.ToString(), 0, High[0] + 1 * TickSize, Color.Black);
}
//Set the calculated values to the plots
myIndicatorB.Set (wTSum);
}
#region Properties
[Browsable(false)]
[XmlIgnore()]
public DataSeries MyIndicatorB
{
get {return myIndicatorB;}
}
#endregion
IndicatorC:
public class IndicatorC : Indicator
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
private DataSeries diffIndA;
private DataSeries changeIndB;
private DataSeries IndicatorA;
private DataSeries IndicatorB;
#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, "Plot0"));
Overlay = true;
//Now create the objects that hold the data
diffIndA = new DataSeries(this);
changeIndB = new DataSeries (this);
IndicatorA = new DataSeries (this);
IndicatorB = new DataSeries (this);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
DiffIndA.Set (IndicatorA[0]);
ChangeIndB.Set(IndicatorB[0]);
}
#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]; }
}
[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 DiffIndA
{
get {return diffIndA;}
}
[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 ChangeIndB
{
get {return changeIndB;}
}
#endregion
}
}
Comment