Multy-Thread Ninjascript Code Example.

I am not experienced programmer, but I making a lot of market statistics using NT for myself.

Once I decided to use both cores of my laptop for lingering calculations, I found out that most examples cause NinjaScript errors or very complicated for my simple practical tasks.

At least, I found working code, that suits by it simplicity and minimalism. And I sharing it here.

This strategy create 2 massives of random double values. Lenght of massives (N) is one only parameter of this strategy.

Then strategy calculates control sum of both massives using resource‐intensive algorithm.

At first, control sum calculates using 2 new threads, than it calculate using ussual serial method.

Strategy print calculation time and control sum in output window.

IMPORTANT:

1) Additional threads read and write to global variables (I know this is wrong, but it is work quick).
2) You can't access to arrays (like int[] i) from additional thread, You have to use List.

For experienced programmers: please, don't read this description and don't look in attached strategy.

Created By fx.practic
NinjaTrader Version 7
File Size 1.4 KB
Create Date(s) 06/30/2013
# of Downloads 208

Importing to NinjaTrader 7 is Easy!

To import your 3rd party app or add-on to NinjaTrader, simply follow these 3 steps:

  1. Download the app or add-on file to your desktop
  2. From the NinjaTrader Control Center window, select the menu File > Utilities > Import NinjaScript
  3. Select the downloaded file from your desktop

Questions?

Visit the NinjaScript File Sharing discussion in the NinjaTrader user forum to interact with fellow traders and the NinjaTrader support team.