/* * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; namespace QuantConnect.Indicators { /// /// Class that extends CompositeIndicator to execute a given action once is reset /// public class ResetCompositeIndicator : CompositeIndicator { /// /// Action to execute once this indicator is reset /// private Action _extraResetAction; /// /// Creates a new ResetCompositeIndicator capable of taking the output from the left and right indicators /// and producing a new value via the composer delegate specified /// /// The left indicator for the 'composer' /// The right indicator for the 'composer' /// Function used to compose the left and right indicators /// Action to execute once the composite indicator is reset public ResetCompositeIndicator(IndicatorBase left, IndicatorBase right, IndicatorComposer composer, Action extraResetAction) : this($"RESET_COMPOSE({left.Name},{right.Name})", left, right, composer, extraResetAction) { } /// /// Creates a new CompositeIndicator capable of taking the output from the left and right indicators /// and producing a new value via the composer delegate specified /// /// The name of this indicator /// The left indicator for the 'composer' /// The right indicator for the 'composer' /// Function used to compose the left and right indicators /// Action to execute once the indicator is reset public ResetCompositeIndicator(string name, IndicatorBase left, IndicatorBase right, IndicatorComposer composer, Action extraResetAction) : base(name, left, right, composer) { _extraResetAction = extraResetAction; } /// /// Resets this indicator and invokes the given reset action /// public override void Reset() { base.Reset(); _extraResetAction.Invoke(); } } }