Another PowerBasic Example – a Random Number Generator

Here is another PowerBasic example for those of you trying to learn how to enhance NeuroShell via programming. This indicator produces a random number between a minimum and maximum value on every bar. It is true that we supply such an indicator in the Statistical indicator category, but that one produces the same values everytime you load the chart. Most people prefer that, but if you want one that is not reproducible, then you can use the code below to build it. Even if you don’t want such an indicator, this is a good learning example. Once you learn how to improve NeuroShell with PowerBasic, it will open a whole new world to you.

Compile the code and save the DLL in the NeuroShell Template folder. Then create an indicator to call it (see the indicator category External Program and Library calls). You will be using the indicator External DLL Call by Array. Find the DLL in the dropdown box and select the randomseed indicator. There will be 4 inputs:

The first is the indicator output which is byref single (pointers are byref)
The second is the number of bars in the time series inputs and is byval long
The third and fourth are byval single

So here is the code:

#COMPILE DLL

SUB randomseed ALIAS “randomseed” (BYVAL out_array AS SINGLE PTR, BYVAL numBars AS LONG, BYVAL minimum AS SINGLE, BYVAL maximum AS SINGLE) EXPORT

 DIM i AS LONG

 RANDOMIZE TIMER ‘resets the seed
 FOR i=0 TO numBars-1
  @out_array = RND()*(maximum-minimum) + minimum
 NEXT i

END SUB

To download an already compiled version (Release 6.0 or better) click here. Put the downloaded files into the NeuroShell Trader 6/Template folder. Then restart NeuroShell and find the Randomseed indicator in the Custom Indicators category.

Was this article helpful?

Related Articles