I have an issue again with the 1st tick indicator development
I am trying to replicate the EMA indicator so it can only calculate on the 1st tick but I am have significant difference between the result. It seems a little much that I have to recode all the indicators so I can be used with a strategy the works on eachticks
any idea why we have this behavior ?
Thank you
Here the code of the modified indicator
namespace NinjaTrader.NinjaScript.Indicators
{
public class EMAFroceonbarclose : Indicator
{ private double constant1;
private double constant2;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionEMA;
Name = "EMAFroceonbarclose";
IsOverlay = true;
IsSuspendedWhileInactive = true;
Period = 14;
AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameEMA);
}
else if (State == State.Configure)
{
constant1 = 2.0 / (1 + Period);
constant2 = 1 - (2.0 / (1 + Period));
}
}
protected override void OnBarUpdate()
{
if (CurrentBar == 0)
Value[0] = Input[0];
if (CurrentBar < 2)
return;
if (IsFirstTickOfBar)
{
Value[0] = (CurrentBar == 0 ? Input[1] : Input[1] * constant1 + constant2 * Value[2]);
}
else
Value[0] = Value[1];
}
#region Properties
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
public int Period
{ get; set; }
#endregion
}
}

Comment