I am an absolute newbie in trying to put strategies together.
I have spent the last 2 months trying to get up to speed enough to put a few ideas into some basic strategies, which have been a success. This is my first try at a little more complicated strategy using volumetric bar and data. I looked on your site about the code needed for these bars, which I placed in my code below. Then I put a few if statements together to execute orders if both volume and delta get to certain levels.
When I run this in playback mode, I get no trades even though a number of bars on multiple days hit my criteria. I have tried to problem solve by going backwards and minimizing the coe, but still have no success. I feel like its something super basic which I am just not seeing.
Any help or guidance you may be able to give me would be great. Thank you so much in advance for your help
Below is my code.
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Calculate = Calculate.OnBarClose;
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 = 1;
TraceOrders =true;
IsInstantiatedOnEachOptimizationIteration = true;
Quantity = 1;
SellStop = 16;
TargetPrice = 80;
VolumeThreshold = 10000;
PositiveDeltaThreshold = 800;
NegativeDeltaThreshold = -800;
}
else if (State == State.Configure)
{
SetStopLoss(@"Long", CalculationMode.Ticks, SellStop, false);
SetStopLoss(@"Short", CalculationMode.Ticks, SellStop, false);
SetProfitTarget(@"Long", CalculationMode.Ticks, TargetPrice);
SetProfitTarget(@"Short", CalculationMode.Ticks, TargetPrice);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as
NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
if (barsType == null)
return;
try
{
double VWAPValue = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.String2TradingHours("CME US Index Futures RTH"), VWAPStandardDeviations.Three, 1, 2, 3).VWAP[0];
double price;
Print("=========================================== ==============================");
Print("Bar: " + CurrentBar);
Print("Trades: " + barsType.Volumes[CurrentBar].Trades);
Print("Total Volume: " + barsType.Volumes[CurrentBar].TotalVolume);
Print("Total Buying Volume: " + barsType.Volumes[CurrentBar].TotalBuyingVolume);
Print("Total Selling Volume: " + barsType.Volumes[CurrentBar].TotalSellingVolume);
Print("Delta for bar: " + barsType.Volumes[CurrentBar].BarDelta);
Print("Delta for bar (%): " + barsType.Volumes[CurrentBar].GetDeltaPercent());
Print("Delta for Close: " + barsType.Volumes[CurrentBar].GetDeltaForPrice(Close[0]));
Print("Ask for Close: " + barsType.Volumes[CurrentBar].GetAskVolumeForPrice(Close[0]));
Print("Bid for Close: " + barsType.Volumes[CurrentBar].GetBidVolumeForPrice(Close[0]));
Print("Volume for Close: " + barsType.Volumes[CurrentBar].GetTotalVolumeForPrice(Close[0]));
Print("Maximum Ask: " + barsType.Volumes[CurrentBar].GetMaximumVolume(true, out price) + " at price: " + price);
Print("Maximum Bid: " + barsType.Volumes[CurrentBar].GetMaximumVolume(false, out price) + " at price: " + price);
Print("Maximum Combined: " + barsType.Volumes[CurrentBar].GetMaximumVolume(null, out price) + " at price: " + price);
Print("Maximum Positive Delta: " + barsType.Volumes[CurrentBar].GetMaximumPositiveDelta());
Print("Maximum Negative Delta: " + barsType.Volumes[CurrentBar].GetMaximumNegativeDelta());
Print("Max seen delta (bar): " + barsType.Volumes[CurrentBar].MaxSeenDelta);
Print("Min seen delta (bar): " + barsType.Volumes[CurrentBar].MinSeenDelta);
Print("Cumulative delta (bar): " + barsType.Volumes[CurrentBar].CumulativeDelta);
Print("Delta Since High (bar): " + barsType.Volumes[CurrentBar].DeltaSh);
Print("Delta Since Low (bar): " + barsType.Volumes[CurrentBar].DeltaSl);
if (barsType.Volumes[CurrentBar].TotalVolume > VolumeThreshold && barsType.Volumes[CurrentBar].BarDelta > PositiveDeltaThreshold && Close[0] > Open[0] && Position.MarketPosition == MarketPosition.Flat)
EnterLong(Convert.ToInt32(Quantity), @"Long");
if (barsType.Volumes[CurrentBar].TotalVolume > VolumeThreshold && barsType.Volumes[CurrentBar].BarDelta < NegativeDeltaThreshold && Close[0] < Open[0] && Position.MarketPosition == MarketPosition.Flat)
EnterShort(Convert.ToInt32(Quantity), @"Short");
}
catch (Exception e) {
Print ("Something has gone wrong." + e.ToString());
}
Comment