I am working on an indicator that shows 2 plots on a tick chart (red and blue), and that works fine. I want to add a 15 minute dataseries to the indicator to get 2 more plots based on 15M (Magenta and green). After much trial and error I am now getting all 4 plots, but the 15MIN plot only for the last day and both Magenta and Green plots are broken in places, whilst the plots based on BarsArray[0] are fine - see image attached. Am I missing something in my coding for the plots?
#region Variables //Defines the DataSeries object private DataSeries myDataSeriesBear; private DataSeries myDataSeriesBull; private DataSeries myDataSeriesBear2nd; private DataSeries myDataSeriesBull2nd; #endregion protected override void Initialize() { Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "BslShortPeriodBear")); Add(new Plot(Color.FromKnownColor(KnownColor.DarkBlue), PlotStyle.Line, "BslShortPeriodBull")); Add(new Plot(Color.FromKnownColor(KnownColor.Magenta), PlotStyle.Line, "BslShortPeriodBear2nd")); Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "BslShortPeriodBull2nd")); // Add a 15 minute Bars object - Bars object index = 1, as the primary data the indicator is run against set by the UI takes the index of 0 Add(PeriodType.Minute, 15); // Create a new DataSeries object and assign it to the variable - for BarsArray[0] //myDataSeries declared in the ‘Variables’ region above - synced to the primary bars object myDataSeriesBear = new DataSeries(this); myDataSeriesBull = new DataSeries(this); } protected override void OnBarUpdate() { if (CurrentBar < minLookBackPeriod || CurrentBars[1] < minLookBackPeriod) return; int i = 0; /* Only need to sync DataSeries objects once. We couldn't do this sync in the Initialize() method because we cannot access the BarsArray property there. */ if (myDataSeriesBear2nd == null || myDataSeriesBull2nd == null) { /* Syncs another DataSeries object to the secondary bar object. We use an arbitrary indicator overloaded with an IDataSeries input to achieve the sync. The indicator can be any indicator. The DataSeries will be synced to whatever the BarsArray[] is provided.*/ myDataSeriesBear2nd = new DataSeries(SMA(BarsArray[1], 14)); myDataSeriesBull2nd = new DataSeries(SMA(BarsArray[1], 14)); } if (BarsInProgress == 0) { /* To set calculated values to our DataSeries we use the Set() method.*/ myDataSeriesBear.Set(Math.Round(bearVolPerTick / bullVolPerTick, 2)/Period); myDataSeriesBull.Set(Math.Round(bullVolPerTick / bearVolPerTick, 2)/Period); /* Plotting the SMA of the intermediate calculation step stored in DataSeries object*/ BslShortPeriodBear.Set(SUM(myDataSeriesBear, Period)[0]); BslShortPeriodBull.Set(SUM(myDataSeriesBull, Period)[0]); } if (BarsInProgress == 1) { myDataSeriesBear2nd.Set(Math.Round(bearVolPerTick / bullVolPerTick, 2)/Period); myDataSeriesBull2nd.Set(Math.Round(bullVolPerTick / bearVolPerTick, 2)/Period); BslShortPeriodBear2nd.Set(SUM(myDataSeriesBear2nd, Period)[0]); BslShortPeriodBull2nd.Set(SUM(myDataSeriesBull2nd, Period)[0]); } }
Comment