else if (State == State.Configure) { Calculate = Calculate.OnBarClose; AddDataSeries("YM 03-23", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last); AddDataSeries("YM 03-23", Data.BarsPeriodType.Second, 15, Data.MarketDataType.Last); AddDataSeries("YM 03-23", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last); AddDataSeries("YM 03-23", Data.BarsPeriodType.Volume, 1, Data.MarketDataType.Last); } else if (State == State.DataLoaded) { CumDelta1m = OrderFlowCumulativeDelta(BarsArray[1], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar, 0); CumDelta15s = OrderFlowCumulativeDelta(BarsArray[2], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar, 0); } protected override void OnBarUpdate() { // obtain current 1m bar timestamp DateTime currentBarTime = Bars.GetTime(Bars.Count-2); if (delta > 100 || delta < -100){ // check if current candle's volume is greather than 3 previous candles if(Volume[0] > Volume[1] && Volume[0] > Volume[2] && Volume[0] > Volume[3]){ double maxPrice = double.MinValue; double minPrice = double.MaxValue; DateTime futureTime = currentBarTime; DateTime correctTime = futureTime; int count = 3; bool found = false; for (int i = 0; i < 4; i++){ // we only take the first delta of 15s chart if(!found){ double delta15s = CumDelta15s.DeltaClose[0]; if (delta15s > 60 || delta15s < -60){ double highPrice = Highs[2][count]; double lowPrice = Lows[2][count]; // Update max and min price if necessary if (highPrice > maxPrice) maxPrice = highPrice; futureTime = futureTime.AddSeconds(15); // we save at correctTime variable the candle timestamp where the max is located correctTime = futureTime; if (lowPrice < minPrice) minPrice = lowPrice; //futureTime = futureTime.AddSeconds(15); correctTime = futureTime; found = true; } count--; //futureTime = futureTime.AddSeconds(15); } } // If a 15s candle with delta > 60 or delta < -60 was found, we save the variables on an array if (maxPrice != double.MinValue && minPrice != double.MaxValue){ // Save values to an array priceRange = new double[] { maxPrice, minPrice, -1}; Print(string.Format("{0} --> MAX price: {1}, MIN price: {2}", correctTime, priceRange[0], priceRange[1])); myCurrentBar = CurrentBar; // Tells when we have detected a new range just_after = true; } else{ // If no 15 seconds candles with delta > 60 or delta < -60 was found, we save the MAX and MIN value of the 1 min array double highPrice = BarsArray[1].GetHigh(0); // Get highest price of 1 min candle double lowPrice = BarsArray[1].GetLow(0); // Get lowest price of 1 min candle // Save LOW and High values into an array priceRange = new double[] {highPrice, lowPrice, -1}; Print(string.Format("{0} --> MAX price: {1}, MIN price: {2}", correctTime, priceRange[0], priceRange[1])); myCurrentBar = CurrentBar; just_after = true; } } }
How can that be implemented following my code?
Thanks
Comment