Lesson 5: Beyond Bot Architecture Overview
I know your excited to create your first BeyondBot. I wanted to share a little about why the architecture is the way that it is. You do not need to understand all this to start creating BeyondBots but it may help.
NinjaTrader strategies derive from Strategy base class. In object-oriented terminology, the desired way to implement new functionality would be to extend Strategy base class. However, this is not possible because of the way Ninja creates Strategy class. As a result, we had to come up with some creative work around to get a similar effect.
Now, one way to try to approach/solve this would be to pass in Strategy object to our SubStrategy (BeyondBot) class, and we do that for some cases. However, if we were to then access the Strategy then we'd have to use an object reference. This would be unnatural when referencing bar close data.
Instead / in addition too that, we use the following C# features to obtain the desired implementation:
Partial classes allow us to extend a class and put it in several files. This allows us to contain our strategies within separate files.
We can define/group properties of our strategy within "inner-classes" which creates another containment level.
We can benefit from code-reuse by defining some of the shared functionality in the Base class SubStrategy.
We use Delegates which are just a way to dynamically call a function. For the bar processing data logic, we define the bar processing logic functions outside the SubStrategy class and inside the Strategy partial class because it allows us to reference all Strategy properties and fields naturally without using an object reference. By using delegates, we can minimize edits required to the BeyondBot "base class", i.e the main partial class when adding new strategies.
Delegates run on the same thread and do not incur much overhead. If you are concerned, you can add in direct function calls in the partial class because the containment is through the partial class structure.