I have created a simple strategy to test the instansiatin of a custom Indicator I have created.
But there seems to be something wrong. Both indicators are added to the chart but with the same values eventhough they are different in the code. Also as the plot color of one of the indicators are changed it also changes the other. I need some help to figure out what is wrong here.
namespace NinjaTrader.NinjaScript.Strategies._own { public class VWAPBounce : Strategy { private VWAP_Attach vwapDay; private VWAP_Attach vwapWeek; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Strategy here."; Name = "VWAPBounce"; Calculate = Calculate.OnPriceChange; 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) { } else if(State == State.DataLoaded) { vwapDay = VWAP_Attach(Close); vwapDay.AttachDate = DateTime.Now; vwapDay.AttachTime = new TimeSpan(00,00,00); vwapWeek = VWAP_Attach(Close); vwapWeek.AttachDate = StartOfWeek(DateTime.Now, DayOfWeek.Monday); vwapWeek.AttachTime = new TimeSpan(00,00,00); vwapDay.Plots[0].Brush = Brushes.AliceBlue; AddChartIndicator(vwapDay); AddChartIndicator(vwapWeek); } } protected override void OnBarUpdate() { //Add your custom strategy logic here. } public DateTime StartOfWeek(DateTime dt, DayOfWeek startOfWeek) { int diff = (7 + (dt.DayOfWeek - startOfWeek)) % 7; return dt.AddDays(-1 * diff).Date; } } }
Sune
Comment