Note I'm using NT 8.1.2.1, on Windows 11. I'm developing a strategy that uses 4 data series and a DoubleStoch indicator on each data series to calculate and decide entry points. I think I am following all of the rules for multiple timelines but the calculations do not match the visual indicators on the chart, which is what I'm trying to emulate. The four data series are a 125 Tick chart is the Entry/Base series. Then a 400 tick, 1200 tick, 3000 tick data series.
My code to add these are as follows in the OnStateChange method:
else if (State == State.Configure)
{
try
{
AddPerformanceMetric(new NinjaTrader.NinjaScript.PerformanceMetrics.SampleC umProfit());
SetProfitTarget("", CalculationMode.Ticks, TargetTicks);
SetStopLoss("", CalculationMode.Ticks, StopTicks, false);
} catch(Exception exception) {
MayPrint("Error occured in State Change - State.Configure. Error is: " + exception.ToString(), 0);
}
// Add AC1
AddDataSeries(BarsPeriodType.Tick, 400);
// Add AC3
AddDataSeries(BarsPeriodType.Tick, 1200);
// Add AC4
AddDataSeries(BarsPeriodType.Tick, 3000);
} else if (State == State.DataLoaded)
{
try
{
if(ChartBars == null)
{
MayPrint("Strategy was not loaded from a chart, exiting strategy...", 0);
return;
}
// Set the Dollars Per tick
DollarsPerTick = Instrument.MasterInstrument.PointValue * TickSize;
MasterInstrumentName = Instrument.MasterInstrument.Name;
mayVeryFastHMA = HMA(veryFastEMAPeriod);
EntryEMA = EMA(EntryEMAPeriod);
AC1EMA = EMA(AC1EMAPeriod);
mayDSEntry = MayDSv4(BarsArray[0], dpTmpEnum, 0.02, -0.02, 20, 4, 6, true, DSPeriod, true, false, true, true, 4, 0.3, 4);
AC1mayDS = MayDSv4(BarsArray[1], dpTmpEnum, 0.02, -0.02, 20, 4, 6, true, SecondDSPeriod, true, false, true, true, 4, 0.3, 8);
AC3mayDS = MayDSv4(BarsArray[2], dpTmpEnum, 0.02, -0.02, 20, 4, 6, true, SecondDSPeriod, true, false, true, true, 4, 0.3, 8);
AC4mayDS = MayDSv4(BarsArray[3], dpTmpEnum, 0.02, -0.02, 20, 4, 6, true, SecondDSPeriod, true, false, true, true, 4, 0.3, 8);
} catch(Exception exception) {
MayPrint("Error occured in State Change - State DataLoaded. Error is: " + exception.ToString(), 0);
}
The MayDSv4 is a fast DoubleStoch. The DS in question here is the 400 Tick DS, or the Yellow one on the chart. Note the two entries on the left. They are printing the values of each DS so I can easily see what the parameters were at the time of entry. The first one down is the 125, the second is the 400, etc. Note that on the two entries on the left, the values of the 400 are 92.929 AND this matches the visual of the DS indicator down below. This is good and I'm OK with that. However, on the entry on the right, the value says 90.497, but the visual says the value is less than 5.
This is where the issue is in the algorithm. If the calculation matched the visual then the algo would not have entered so I must be doing something wrong. Note that I am using OnBarUpdate and NOT OnTickUpdate.
The code at the beginning of the OnBarUpdate is as follows to keep the values of the DoubleStoch for each timeline so when it enters on the main series, I can do my calculations:
try
{
// Make sure we have enough bars to run this algo and that we shouldn't stop for other reasons.
if (((CurrentBars[0] < BarsRequiredToPlot) && (CurrentBars[1] < BarsRequiredToPlot) && (CurrentBars[2] < BarsRequiredToPlot) && (CurrentBars[3] < BarsRequiredToPlot)) || (StopMaxProfit == true) || (StopMaxLoss == true))
return;
if (BarsInProgress == 1)
AC1CurrVal = AC1mayDS.KMiddle[0];
if (BarsInProgress == 2)
AC3CurrVal = AC3mayDS.KMiddle[0];
if (BarsInProgress == 3)
AC4CurrVal = AC4mayDS.KMiddle[0];
//
// This is here so we only process the first bar for the on update. We only analyze where we are for the first bar and not the other Anchor charts
//
if (BarsInProgress != 0)
return;
So, I only do the calculations on the main series. I check all values and decide to enter long or short or nothing. I have attached an image so you can visualize what I am discussing better.
My main question is: Can you help me figure out what I am doing incorrectly with the calculations because the 400 DoubleStoch calculation should be less than 10 and not above 90?
Thank you for your assistance,
Steve

Comment