NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


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

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 05-20-2007, 07:37 AM   #1
grd974
Senior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 124
Thanks: 0
Thanked 0 times in 0 posts
Default Hello world

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.
grd974 is offline  
Reply With Quote
Old 05-20-2007, 08:45 AM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

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:

Code:
if (ADX(14)[0] > 30) 
    PlaySound("Connected.wav");
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-20-2007, 01:41 PM   #3
grd974
Senior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 124
Thanks: 0
Thanked 0 times in 0 posts
Arrow Some further programing

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
grd974 is offline  
Reply With Quote
Old 05-20-2007, 04:36 PM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

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.
NinjaTrader_Ray 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 02:01 AM.