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 > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 07-21-2012, 04:22 PM   #1
dr0832
Junior Member
 
Join Date: Dec 2009
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
Default Need some help debuging my first basic strategy

I am a complete beginner to programming. I am trying to create a basic ATM strategy in Ninjatrader 7 using the new strategy wizard. For some reason I am getting and error
which I have included in a jpg screenshot, on the following line below once I view the code. Can anyone help me out?

if (CrossAbove(T3(MyInput0, 3, 0.7), T3(MyInput1, 3, 0.7), 1)





------------------------------------------------------------------------------------------------
{
/// <summary>
/// Test Strategy
/// </summary>
[Description("Enter the description of your strategy here")]
public class MyCustomStrategy : Strategy
{
#region Variables
// Wizard generated variables
private int myInput0 = 50; // Default setting for MyInput0
private int myInput1 = 100; // Default setting for MyInput1
private int myInput2 = 20; // Default setting for MyInput2
// User defined variables (add any user defined variables below)
#endregion

/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
Add(T3(MyInput0, 3, 0.7));
Add(T3(MyInput1, 3, 0.7));
SetProfitTarget("buy", CalculationMode.Percent, 20);
SetStopLoss("buy", CalculationMode.Percent, 10, false);

CalculateOnBarClose = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(T3(MyInput0, 3, 0.7), T3(MyInput1, 3, 0.7), 1)
&& Close[0] < Bollinger(2, MyInput2).Lower[0])
{
EnterLong(DefaultQuantity, "buy");
}

// Condition set 2
if (T3(MyInput0, 3, 0.7)[0] <= T3(MyInput1, 3, 0.7)[0]
&& Close[0] == Bollinger(2, MyInput2).Lower[0])
{
ExitLong("sell", "buy");
}
}

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

[Description("")]
[GridCategory("Parameters")]
public int MyInput1
{
get { return myInput1; }
set { myInput1 = Math.Max(1, value); }
}

[Description("")]
[GridCategory("Parameters")]
public int MyInput2
{
get { return myInput2; }
set { myInput2 = Math.Max(1, value); }
}
#endregion
}
}
Attached Images
File Type: jpg ninjatrader error.jpg (84.6 KB, 5 views)
dr0832 is offline  
Reply With Quote
Old 07-21-2012, 04:56 PM   #2
marcow
Senior Member
 
Join Date: Dec 2009
Location: Netherlands
Posts: 179
Thanks: 15
Thanked 72 times in 51 posts
Default

hello dr0832,

I just took a look at the code you posted and couldn't find anything wrong. To be sure I recreated the startegy in the strategywizard and I get no errors when I compile, your code is fine.

Having said that the error must be from something else, like another indicator or strategy that failed to compile.Can you re-post an image of the error with all the left-side colums visible ?

Marco
marcow is offline  
Reply With Quote
Old 07-22-2012, 08:44 AM   #3
dr0832
Junior Member
 
Join Date: Dec 2009
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks for taking a look. Here is the screenshot you requested.
Attached Images
File Type: jpg ninjatrader error1.jpg (133.6 KB, 4 views)
dr0832 is offline  
Reply With Quote
Old 07-22-2012, 10:57 AM   #4
marcow
Senior Member
 
Join Date: Dec 2009
Location: Netherlands
Posts: 179
Thanks: 15
Thanked 72 times in 51 posts
Default

Thank you,

The error is indeed in your strategy and not somewhere else.

However, as I mentioned before, I duplicated the code you posted into a strategy, and it worked fine on my computer. I attached this stratgey (qqq.cs) including all the required indicators. I suggest you import this strategy, so we are using the same code for further dubugging.

Don't know if you're familiar with importing code into NT, so here's a howto:
In the control panel, go to File/Utilities/Import NinjaScript and select the attached file (which of course you first downloaded to your computer) Do not unzip !
A popup window will come up asking if you would like to overwrite indicators.I suggest you overwrite at least the T3 indicator. No need overwriting the system indicators - the ones with "@".
You will now see the strategy in your list named as "qqq.cs"

let me know if it worked.

Marco
Attached Files
File Type: zip test.zip (11.8 KB, 8 views)
marcow is offline  
Reply With Quote
Old 07-22-2012, 11:07 AM   #5
dr0832
Junior Member
 
Join Date: Dec 2009
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
Default

The strategy worked this time. Thank you for your help. Can you suggest any guides on learning Ninjatrader programming?
Attached Images
File Type: jpg ninja import error.jpg (38.0 KB, 3 views)
Last edited by dr0832; 07-22-2012 at 11:16 AM.
dr0832 is offline  
Reply With Quote
Old 07-22-2012, 11:14 AM   #6
marcow
Senior Member
 
Join Date: Dec 2009
Location: Netherlands
Posts: 179
Thanks: 15
Thanked 72 times in 51 posts
Default

that's because there is an error in your strategy. (Or another one )
In NT all indicators/strategy's are "linked" so if there is only one indicator/strategy with erros, nothing will work.

To resolve this issue, go to the directory where the strategy's are located:
C:\Users\marco\Documents\NinjaTrader 7\bin\Custom\Strategy (replace marco with your own windows-username ) and find your strategy ( I believe it's called myfirtsstrategy.cs ,was it ?)
Now temporarily rename it to myfirtsstrategy.aaa

Now you should be able to import.

Marco
marcow is offline  
Reply With Quote
Old 07-22-2012, 11:29 AM   #7
marcow
Senior Member
 
Join Date: Dec 2009
Location: Netherlands
Posts: 179
Thanks: 15
Thanked 72 times in 51 posts
Default

Quote:
Originally Posted by dr0832 View Post
The strategy worked this time. Thank you for your help. Can you suggest any guides on learning Ninjatrader programming?
The key to learning NT programming imo is understanding why things didn't work

Does your original strategy work now, or are you using the one I created (qqq.cs) ?
If you undo the rename of your original strategy -see my previous post- do you get the error again when compiling, or is it fine now ?

Marco
marcow is offline  
Reply With Quote
Old 07-22-2012, 11:34 AM   #8
dr0832
Junior Member
 
Join Date: Dec 2009
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
Default

I deleted my original strategy and then everything worked. Now the only problem is I just tried to run a backtest on the NASDAQ 100 using this strategy on historic data and when the backtest finished running it showed all of the 100 symbols but all the stats just say 0.00 0.00 0.00 1.00 .000% etc. Why would this be?
Attached Images
File Type: jpg backtest1.jpg (172.8 KB, 4 views)
Last edited by dr0832; 07-22-2012 at 11:43 AM.
dr0832 is offline  
Reply With Quote
Old 07-22-2012, 11:53 AM   #9
marcow
Senior Member
 
Join Date: Dec 2009
Location: Netherlands
Posts: 179
Thanks: 15
Thanked 72 times in 51 posts
Default

Quote:
I deleted my original strategy and then everything worked
Can you undelete your original strategy and check if it now also works, otherwise we will never know what was wrong ?
Are there any differences in code between your original strategy and the one I posted ? Can you post your original strategy so I can take a look at it ?


Quote:
Now the only problem is I just tried to run a backtest on the NASDAQ 100 using this strategy on historic data and when the backtest finished running it showed all of the 100 symbols but all the stats just say 0.00 0.00 0.00 1.00 .000% etc. Why would this be?
I don't have experience with the Nasdaq100, I only trade futures. But shouldn't you run a backtest on each symbol individually instead of all 100 at once ?



Marco
marcow 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with basic SMA Crossover strategy kemosabe Automated Trading 9 04-26-2012 12:48 PM
basic strategy wizard features anniebee Suggestions And Feedback 1 07-11-2010 09:30 AM
Combining Basic Halt strategy with another strategy? Ninja B Automated Trading 1 07-18-2008 01:11 AM
Basic TRIN strategy alfie Strategy Development 4 05-11-2008 06:32 AM
basic help on program a strategy z32000 Strategy Development 10 11-23-2007 07:59 PM


All times are GMT -6. The time now is 08:45 AM.