I am trying to add a custom indicator to a strategy and pass it some parameters derived from the strategy
Unfortunately, when I run a print to Output of the value that the Indicator is receiving, the only value i get is 1.
What am I doing wrong?
Thanks.
Strategy:-
double param1;
double param2;
protected override void Initialize()
{
setParameters();
Add(MyIndicator( param1, param2));
}
setParameters()
{
param1 = 0.9;
param2 = 0.4;
}
Indicator:-
public class MyIndicator : Indicator
{
#region Variables
// Wizard generated variables
private double param1 = 0.5; // Default setting for param1
private double param2 = 0.5; // Default setting for param2
// User defined variables (add any user defined variables below)
double val;
double lastDailyClose = 0.0;
double LongStopIn;
double ShortStopIn;
#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.Green), PlotStyle.Line, "LongEntry"));
Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "ShortEntry"));
Overlay = true;
Add(PeriodType.Day, 1);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// 3 Days lookback
if (CurrentBar < 4200) //700
return;
// OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
// We only want to process events on our primary Bars object (main instrument) (index = 0) which
// is set when adding the strategy to a chart
if (BarsInProgress != 0)
return;
if (Bars.FirstBarOfSession)
{
val= calcVal();
lastDailyClose = Closes[1][0];
LongStopIn = lastDailyClose + (val*longStopEntry);
ShortStopIn = lastDailyClose - (val*shortStopEntry);
// Only ever see value 1.........
string str = "INDICATOR------longStopEntry=" + longStopEntry;
Print(str);
str = "INDICATOR-------shortStopEntry=" + shortStopEntry;
Print(str);
}
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
LongEntry.Set(LongStopIn);
ShortEntry.Set(ShortStopIn);
}
Comment