• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Compile with /unsafe

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

    Compile with /unsafe

    Is there any way to compile ninjascript with the unsafe compiler directive? I want to use pointers in my code.

    If this is not possible, I assume I can create a DLL in Visual Studio, and reference it.

    #2
    imported post

    Sorry. not supported right now.

    Yes you can create a custom DLL in VS studio by compiling/linking all *.cs file in bin\custom, although we do not support that.
    DierkNinjaTrader Customer Service

    Comment


      #3
      what about unsafe in NT7 ?

      I want to use pointers either.

      Please pay attention, you're rendering invalid a whole branch of advanced programming in NT script.

      I need pointers to access a variable within cooperating indicators.

      Comment


        #4
        Unfortunately this is not supported in NT7.
        DierkNinjaTrader Customer Service

        Comment


          #5
          Please consider.

          I think that for advanced programmers it may provide a lot of both: memory and CPU usage optimization. As for now, when I'm using certain indicator separately and then as an embedded indicator in another indicator/strategy , I understand a separate instance of this indicator is created, including its BarArray. In addition , separate , BUT EXACTLY THE SAME computations for 2 or more instances are performed.
          I'm not sure, than even with memory usage optimization in NT7 you're eliminating this resources waste.
          It seems, If I could create and use ONE instance of the same indicator with the same input values globally, it would vastly eliminate waste of resources.
          I can implement such pattern, using pointers , for specific variables I need with cooperation between indicator instances fully programmed according to my needs.

          Comment


            #6
            Thanks for your suggestion. We'll add it to the list of future considerations.
            DierkNinjaTrader Customer Service

            Comment


              #7
              Originally posted by xTrader1 View Post
              ...I understand a separate instance of this indicator is created, including its BarArray. In addition , separate , BUT EXACTLY THE SAME computations for 2 or more instances are performed...
              That is absolutely not true xTrader. Only one indicator instance is created by NT for each indicator with identical signatures.

              Regards
              Ralph

              Comment


                #8
                Thank you for remark.

                Originally posted by Ralph View Post
                That is absolutely not true xTrader. Only one indicator instance is created by NT for each indicator with identical signatures.

                Regards
                Ralph
                What I wrote was based on my feeling regarding memory and CPU utilization.

                After reading your remark, I experimented a little:
                1) I created 3 new charts using historical data for the same instrument, the same last date , all of them 1 sec. period , 60000 bars back. When adding the 2nd chart, memory usage incerased by 34MB , but after adding the 3-rd chart it decreased by 17MB.

                2) Then I added Bollinger Band indicator with the same inputs to all the charts. Adding to the 1-st chart raised memory usage by 3.5 MB. Adding to the 2-nd chart raised memory usage by 3.5 MB again. Adding to the 3-rd chart raised the memory usage by 1.25 MB only.

                It seems, you're right, but somehow NT "gives up" memory allocation, not for the 2-nd, but for the 3-rd instance. But then:

                3) I added 4-th identical new chart. This time memory usage grew by 55Mb. Adding Bollinger DECREASED memory usage by 8MB.

                It seems that there is no direct correlation between memory usage and number of identical charts, but even if you're right, NT preallocates all th time more and more resources for the same charts with the same indicators.

                I used Bollinger, not custom indicator, to avoid any possible bugs. Therefore I could not printout a hash of the Bollinger indicators, which in my mind would be an ultimative indication , whether we're talking about the same instance.

                Then:

                4) I wrote Test1 indicator, with one plot. The only thing it is doing , is to print relevant hash codes :
                protected override void OnBarUpdate()
                {
                if (CurrentBar == 1)
                {
                Print(this.GetHashCode()) ;
                Print(Close.GetHashCode()) ;
                }

                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
                Plot0.Set(Close[0]);
                }

                I added the indicator to all 4 charts. Hashcode is different, for both Close and "this" .
                I'm an experienced programmer , but .NET beginner.

                In my understanding of .NET it means we have separate instances of Test1 and Close the Test1 instances are using for every chart.

                Anything I don't understand ?
                Attached Files

                Comment


                  #9
                  Interesting evaluation xTrader1.

                  Seems I have to revise my point of view partially. I agree with you that there is a separate indicator instance created, as soon as you open one on a chart (It is possible to observe that process with print statements). And during this process an opened Indicator is instantiated several times by Ninja, until one of them is used to be applied to the chart, the others are trashed. That may explain why the memory usage gets down occasionally.

                  On the other hand, if you access an indicator in your code, then it is reused assuming the signature is identical. You can prove that if you have a look at the code of a indicator (after compilation). At the file's end you find a section starting with
                  #region NinjaScript generated code. Neither change nor remove.
                  There you could find the explanation why.

                  Maybe these two different applications of an indicator should be considered separately.

                  Regards
                  Ralph

                  Comment


                    #10
                    Can the /unsafe compiler directive be added in any of the recent NT7 builds?

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by brunoviveiros, Today, 09:36 AM
                    1 response
                    17 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by GARZONJ, Today, 11:22 AM
                    1 response
                    10 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by KonalGondal, Today, 10:18 AM
                    1 response
                    14 views
                    0 likes
                    Last Post NinjaTrader_Kate  
                    Started by Jorge.andres.o, Today, 09:24 AM
                    4 responses
                    21 views
                    0 likes
                    Last Post NinjaTrader_PaulH  
                    Started by Oracletrades, Today, 09:02 AM
                    5 responses
                    22 views
                    0 likes
                    Last Post Oracletrades  
                    Working...
                    X