// Indicator: Daily Direction Bias Analyzer (Final - Order Flow VWAP Corrected for NinjaTrader 8)
using System;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Tools;
using NinjaTrader.NinjaScript;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.OrderFlow; // Correct namespace for OrderFlowVWAP
using NinjaTrader.NinjaScript.DrawingTools;
using System.Windows.Media;
namespace NinjaTrader.NinjaScript.Indicators
{
public class DailyDirectionBiasIndicator : Indicator
{
private EMA ema9, ema21, ema50, ema200;
private OrderFlowVWAP vwap;
private MACD macd;
private double preMarketHigh = 0;
private double preMarketLow = double.MaxValue;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Displays daily directional bias (Bullish/Bearish) based on trend, VWAP, MACD, and pre-market breakout.";
Name = "DailyDirectionBiasIndicator";
IsOverlay = true;
Calculate = Calculate.OnBarClose;
}
else if (State == State.DataLoaded)
{
ema9 = EMA(9);
ema21 = EMA(21);
ema50 = EMA(50);
ema200 = EMA(200);
macd = MACD(12, 26, 9);
vwap = OrderFlowVWAP(); // Correct instantiation
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 50)
return;
// Pre-market high/low from 8:30 to 9:29 EST
if (ToTime(Time[0]) >= 83000 && ToTime(Time[0]) <= 92900)
{
preMarketHigh = Math.Max(preMarketHigh, High[0]);
preMarketLow = Math.Min(preMarketLow, Low[0]);
}
// EMA alignment
bool emaStackBullish = ema9[0] > ema21[0] && ema21[0] > ema50[0];
bool emaStackBearish = ema9[0] < ema21[0] && ema21[0] < ema50[0];
// VWAP position
bool priceAboveVWAP = Close[0] > vwap.VWAP[0];
bool priceBelowVWAP = Close[0] < vwap.VWAP[0];
// MACD direction
bool macdBullish = macd.Diff[0] > 0 && macd.Diff[0] > macd.Diff[1];
bool macdBearish = macd.Diff[0] < 0 && macd.Diff[0] < macd.Diff[1];
// Signal logic
if (emaStackBullish && priceAboveVWAP && macdBullish && Close[0] > preMarketHigh)
{
Draw.Text(this, "BullBias" + CurrentBar, " BULLISH BIAS", 0, High[0] + TickSize * 10, Brushes.LimeGreen);
&nbs; }
else if (emaStackBearish && priceBelowVWAP && macdBearish && Close[0] < preMarketLow)
{
Draw.Text(this, "BearBias" + CurrentBar, " BEARISH BIAS", 0, Low[0] - TickSize * 10, Brushes.Red);
}
}
}
}

Comment