I have a question.
I want to build an indicator composed of two equals moving averages, namely: SMA1 (28) [0] and SMA2 (28) [0]. But the second moving average has moved forward by 7 periods.
My code move forward both moving averages, not just one.
Someone can tell me where is the error?
Thank you for your help.
Germano
The code:
publicclass TwoEqualsSMA : Indicator
{
#region Variables
privateint period = 28; // Default setting for Period
privateint displace = 7; // Default setting for Displace
#endregion
protectedoverridevoid Initialize()
{
// 1° Moving average
Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Value_SMA1"));
// 2° Moving average
Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "Value_SMA2"));
Displacement = displace;
CalculateOnBarClose = true;
Overlay = true;
}
protectedoverridevoid OnBarUpdate()
{
Value_SMA1.Set(SMA(period )[0]);
Value_SMA2.Set(SMA(period )[0]);
}
Comment