picture left NQ in 2 minutes timeframe and right NQ in 4 tick unirenko, the script runs on the unirenko 4 tick chart. after a while in the unirenko 4 tick chart the lines are not displayed correctly. everything should always look the same as on the left side of the 2 minute chart. of course the lines are not exactly the same in both charts, because on the left is the 2 minute timeframe and on the right the 4 tick unirenko chart. it seems that the line is calculated correctly on 2 minutes, but is drawn too fast in the 4 tick chart. i've marked it in yellow on the image where it's out of sync.
When I reload the script with F12, the line is displayed correctly and synchronously on both charts again, for some time. the goal is to have a line on the 4 tick unirenko chart that is calculated from the 2 minute timeframe and also drawn synchronously as in the 2 minute chart. please look at the pictures, the first image is before reloading the script with F12 and the second image after.
Can anyone help me with this, please?
public class RenkoTrend : Strategy
{
private double atrtrailHTF;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Calculate = Calculate.OnEachTick;
ATRPeriodHTF = 7;
MultiplikatorHTF = 2.3;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 2)
}
protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[2] < 1 || CurrentBars[3] < 1)
return;
double atrlossHTF = ATR(Closes[3], ATRPeriodHTF)[0] * MultiplikatorHTF;
if (Closes[3][0] > ATRTrendHTF[1] && Closes[3][1] > ATRTrendHTF[1])
atrtrailHTF = Math.Max(ATRTrendHTF[1], Closes[3][0] - atrlossHTF);
else if (Closes[3][0] < ATRTrendHTF[1] && Closes[3][1] < ATRTrendHTF[1])
atrtrailHTF = Math.Min(ATRTrendHTF[1], Closes[3][0] + atrlossHTF);
else if (Closes[3][0] > ATRTrendHTF[1])
{
atrtrailHTF = Closes[3][0] - atrlossHTF;
}
else
{
atrtrailHTF = Closes[3][0] + atrlossHTF;
}
if (showATRTrendHTF)
{
ATRTrendHTF[0] = atrtrailHTF;
}
}
#region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="ATRPeriod", Description="ATR Period", Order=19, GroupName="2. Indikatoren")]
public int ATRPeriod
{ get; set; }
[NinjaScriptProperty]
[Range(1, double.MaxValue)]
[Display(Name="Multiplikator", Description="ATR multiplication", Order=20, GroupName="2. Indikatoren")]
public double Multiplikator
{ get; set; }
[Browsable(false)]
[XmlIgnore]
public Series<double> ATRTrendHTF
{
get { return Values[4]; }
}
#endregion
}
}
Comment