PDA

View Full Version : my first script


stephenszpak
05-24-2008, 05:20 PM
I seem to be missing something here.
I can't get NinjaScript to work at all.
I'm just trying to get it to print Hi at the output window and
ever time I add anything to the bottom of what is below
I will get an error. If I figure this out tonight I will repost.
Putting // with comments if just fine
but anything else results in an error, usually Namespace
Member Declaration Expected.




Thanks to any replies. -Stephen

#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Enter the description of your new custom indicator here")]
public class MyCustomIndicator : Indicator
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
#endregion

/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
CalculateOnBarClose = true;
Overlay = false;
PriceTypeSupported = false;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// 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]);
}

#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot0
{
get { return Values[0]; }
}

[Description("")]
[Category("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(1, value); }
}
#endregion
}
}

NinjaTrader_Ray
05-24-2008, 06:04 PM
Try deleting this script and start again.

Close it, then select Tools > Edit NinjaScript > Indicator > selec this and press Delete button.

stephenszpak
05-24-2008, 06:34 PM
Try deleting this script and start again.

Close it, then select Tools > Edit NinjaScript > Indicator > selec this and press Delete button.

Clearing the screen doesn't help.

This is the program I wish to use:

//Either/Or decision
int x=1;
if (x==0)
{
Print("Hi");
}
else
{
Print("Buy");
}

>>>>>>>>>>>>> Sorry..

Might be on the wrong screen, but I don't think you want me to delete all
the NinjaTrader indicators??

NinjaTrader_Ray
05-24-2008, 08:28 PM
I wanted you to delete the indicator causing the issue and start from scratch.

Here is a reference for debugging compile errors.

http://www.ninjatrader-support.com/vb/showthread.php?t=4678

stephenszpak
05-24-2008, 08:35 PM
I wanted you to delete the indicator causing the issue and start from scratch.

Here is a reference for debugging compile errors.

http://www.ninjatrader-support.com/vb/showthread.php?t=4678

Ray

Thanks, there is no indicator to my knowledge.
I'm just trying to get some of the simple programs at "Getting Started with NinjaScript-
Basic Syntax" to run. The program below is just 10 lines of code. I think I must
be putting it in the wrong screen or something. Sorry this is so confusing to us.

Is it possible for you to post an image of what I should be seeing on my computer
and also where to add my short program within the image?

-Stephen

NinjaTrader_Ray
05-25-2008, 08:58 AM
Stephen,

What you should be seing is "no errors".

- Shut down NT
- Restart
- Tools > Edit NinjaScript > Indicator
- Select "any" indicator, press F5
---> Does it compile?

- NO, then delete the problem files as per my earlier messages/links
- YES, great then there is no problem

stephenszpak
05-25-2008, 09:47 AM
I hope I uploaded an attachment showing what happened.
I tried 3 indicators. I keep getting CS0116. These are 3 indicators
that came with NT. I have not modified them.

NinjaTrader_Ray
05-25-2008, 05:50 PM
You will see that there is an error in the file "MyCustomIndicator". Please delete this indicator or fix the errors in this indicator. Please review this thread for past information and resource links that I have provided that can help you out.

stephenszpak
05-25-2008, 08:09 PM
You will see that there is an error in the file "MyCustomIndicator". Please delete this indicator or fix the errors in this indicator. Please review this thread for past information and resource links that I have provided that can help you out.

I deleted this indicator, which had no other lines of code besides what
is seen below:

//Either/Or decision
int x=1;
if (x==0)
{
Print("Hi");
}
else
{
Print("Buy");
}

Now I no longer get an error when I press F5 on another indicator.
(Why one bad indicator messes up all the others is quite the mystery.)

I am now back to pretty much where I was.
I have no idea where to place my short program above. Maybe over time
I'll figure it out.

Thanks for trying, I usually have problems with things that require programming.


-Stephen

stephenszpak
05-26-2008, 03:43 AM
Ok I figured it out. This is from the NT site:
----------------------------------------------------------------------------------
Replace the wizard generated code with the following code into the OnBarUpdate() method in the NinjaScript Editor:
----------------------------------------------------------------------------------

I used the above hint to show me where to put my program.

I added my code to this area and the program printed Buy to the NinjaTrader output
window when I ran it.
It printed BUY 20 times or so which I didn't think was supposed to happen.
Well, regardless, I'm a programmer now.

-Stephen