PDA

View Full Version : Hello world


grd974
05-20-2007, 07:37 AM
Trying to learn NinjaScript language, I wanted to write down my first script in the line of Print("Hello world"); at the first shot I got syntax errors that scared me so I went doing : Tools/Edit NinjaScript/Strategy/SampleMACrossOver.
Then I clicked on the icon Compile and got the error message "Error on generating Strategy" and the following error report appeared below :
-----
Description File Line Column
Expected class, delegate, enum, interface, or struct Strategy\UserDefinedMethods.cs 22 20
Identifier expected Strategy\UserDefinedMethods.cs 25 16
Identifier expected Strategy\UserDefinedMethods.cs 25 28
Identifier expected Strategy\UserDefinedMethods.cs 29 16
Identifier expected Strategy\UserDefinedMethods.cs 29 37
Type or namespace definition, or end-of-file expected Strategy\UserDefinedMethods.cs 31 1
The namespace '<global namespace>' already contains a definition for '?' Strategy\UserDefinedMethods.cs 25 27
The namespace '<global namespace>' already contains a definition for '?' Strategy\UserDefinedMethods.cs 29 15
The namespace '<global namespace>' already contains a definition for '?' Strategy\UserDefinedMethods.cs 29 36
-----

Could any helpful NT user provide me with a NinjaScript that I just would have to type in and which, instead of "Hello world" would do {if (ADX(14)[0] > 30 Playsound(Connected.wav")} ?

Gérard.

NinjaTrader_Ray
05-20-2007, 08:45 AM
Gerard,

I would delete all files that you created. You can do this via Tools > Edit NinjaScript > Indicators, selecting a file you created and then press the "Delete" button. Do the same for strategies. Then open any system indicator and press F5 to compile? Hopefully it will compile. If not, double click on any error and fix the error, likely by deleting any code you created.

Then for your code, implement your code as an indicator. Go through the wizard and once you get to the editor, just replace any code within OnBarUpdate() with the following code:


if (ADX(14)[0] > 30)
PlaySound("Connected.wav");

grd974
05-20-2007, 01:41 PM
NinjaTrader_Ray,

I took your advice and it worked, thanks a lot. I'd like to know : what data series or methods are available in order to get the most of the Time & Sales window ?
I'd like to write a strategy dealing with it this way :

if (TickPrice[0] = TickPrice[1] + TickSize) and (TickPrice[1] = TickPrice[2] + TickSize) then do
begin
PlaySound("Alert2.wav");
if (TickVolume[0) >= 100) or (TickVolume[1) >= 100) or (TickVolume[2) >= 100) then PlaySound("Announcement.wav");
end;

Gerard

NinjaTrader_Ray
05-20-2007, 04:36 PM
You need to run the indicator with CalculateOnBarClose = false. This is tick by tick.

if (Close[0] == Close[1] + TickSize && Close[1] == Close[2] + TickSize)
// Do something

For volume, you have to self calculate the difference between the prior volume seen and the current volume. You have to store the last volume in a variable and then reset it to zero when the property FirstTickOfBar == true.