Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Intermediate between StrategyBase and IndicatorBase
Collapse
X
-
No, this is not possible.Originally posted by TazoTodua View PostMy question, or maybe feature suggestion is, if it's possible to have 1 intermediate class, which will ALSO CONTAIN THE INDICATOR/STRATEGY SPECIFIC FUNCTIONS, LIKE "UserControlCollection", "ChartControl" and etc... (like NinjaScriptBase already contains the `Print` or other shared methods). so, we wouldnt have to write same codes 2 times.
However, (expanding on what I wrote before) I achieved an interesting solution that you may find useful. Let me explain further.
Ultimately, I invented a way to create a quasi-"single" intermediate class for both Indicators and Strategies with a minimum (*) of fuss (**) and maintenance (***).
(*) You still need two files, one in bin/Custom/Indicator and the other in bin/Custom/Strategy.
(**) Because two files are needed to achieve this, the goal was to make these 2 files as completely identical as possible. The tricks needed to achieve this are simple & safe.
(***) After I edit one of the files, I use WinMerge to copy the changes to the other file.
Ok, so there is no 'single' intermediate class file, since that is not possible.
Here's what I really did: I wanted two files, kept identical as possible, that would be used to define an appropriate intermediate class that would still be Indicator and Strategy specific.
I decided to employ preprocessor directives. That way I could segregate Indicator specific code away from the Strategy specific code.
For this solution I created two files,
that each have the section below, defined appropriately for that file,Code:bin/Custom/Indicator/bltBaseIndicator.cs bin/Custom/Strategy/bltBaseStrategy.cs
That is,Code:#region Preprocessor Directives #define DEFINED_STRATEGY /* #define DEFINED_INDICATOR */ #endregion
in bltBaseIndicator.cs, only DEFINED_INDICATOR is defined.
in bltBaseStrategy.cs, only DEFINED_STRATEGY is defined.
The other unused directive is simply commented out, as the above code sample illustrates. The remainder of the files are absolutely identical.
How to define the intermediate class? Simple, use the preprocessor directives as a type of 'macro guard' to segregate the code. For example, inside both files, I defined the intermediate class names inside short guarded code sections, like this,
and in the remainder of the file, was able to use the macro guards, as necessary, to further segregate Indicator-only code (such as helpers for the Plot/OnRender function) and Strategy-only code (such as helpers for OnOrderUpdate and OnExecution) very easily. For me, turns out there were relatively few areas needing segregation.Code:#if DEFINED_STRATEGY namespace NinjaTrader.Strategy { abstract public class bltBaseStrategy : Strategy { #endif #if DEFINED_INDICATOR namespace NinjaTrader.Indicator { abstract public class bltBaseIndicator : Indicator { #endif ... [remainder of file] ... } }
The last extra bit of maintenance requires that you keep both files in sync. This is relatively simple to do using WinMerge, which I found very easy to use.
That's it!
The key to this has been using WinMerge (I am using version 2.14). Using WinMerge made it easy to accept the symbiotic relationship between the two files. Once you get the hang of using WinMerge, you will see it's a very fast and easy tool.
PS: WinMerge supports an option called 'Shell Integration' that adds items to the context menu of file explorer to make the merge process easier. Once you master this process of using WinMerge, merging your changes becomes routine and very fast.
Enjoy!
Last edited by bltdavid; 09-12-2018, 09:28 AM.
- Likes 1
Comment
-
thanks bltdavid for the solution. I use WinMerge already years, excellent tools (sometimes text-compare.com too).
Btw, not a subject, but i also reccommend TextCrawler, another excellent tool.
btw 2) I still never ever will maintain two same identical files, as it's hard for me. To say a bit more (which might even surprise you), i use Symlink of folder of `custom` (using https://puvox.software/blog/easiest-...link-symbolic/ ) so, those folders actually reside on my D disk, and i have shared C# .cs library file between NT7 and NT8 (that file also exists on D disk).Last edited by ttodua; 08-26-2021, 01:25 PM.
Comment
-
Thanks for the link! I already use that SymLink technique to keep my db/data folder on a different drive.Originally posted by TazoTodua View Postthanks bltdavid for the solution. I use WinMerge already years, excellent tools (sometimes text-compare.com too).
Btw, not a subject, but i also reccommend TextCrawler, another excellent tool.
btw 2) I still never ever will maintain two same identical files, as it's hard for me. To say a bit more (which might even surprise you), i use Symlink of folder of `custom` (using https://www.protectpages.com/blog/ea...link-symbolic/ ) so, those folders actually reside on my D disk, and i have shared C# .cs library file between NT7 and NT8 (that file also exists on D disk).
What did you do to achieve a shared C# library for NT7 & NT8?
I presume that library is not calling much NinjaScript-Framework specific code?
Comment
-
You are right it's not NT specific, instead c# 3.5 specific functions library, which i use frequently (Read/write from/to url/website, dictionary and string manipulation methods, and many C# functions library that i call from Indis and strategies easily).
i think everyone'd better to have their custom library (to say as a conclusion, i have:
- 1 shared library cs file between NT7 and NT8
- 1 additional cs file specifically in NT7 folder (for nt7 functions)
- 1 additional cs file specifically in NT8 folder (for nt8 functions)
(but i am thinking now to merge the shared file directly in NT7 and NT8 cs files, thus i will have 1 compact file for NT7 and 1 for NT8)
also, I use Cobian Backuper (to backup D: functons folder every day). for some folders (which i extensively modify) i use TortoiseGit to maintain it on bitbucket, instead of cobian.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
596 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
343 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
556 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
554 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment