I'm working on a partial logic for a strategy or indicator and trying this in an isolated script first.
Basically I want to be able to compare the current cumulative delta close or low with the one from the previous bar in a primary data series and potentially then the previous with the one before that.
I read up on multiseries and cumulative data and got it somehow working for the current bar but I dont seem to manage to get the data for a .close[1] (assuming that is the "bar ago")
or the script will just refuse to apply to the chart.
The line in the script below: "D0 = cumulativeDelta.DeltaClose[0];" I thought is setting the delta close for the current bar to the variable D0.
Script works as expected.
As soon as I change the number in the brackets (which I thought is bars ago) the script refuses to apply.
If you could help me to get to the point where I can say "if the close of the delta of the delta is greater than the close of the delta from the previous bar..."
I would be very grateful for any pointers.
Thank you in advance!
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class testing : Strategy
{
private OrderFlowCumulativeDelta cumulativeDelta;
private double D0;
private double D1;
private double D2;
private double D3;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "testing";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
AddDataSeries("MNQ 06-22", Data.BarsPeriodType.Second, 15, Data.MarketDataType.Last);
AddDataSeries(Data.BarsPeriodType.Tick, 1);
}
else if (State == State.DataLoaded)
{
cumulativeDelta = OrderFlowCumulativeDelta(CumulativeDeltaType.BidAs k, CumulativeDeltaPeriod.Bar, 0);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress == 0)
{
D0 = cumulativeDelta.DeltaClose[0];
//Print("Delta Close: " + cumulativeDelta.DeltaClose[0]);
}
else if(BarsInProgress == 1)
{
cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count -1, 1);
}
// Set 1
if (D0 > 0)
{
BarBrush = Brushes.Yellow;
}
else if (D0 < 0)
{
BarBrush = Brushes.Turquoise;
}
}
}
}


Comment