The documentation on OrderFlowCumulativeDelta is great but I'm having trouble applying it when I'm working with multiple instruments.
The strategy I'm working on seeks to measure delta bias on an instrument separate from the primary series and then take action on the primary series. I'm confused on what BarsArray to update to and where to put the measurement logic.
Here's the excerpt that highlights the concept:
public class CDmultipleInstrument : Strategy { private OrderFlowCumulativeDelta OrderFlowCumulativeDelta1; private string Instrument1; private int deltaBiasInstrument1; protected override void OnStateChange() { if (State == State.SetDefaults) { Instrument1 = "..."; deltaBiasInstrument1 = 0; } else if (State == State.Configure) { AddDataSeries(Data.BarsPeriodType.Tick, 1); // BarsArray[1] - to execute orders on primary series AddDataSeries(Instrument1, Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last); // BarsArray[2] - to drive cumulative delta indiactor on Instrument 1 AddDataSeries(Instrument1, Data.BarsPeriodType.Second, 10, Data.MarketDataType.Last); // BarsArray[3] - to measure cumulative delta on Instrument 1 } else if (State == State.DataLoaded) { OrderFlowCumulativeDelta1 = OrderFlowCumulativeDelta(BarsArray[3],CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar,0); } } protected override void OnBarUpdate() { if ( CurrentBars[0] <= BarsRequiredToTrade || CurrentBars[1] <= BarsRequiredToTrade || CurrentBars[2] <= BarsRequiredToTrade || CurrentBars[3] <= BarsRequiredToTrade ) return; if (BarsInProgress == 0) // Primary series -- could be 10 second, UniRenko, or other bar type { if ( deltaBiasInstrument1 > 0 ) { BackBrushes[1] = Brushes.Green; } else if ( deltaBiasInstrument1 < 0 ) { BackBrushes[1] = Brushes.Red; } } if (BarsInProgress == 1) // Primary series 1 tick { } if (BarsInProgress == 2) // Instrument1 1 tick { // Sync Instrument1 cumulative delta indicators to primary series // First argument = primary series? // Second argument = 1 tick driver of the specific cumulative delta indicator? OrderFlowCumulativeDelta1.Update(0, 2); } if (BarsInProgress == 3) // Instrument1 10 second // Put delta measurement logic here? { if ( OrderFlowCumulativeDelta1.DeltaClose[1] > 0 ) { deltaBiasInstrument1 = 1; } else if ( OrderFlowCumulativeDelta1.DeltaClose[1] < 0 ) { deltaBiasInstrument1 = -1; } else { deltaBiasInstrument1 = 0; } } }
Am I synching the bars correctly with the Update() method? Is the delta logic on the secondary series in the right place?
Many thanks!
Comment