I've tried to ask this question at "quantitive finance" but it seems this is better place because the question more about programing than trading
How do you declare Indicator
interface? What would be the correct way to model an "Indicator"?
I'm using c# and I want to declare Indicator
interface like this:
interface Indicator
{
double Value { get; }
event Action<Void> ValueUpdated;
}
or probably even like this:
interface Indicator
{
event Action<Double> ValueUpdated;
}
I consider "pure price" also as trivial indicator:
class PriceIndicator : Indicator {
PriceIndicator(string ticker) {
....
}
}
Example of MA:
class MovingAverage : Indicator {
private PriceIndicator price;
public MovingAverage(PriceIndicator price, int period) {
....
}
// when price.ValueUpdated event occurs need to recalculate MA and raise ValueUpdated event
}
What do you think? Any suggestions are welcome!
I would have something like this
So an indicator that is composed could be
Then a component that knows all indicators that need to be calculated would call this method every time the price is changed, and reflect that in a chart or somewhere else.
Really this problem has been resolved in a numerous existing applications already, some examples you could check are Ninjatrader (implemented in C#) or Metatrader (implemented with c)