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!
See more
See less

Partner 728x90

Collapse

Intermediate between StrategyBase and IndicatorBase

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    I think it's not possible in NT7, however, if it's possible NT8, i will be glad (in my last post, i related to NT8 primarily)

    Comment


      #17
      Originally posted by TazoTodua View Post
      My 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.
      No, this is not possible.

      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
      that each have the section below, defined appropriately for that file,

      Code:
      #region Preprocessor Directives
      #define DEFINED_STRATEGY
      /* #define DEFINED_INDICATOR */
      #endregion
      That is,
      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]
      ...
          }
      }
      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.

      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.

      Comment


        #18
        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


          #19
          Originally posted by TazoTodua View Post
          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://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).
          Thanks for the link! I already use that SymLink technique to keep my db/data folder on a different drive.

          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


            #20
            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 mjairg, 07-20-2023, 11:57 PM
            3 responses
            213 views
            1 like
            Last Post PaulMohn  
            Started by TheWhiteDragon, 01-21-2019, 12:44 PM
            4 responses
            544 views
            0 likes
            Last Post PaulMohn  
            Started by GLFX005, Today, 03:23 AM
            0 responses
            3 views
            0 likes
            Last Post GLFX005
            by GLFX005
             
            Started by XXtrader, Yesterday, 11:30 PM
            2 responses
            12 views
            0 likes
            Last Post XXtrader  
            Started by Waxavi, Today, 02:10 AM
            0 responses
            7 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Working...
            X