https://ninjatrader.com/support/help...=orderflowvwap
For some reason, following the example in the link above, my output isn't matching what the indicator shows. It's off by nearly 2 points. Below is a simplified version of my code, which is basically what is in the example. I would appreciate any assistance.
protected override void OnStateChange() {
if (State == State.SetDefaults) {
Description = @"";
Name = "TradingBot";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = false;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = true;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.ImmediatelySubmit;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
IsInstantiatedOnEachOptimizationIteration = true;
} else if (State == State.Configure) {
AddDataSeries(Data.BarsPeriodType.Minute, 1);
AddDataSeries(Data.BarsPeriodType.Tick, 1);
}
}
protected override void OnBarUpdate() {
if(BarsInProgress == 0) {
if (IsFirstTickOfBar) {
double VWAPValue = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.String2TradingHours("CME US Index Futures RTH"), VWAPStandardDeviations.Three, 1, 2, 3).VWAP[0];
Print(VWAPValue);
}
}
if (BarsInProgress == 2) {
OrderFlowVWAP(BarsArray[0], VWAPResolution.Tick, BarsArray[0].TradingHours, VWAPStandardDeviations.Three, 1, 2, 3)
.Update(OrderFlowVWAP(BarsArray[0], VWAPResolution.Tick, BarsArray[0].TradingHours, VWAPStandardDeviations.Three, 1, 2, 3).BarsArray[1].Count - 1, 1);
}
}

Comment