![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Jan 2007
Location: , ,
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
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.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Apr 2009
Posts: 208
Thanks: 0
Thanked 4 times in 3 posts
|
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. |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Unfortunately this is not supported in NT7.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Apr 2009
Posts: 208
Thanks: 0
Thanked 4 times in 3 posts
|
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. |
|
|
|
|
|
#6 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Thanks for your suggestion. We'll add it to the list of future considerations.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#7 | |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
Quote:
Regards Ralph |
|
|
|
|
|
The following user says thank you to Ralph for this post: |
|
|
|
#8 | |
|
Senior Member
Join Date: Apr 2009
Posts: 208
Thanks: 0
Thanked 4 times in 3 posts
|
Quote:
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 ? |
|
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
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 |
|
|
|
|
|
#10 |
|
Member
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
|
Can the /unsafe compiler directive be added in any of the recent NT7 builds?
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|