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

Undocumented/Unsupported Ninja Tips and Tricks

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

    #91
    Originally posted by fosch View Post
    Have you tried the OnStartUp() method instead of Initialize()?
    That would work, but there is a problem -- it never gets called automatically, and you cannot call it externally, because it is protected. That is why my cleverly named function DoStartUp() is needed -- it is a publicly callable OnStartUp() replacement (remember, this is only a helper class, not an indicator).

    The code that instantiates the object has to call DoStartUp() because Initialize() is the only thing called automatically, and that is too early. If you know anything that is called automatically -- later than Initialize() -- in this scenario, please speak up -- it would probably work, and would be preferable to requiring the explicit DoStartUp() call.

    -----

    By the way, does anyone know how Initialize() gets called? My best guess is that it gets called from the base class constructor.

    --EV

    Comment


      #92
      I’m sorry if I’m telling people something that already know watching this thread, but someone put a link referencing the search functionality of the support forum so I thought it best to offer this than stay quite.

      I don’t ever use the forum search functionality now, I just use Google for this. You can define the site you want Google to search. The example below looks for OnStartUp on the support forum. You can look at the advanced search function on the Google Homepage to get a description.

      site:www.ninjatrader.com/support/forum/ OnStartUp()

      Cheers,

      drolles

      Comment


        #93
        Originally posted by gg80108 View Post
        found this on emini-fools.com.. if still need something
        Hello gg80108, I tried this strategy you've attached and I get the following error in my output window:

        **NT** Failed to call method 'Initialize' for strategy 'ToolBarButtons/ad6245d13b3a4db98869002615f8e9ef': Object reference not set to an instance of an object.
        **NT** Failed to call method 'Initialize' for strategy 'ToolBarButtons/e0d4cb082f384a69bfe009e91bbed7bf': Object reference not set to an instance of an object.

        What does this strategy do? Because I am looking for a code to help me activate or trigger the CLOSE button in the dom when its reached a certain condition so that my strategies will be automatically disable. Can you explain to me how to use this strategy you have attached? Thanks in advance. Or if you can help me on searching code that will automatically disable strategy in the strategy tab of Ninja if it reached a certain condition.

        Comment


          #94
          This puts "buttons" on your chart so u can manually change the strategy without having to shut the strategy down and bring back up,,,, like all of a sudden u only want to take longs only etc..
          Check this out for stopping ur strategy
          Disables the running strategy.
          Syntax
          Disable()


          Examples
          protected override void OnBarUpdate()
          {
          // Disable strategy at 2PM
          if (ToTime(Time[0]) == 140000)
          Disable();
          }
          Last edited by gg80108; 02-13-2011, 10:37 PM.

          Comment


            #95
            Originally posted by gg80108 View Post
            This puts "buttons" on your chart so u can manually change the strategy without having to shut the strategy down and bring back up,,,, like all of a sudden u only want to take longs only etc..
            Check this out for stopping ur strategy
            Disables the running strategy.
            Syntax
            Disable()


            Examples
            protected override void OnBarUpdate()
            {
            // Disable strategy at 2PM
            if (ToTime(Time[0]) == 140000)
            Disable();
            }
            Thank you very much gg80108, the Disable(); code works well but I am worried for the side effect of this method.

            Comment


              #96
              Crosshairs and future dateTimes

              If you have equidistant bar spacing the crosshairs will not reveal future date times beyond Current Bar

              open the chart, go to chart properties (right mouse klick), change "equidistant bar spacing" to false. this will reveal future date times.

              original author below

              original author

              Comment


                #97
                Originally posted by Mindset View Post
                If you have equidistant bar spacing the crosshairs will not reveal future date times beyond Current Bar

                open the chart, go to chart properties (right mouse klick), change "equidistant bar spacing" to false. this will reveal future date times.
                Thanks Mindset, very interesting.

                It is strange, isn't it? If the bar distance is equidistant then it should be quite easy for NT to calculate & display the future date times.

                Regards
                Ralph

                Comment


                  #98
                  ARGB of colors

                  In looking for something else I stumbled across this.... if you want to know what a color's ARGB values are


                  Code:
                  	 var props = typeof(Color).GetProperties(BindingFlags.Public | BindingFlags.Static);
                          foreach (PropertyInfo prop in props)
                          {
                              Color color = (Color) prop.GetValue(null, null);
                              Print("Color ."+ prop.Name  +
                  	   Environment.NewLine+ color.A +" A"+
                             Environment.NewLine+color.R+" R"+ 
                  	   Environment.NewLine+color.G + " G"+ 
                  	   Environment.NewLine+color.B+ " B");
                          }
                  NB requires using System.Reflection
                  Last edited by Mindset; 07-15-2011, 01:24 AM. Reason: Add

                  Comment


                    #99
                    Compile and reload custom assembly from within strategy

                    the following code will accomplish the subj task:

                    NinjaTrader.Code.Compiler.Compile(false, false, null);

                    edit: this will not reload the strategy itself though. the following does compile custom assembly, reload it AND re-initialize idicators/strategies for the active chart.

                    CompilerResults results = NinjaTrader.Code.Compiler.Compile(false, false, null);

                    if (results.Errors.Count == 0)
                    {
                    ChartControl.ApplyIndicatorsStrategies();
                    }

                    Apparently, ChartControl method is not public, but hey this is 'unsupported' thread anyway. and so it's easily done through reflection.
                    Last edited by jbarr; 08-06-2011, 01:27 PM.

                    Comment


                      Synchronize Strategy to Account Postions

                      The following code appears to copy the account positions to the strategy positions:

                      protectedoverridevoid OnStartUp()
                      {
                      // Copy any outstanding Positions from the Account to the Strategy
                      for (int i = 0; i < Positions.GetLength(0); i++)
                      {
                      Position StratPos = Positions[i];
                      Position AcctPos = Account.Positions.FindByInstrument(StratPos.Instru ment);
                      if (AcctPos != null)
                      Positions.SetValue(AcctPos, i);
                      }
                      }

                      Are there any particular issues or problems that I should look out for when using this approach to synchronize the strategy to match the account?

                      I suppose that if there was a possibility of orders left outstanding, I would need to do something similar for the Orders object as I did above for the Positions object.

                      Are there other objects that would need to be brought into sync in order to get the Strategy as a whole into sync with the Account? For example, would the statistics in the Performance object be incorrect as a result of doing this? What else am I forgetting?

                      Any experience anyone else can add as a result of using this code or alternatives would be greatly appreciated.

                      Comment


                        Calling an external .dll based Form

                        Here is a link to a NT indicator w/ VisualStudio project files for any one interested in modifying indicator parameters w/o disturbing other indicators (not good in multi-time-frame).

                        http://www.ninjatrader.com/support/f...480#post253480

                        Comment


                          The compiler command that NT uses

                          When NT starts, it compiles all the .cs files using the CSC.EXE compiler. Apparently that is also what it does when you import an indicator or strategy: it calls the csc.exe command to recompile the assembly. That is why when we import indicators, you do not have to restart NT before you can use the indicator, whereas if you just copy the cs file into the folder, the only way you can use the indictor is by restarting NT or opening the file and using the F5 function. This presents a problem when one uses a custom setup file to distribute indicators. It is silly to ask clients to shutdown, and restart NT after running the custom installer.

                          Does anyone have any idea what the command line is the NT uses for compiling the assembly under the covers? That way, we can just call the same command using our custom installer.
                          Last edited by koganam; 05-13-2014, 10:55 AM. Reason: Corrected spelling.

                          Comment


                            the command they use: post #99.

                            however, the newly compiled assembly gets loaded into the same appdomain as the main app and, therefore, cannot be simply unloaded. so what they do is give it a random guid name, save it to 'NinjaTrader 7\bin\Custom\Tmp' and load a new copy into memory every time 'NinjaTrader.Custom.dll' gets recompiled.

                            in my setup, i use vs2010 project and build an external dll myself. but that's a slightly different story as i dont link into the same custom dll where all the indicators are but rather build a vendor one. so, in order NOT to restart nt7 when dynamically reloading my stuff i have to get around the fusion probing algorithm (by carefully using assembly.loadfile as opposed to loadfrom) from within ninja code itself.

                            once again they load all custom made assemblies into the same appdomain. of course, it's convenient as they dont have to marshal data and calls, no need for a proxy. but there is no real separation from the user code and one cannot unload a dll without unloading an entire domain so every single time you recompile another copy is loaded into same memory pool.

                            hope that helps.

                            Comment


                              Originally posted by jbarr View Post
                              the command they use: post #99.

                              however, the newly compiled assembly gets loaded into the same appdomain as the main app and, therefore, cannot be simply unloaded. so what they do is give it a random guid name, save it to 'NinjaTrader 7\bin\Custom\Tmp' and load a new copy into memory every time 'NinjaTrader.Custom.dll' gets recompiled.

                              in my setup, i use vs2010 project and build an external dll myself. but that's a slightly different story as i dont link into the same custom dll where all the indicators are but rather build a vendor one. so, in order NOT to restart nt7 when dynamically reloading my stuff i have to get around the fusion probing algorithm (by carefully using assembly.loadfile as opposed to loadfrom) from within ninja code itself.

                              once again they load all custom made assemblies into the same appdomain. of course, it's convenient as they dont have to marshal data and calls, no need for a proxy. but there is no real separation from the user code and one cannot unload a dll without unloading an entire domain so every single time you recompile another copy is loaded into same memory pool.

                              hope that helps.
                              Thanks for your response, but I must not have been as clear in my description as I thought that I was.

                              The command in post#99 is run from thinkscript, and works pretty well.

                              What I am looking for however it the command line for csc.exe that they run in a hidden CMD window, both when we start NT, and when we import an indicator/strategy.

                              I do not want to have to open a dummy ninjascript file (with the ninjascript compile method), and send an F5 key, which is what I would have to do to use the method of post#99.

                              Comment


                                well, answering your question again they do NOT run any 'hidden cmd windows'.
                                the command in #99 is what nt7 code uses (oversimplified) and what is completely sufficient as of 7.0.6 .
                                all the rest is handled by microsoft.csharp facilities (including running the compiler itself and then a linker). there is, of course, a call like 'Provider.CompileAssemblyFromFile' made from NinjaTrader.Code.Compiler routine where Provider is of CodeDomProvider and apparently CSharpCodeProvider.
                                if you need to know what compiler options are i can give it to you, but the problem is not to compile but TO LOAD a compiled assembly. you can do it either from the code running under nt7 or through injector which is very doable but obviously a huge overkill.

                                i've no idea what you mean by custom installer and dummy script.

                                if you want to install external dll just once it is only reasonable to require a restart.

                                if you are a developer and need reload a dll in question many times during a session you would need to employ your own assembly loading algorithm (which is, once again, different from the one used to dynamically load NinjaTrader.Custom.dll).

                                if you want to deploy a source code dynamically, without user interaction, then you must have a code already running under nt and employ #99 commands to compile/reload.
                                Last edited by jbarr; 09-04-2011, 02:06 PM.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by cshox, Today, 04:21 PM
                                0 responses
                                2 views
                                0 likes
                                Last Post cshox
                                by cshox
                                 
                                Started by z679Gju, 05-03-2024, 02:37 PM
                                2 responses
                                18 views
                                0 likes
                                Last Post z679Gju
                                by z679Gju
                                 
                                Started by ExtremelyRough, Today, 03:50 PM
                                0 responses
                                5 views
                                0 likes
                                Last Post ExtremelyRough  
                                Started by cshox, Yesterday, 01:07 PM
                                2 responses
                                8 views
                                0 likes
                                Last Post cshox
                                by cshox
                                 
                                Started by FAQtrader, Today, 11:31 AM
                                2 responses
                                11 views
                                0 likes
                                Last Post FAQtrader  
                                Working...
                                X