NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 02-16-2007, 01:51 AM   #1
chantj
Junior Member
 
Join Date: Jan 2007
Location: , ,
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

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.
chantj is offline  
Reply With Quote
Old 02-20-2007, 12:24 AM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Post 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.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 10-23-2009, 08:35 AM   #3
xTrader1
Senior Member
 
Join Date: Apr 2009
Posts: 208
Thanks: 0
Thanked 4 times in 3 posts
Default 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.
xTrader1 is offline  
Reply With Quote
Old 10-23-2009, 08:38 AM   #4
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Unfortunately this is not supported in NT7.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 10-23-2009, 08:50 AM   #5
xTrader1
Senior Member
 
Join Date: Apr 2009
Posts: 208
Thanks: 0
Thanked 4 times in 3 posts
Default 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.
xTrader1 is offline  
Reply With Quote
Old 10-23-2009, 08:52 AM   #6
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Thanks for your suggestion. We'll add it to the list of future considerations.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 10-23-2009, 09:27 AM   #7
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

Quote:
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
Ralph is offline  
Reply With Quote
The following user says thank you to Ralph for this post:
Old 10-23-2009, 10:32 AM   #8
xTrader1
Senior Member
 
Join Date: Apr 2009
Posts: 208
Thanks: 0
Thanked 4 times in 3 posts
Default Thank you for remark.

Quote:
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 Images
File Type: jpg output.jpg (17.4 KB, 11 views)
xTrader1 is offline  
Reply With Quote
Old 10-23-2009, 01:34 PM   #9
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

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
Ralph is offline  
Reply With Quote
Old 10-04-2012, 06:25 PM   #10
NJA_MC
Member
 
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
Default

Can the /unsafe compiler directive be added in any of the recent NT7 builds?
NJA_MC is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 06:56 AM.