public void kekek() { ExponentialMovingAverage Selector(int i) => new ExponentialMovingAverage($"EMA{i + 2}", i + 2); var concat = Concat.OnAllUpdatedOnce(Enumerable.Range(0, 3).Select(Selector)); Concat.ForEvery.OnAllUpdatedOnce(concat, Selector); }
private static Concat BindToConcatenatingList(IUpdatable source, Concat concat) { //var bindTo = concat.Concatenating; //var len = bindTo.Length; //concat.UpdateHandler = ConcatUpdateHandler; //bool ConcatUpdateHandler(long time, DoubleArray input) { // for (int i = 0; i < len; i++) // bindTo[i].Update(time, input.SliceIndex(i)); // return concat.IsReady; //} return(concat); }
private static Concat BindToConcatenatingList(Concat concat) { var bindTo = concat.Concatenating; var len = bindTo.Length; concat.UpdateHandler = ConcatUpdateHandler; void ConcatUpdateHandler(long time, DoubleArray input) { for (int i = 0; i < len; i++) { bindTo[i].Update(time, input); } } return(concat); }
/// <summary> /// Crunches <paramref name="updatables"/> whenever <paramref name="crunchTriggers"/> is updated for n <paramref name="interval"/> times. /// </summary> /// <param name="name">Name of the cruncher for debugging purposes.</param> /// <param name="updatables">The updatables to observe and crunch.</param> /// <param name="crunchTriggers">The <see cref="IUpdatable"/>s to observe for fires of <see cref="IUpdatable.Updated"/>.</param> /// <param name="interval">The interval for how many fires must <paramref name="crunchTriggers"/> trigger <see cref="IUpdatable.Updated"/> in order to trigger Concat's update event.</param> /// <param name="properties"> /// How many properties all of the <paramref name="updatables"/> emit. /// this can be less than their minimal properties. /// e.g. if <paramref name="updatables"/> emit <see cref="BarValue"/> (4 properties), selecting 1 will take only <see cref="BarValue.Close"/>. /// </param> /// <param name="triggerMustBeReady">Does <paramref name="crunchTriggers"/> must be ready to trigger Concat's update event? By default </param> /// <returns>A new cruncher configured.</returns> public static Concat OnSpecificUpdate(IEnumerable <IUpdatable> updatables, IUpdatable[] crunchTriggers, int interval = 1, int properties = 1, string name = null, bool[] triggerMustBeReady = null) { if (interval <= 0) { throw new ArgumentOutOfRangeException(nameof(interval)); } // ReSharper disable once UseObjectOrCollectionInitializer var c = new Concat { Name = name ?? "Concat" }; c.Options = ConcatOptions.OnSpecificUpdated; c.observing = crunchTriggers; c.concatenating = updatables.ToArray(); var len = c.length = c.concatenating.Length; var props = c.Properties = properties; var outputCount = c.outputCount = c.concatenating.Sum(upd => upd.OutputCount); c.signalCounter = null; var workingTarget = new DoubleArrayPinned2DManaged(outputCount, props); c.workingTarget = workingTarget; c.counter = interval; c.BindValues(); for (var i = 0; i < crunchTriggers.Length; i++) { var onlyWhenReady = triggerMustBeReady[i]; var crunchTrigger = crunchTriggers[i]; if (interval == 1) { if (onlyWhenReady) { crunchTrigger.Updated += (time, updated) => { if (crunchTrigger.IsReady) { c.OnUpdated(time); } }; } else { crunchTrigger.Updated += (time, updated) => c.OnUpdated(time); } } else { if (onlyWhenReady) { crunchTrigger.Updated += (time, updated) => { if (!crunchTrigger.IsReady) { return; } if (--c.counter <= 0) { c.OnUpdated(time); c.counter = interval; } }; } else { crunchTrigger.Updated += (time, updated) => { if (--c.counter <= 0) { c.OnUpdated(time); c.counter = interval; } }; } } crunchTrigger.Resetted += _ => c.counter = interval; } return(c); }
/// <summary> /// Crunches when any of <see cref="IUpdatable"/> are updated for every n <paramref name="interval"/>. /// </summary> /// <param name="name">Name of the cruncher for debugging purposes.</param> /// <param name="updatables">The updatables to observe and crunch.</param> /// <param name="interval">The interval for how many fires must any of <paramref name="updatables"/> trigger <see cref="IUpdatable.Updated"/> in order to trigger Concat's update event.</param> /// <param name="properties"> /// How many properties all of the <paramref name="updatables"/> emit. /// this can be less than their minimal properties. /// e.g. if <paramref name="updatables"/> emit <see cref="BarValue"/> (4 properties), selecting 1 will take only <see cref="BarValue.Close"/>. /// </param> /// <returns>A new cruncher configured.</returns> public static Concat OnEveryUpdate(IEnumerable <IUpdatable> updatables, int interval = 1, int properties = 1, string name = null) { if (interval <= 0) { throw new ArgumentOutOfRangeException(nameof(interval)); } // ReSharper disable once UseObjectOrCollectionInitializer var c = new Concat(); c.Name = name ?? "Concat"; c.Options = ConcatOptions.OnEveryUpdate; var obsing = c.observing = updatables.ToArray(); c.concatenating = c.observing.ToArray(); var len = c.length = c.concatenating.Length; var props = c.Properties = properties; var outputCount = c.outputCount = c.concatenating.Sum(upd => upd.OutputCount); c.signalCounter = null; var workingTarget = new DoubleArrayPinned2DManaged(outputCount, props); c.workingTarget = workingTarget; c.counter = interval; c.BindValues(); for (var i = 0; i < obsing.Length; i++) { IUpdatable srcUpdatable = obsing[i]; if (properties == 1) { if (interval == 1) { srcUpdatable.Updated += (time, updated) => { c.OnUpdated(time); }; } else { srcUpdatable.Updated += (time, updated) => { if (--c.counter <= 0) { c.OnUpdated(time); c.counter = interval; } }; srcUpdatable.Resetted += sender => { c.counter = interval; }; } } else { //case when values collected are multi-valued output (tradebar value) if (interval == 1) { srcUpdatable.Updated += (time, updated) => { c.OnUpdated(time); }; } else { srcUpdatable.Updated += (time, updated) => { if (--c.counter <= 0) { c.OnUpdated(time); c.counter = interval; } }; srcUpdatable.Resetted += sender => { c.counter = interval; }; } } } return(c); }
/// <summary> /// Crunches when all <see cref="IUpdatable"/> were updated atleast once. /// </summary> /// <param name="name">Name of the cruncher for debugging purposes.</param> /// <param name="updatables">The updatables to observe and crunch.</param> /// <param name="properties"> /// How many properties all of the <paramref name="updatables"/> emit. /// this can be less than their minimal properties. /// e.g. if <paramref name="updatables"/> emit <see cref="BarValue"/> (4 properties), selecting 1 will take only <see cref="BarValue.Close"/>. /// </param> /// <returns>A new cruncher configured.</returns> public static Concat OnAllUpdatedOnce(IEnumerable <IUpdatable> updatables, int properties = 1, string name = null) { // ReSharper disable once UseObjectOrCollectionInitializer var c = new Concat(); c.Name = name ?? "Concat"; c.Options = ConcatOptions.OnAllUpdatedOnce; var obsing = c.observing = updatables.ToArray(); c.concatenating = c.observing.ToArray(); var len = c.length = c.concatenating.Length; var outputCount = c.outputCount = c.concatenating.Sum(upd => upd.OutputCount); var props = c.Properties = properties; var cntr = c.signalCounter = new bool[len]; var workingTarget = new DoubleArrayPinned2DManaged(outputCount, props); c.workingTarget = workingTarget; c.counter = len; //debug handle //bind the values to their repsective memory address. c.BindValues(); for (var i = 0; i < obsing.Length; i++) { IUpdatable srcUpdatable = obsing[i]; int updId = i; //case when values collected are indicator output (single value) if (properties == 1) { srcUpdatable.Updated += (time, updated) => { if (!cntr[updId]) { cntr[updId] = true; if (--c.counter <= 0) { c.OnUpdated(time); Array.Clear(cntr, 0, len); c.counter = len; } } }; srcUpdatable.Resetted += sender => { if (cntr[updId]) { c.counter++; cntr[updId] = false; } }; } else { //case when values collected are multi-valued output (tradebar value) srcUpdatable.Updated += (time, updated) => { if (!cntr[updId]) { cntr[updId] = true; if (--c.counter <= 0) { c.OnUpdated(time); Array.Clear(cntr, 0, len); c.counter = len; } } }; srcUpdatable.Resetted += sender => { if (cntr[updId]) { c.counter++; cntr[updId] = false; } }; } } return(c); }
/// <summary> /// Concatenates when all <see cref="IUpdatable"/> were updated atleast once. /// </summary> /// <param name="name">Name of the cruncher for debugging purposes.</param> /// <param name="properties"> /// How many properties all of the <paramref name="updatables"/> emit. /// this can be less than their minimal properties. /// e.g. if <paramref name="updatables"/> emit <see cref="BarValue"/> (4 properties), selecting 1 will take only <see cref="BarValue.Close"/>. /// </param> /// <returns>A new cruncher configured.</returns> public static Concat OnAllUpdatedOnce(IUpdatable source, BindingIndicatorFactoryHandler factory, int properties = 1, string name = null, bool waitForSourceReady = true) { IUpdatable[] sources = Factory(source, factory); return(BindToConcatenatingList(source, Concat.OnAllUpdatedOnce(sources, properties, name))); }
/// <summary> /// Concatenates <paramref name="updatables"/> whenever <paramref name="crunchTriggers"/> is updated for n <paramref name="interval"/> times. /// </summary> /// <param name="name">Name of the cruncher for debugging purposes.</param> /// <param name="crunchTriggers">The <see cref="IUpdatable"/>s to observe for fires of <see cref="IUpdatable.Updated"/>.</param> /// <param name="interval">The interval for how many fires must <paramref name="crunchTriggers"/> trigger <see cref="IUpdatable.Updated"/> in order to trigger IndicatorRow's update event.</param> /// <param name="properties"> /// How many properties all of the <paramref name="updatables"/> emit. /// this can be less than their minimal properties. /// e.g. if <paramref name="updatables"/> emit <see cref="BarValue"/> (4 properties), selecting 1 will take only <see cref="BarValue.Close"/>. /// </param> /// <param name="size">How many indicators will be initialized via <paramref name="factory"/>.</param> /// <param name="factory">A factory to initialize new indicators.</param> /// <param name="triggerMustBeReady">Does <paramref name="crunchTriggers"/> must be ready to trigger IndicatorRow's update event? By default </param> /// <returns>A new cruncher configured.</returns> public static Concat OnSpecificUpdate(IUpdatable source, BindingIndicatorFactoryHandler factory, IUpdatable[] crunchTriggers, int interval = 1, int properties = 1, string name = null, bool[] triggerMustBeReady = null, bool waitForSourceReady = true) { IUpdatable[] sources = Factory(source, factory); return(BindToConcatenatingList(source, Concat.OnSpecificUpdate(sources, crunchTriggers, interval, properties, name, triggerMustBeReady))); }
/// <summary> /// Concatenates when any of <see cref="IUpdatable"/> are updated for every n <paramref name="interval"/>. /// </summary> /// <param name="name">Name of the cruncher for debugging purposes.</param> /// <param name="interval">The interval for how many fires must any of <paramref name="updatables"/> trigger <see cref="IUpdatable.Updated"/> in order to trigger IndicatorRow's update event.</param> /// <param name="properties"> /// How many properties all of the <paramref name="updatables"/> emit. /// this can be less than their minimal properties. /// e.g. if <paramref name="updatables"/> emit <see cref="BarValue"/> (4 properties), selecting 1 will take only <see cref="BarValue.Close"/>. /// </param> /// <param name="size">How many indicators will be initialized via <paramref name="factory"/>.</param> /// <param name="factory">A factory to initialize new indicators.</param> /// <returns>A new cruncher configured.</returns> public static Concat OnEveryUpdate(int size, IndicatorFactoryHandler factory, int interval = 1, int properties = 1, string name = null) { return(BindToConcatenatingList(Concat.OnEveryUpdate(Factory(size, factory), interval, properties, name))); }
/// <summary> /// Concatenates <paramref name="updatables"/> whenever <paramref name="crunchTriggers"/> is updated for n <paramref name="interval"/> times. /// </summary> /// <param name="name">Name of the cruncher for debugging purposes.</param> /// <param name="crunchTriggers">The <see cref="IUpdatable"/>s to observe for fires of <see cref="IUpdatable.Updated"/>.</param> /// <param name="interval">The interval for how many fires must <paramref name="crunchTriggers"/> trigger <see cref="IUpdatable.Updated"/> in order to trigger IndicatorRow's update event.</param> /// <param name="properties"> /// How many properties all of the <paramref name="updatables"/> emit. /// this can be less than their minimal properties. /// e.g. if <paramref name="updatables"/> emit <see cref="BarValue"/> (4 properties), selecting 1 will take only <see cref="BarValue.Close"/>. /// </param> /// <param name="indices">The index to use to call <paramref name="factory"/>.</param> /// <param name="factory">A factory to initialize new indicators using <paramref name="indices"/>.</param> /// <param name="triggerMustBeReady">Does <paramref name="crunchTriggers"/> must be ready to trigger IndicatorRow's update event? By default </param> /// <returns>A new cruncher configured.</returns> public static Concat OnSpecificUpdate(IEnumerable <int> indices, IndicatorFactoryHandler factory, IUpdatable[] crunchTriggers, int interval = 1, int properties = 1, string name = null, bool[] triggerMustBeReady = null) { return(BindToConcatenatingList(Concat.OnSpecificUpdate(Factory(indices, factory), crunchTriggers, interval, properties, name, triggerMustBeReady))); }
/// <summary> /// Concatenates when all <see cref="IUpdatable"/> were updated atleast once. /// </summary> /// <param name="name">Name of the cruncher for debugging purposes.</param> /// <param name="properties"> /// How many properties all of the <paramref name="updatables"/> emit. /// this can be less than their minimal properties. /// e.g. if <paramref name="updatables"/> emit <see cref="BarValue"/> (4 properties), selecting 1 will take only <see cref="BarValue.Close"/>. /// </param> /// <param name="factory">A factory to initialize new indicators using <paramref name="indices"/>.</param> /// <param name="indices">The index to use to call <paramref name="factory"/>.</param> /// <returns>A new cruncher configured.</returns> public static Concat OnAllUpdatedOnce(IEnumerable <int> indices, IndicatorFactoryHandler factory, int properties = 1, string name = null) { return(BindToConcatenatingList(Concat.OnAllUpdatedOnce(Factory(indices, factory), properties, name))); }
/// <summary> /// Concatenates <paramref name="updatables"/> whenever <paramref name="crunchTrigger"/> is updated for n <paramref name="interval"/> times. /// </summary> /// <param name="name">Name of the cruncher for debugging purposes.</param> /// <param name="crunchTrigger">The <see cref="IUpdatable"/> to observe for fires of <see cref="IUpdatable.Updated"/>.</param> /// <param name="interval">The interval for how many fires must <paramref name="crunchTrigger"/> trigger <see cref="IUpdatable.Updated"/> in order to trigger IndicatorRow's update event.</param> /// <param name="properties"> /// How many properties all of the <paramref name="updatables"/> emit. /// this can be less than their minimal properties. /// e.g. if <paramref name="updatables"/> emit <see cref="BarValue"/> (4 properties), selecting 1 will take only <see cref="BarValue.Close"/>. /// </param> /// <param name="size">How many indicators will be initialized via <paramref name="factory"/>.</param> /// <param name="factory">A factory to initialize new indicators.</param> /// <param name="triggerMustBeReady">Does <paramref name="crunchTrigger"/> must be ready to trigger IndicatorRow's update event?</param> /// <returns>A new cruncher configured.</returns> public static Concat OnSpecificUpdate(int size, IndicatorFactoryHandler factory, IUpdatable crunchTrigger, int interval = 1, int properties = 1, string name = null, bool triggerMustBeReady = true) { return(BindToConcatenatingList(Concat.OnSpecificUpdate(Factory(size, factory), crunchTrigger, interval, properties, name, triggerMustBeReady))); }