Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Intermediate between StrategyBase and IndicatorBase
Collapse
X
-
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,
Code:bin/Custom/Indicator/bltBaseIndicator.cs bin/Custom/Strategy/bltBaseStrategy.cs
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,
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
-
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 NM_eFe, 04-30-2024, 06:14 AM
|
5 responses
30 views
0 likes
|
Last Post
by NM_eFe
Today, 04:28 PM
|
||
Started by Jonker, 04-27-2024, 01:19 PM
|
2 responses
20 views
0 likes
|
Last Post
by Jonker
Today, 04:25 PM
|
||
Started by Max Baxter, 03-07-2019, 09:20 PM
|
8 responses
266 views
0 likes
|
Last Post
by Ymcapital
Today, 04:17 PM
|
||
Started by Felix Reichert, 04-26-2024, 02:12 PM
|
9 responses
53 views
0 likes
|
Last Post Today, 03:56 PM | ||
Started by AaronKoRn, 04-27-2024, 09:49 PM
|
3 responses
31 views
0 likes
|
Last Post
by AaronKoRn
Today, 03:47 PM
|
Comment