![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Dec 2009
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
|
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 } } |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Dec 2009
Location: Netherlands
Posts: 179
Thanks: 15
Thanked 72 times in 51 posts
|
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 |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Dec 2009
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks for taking a look. Here is the screenshot you requested.
|
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Dec 2009
Location: Netherlands
Posts: 179
Thanks: 15
Thanked 72 times in 51 posts
|
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 |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Dec 2009
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
|
The strategy worked this time. Thank you for your help. Can you suggest any guides on learning Ninjatrader programming?
Last edited by dr0832; 07-22-2012 at 11:16 AM.
|
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Dec 2009
Location: Netherlands
Posts: 179
Thanks: 15
Thanked 72 times in 51 posts
|
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 |
|
|
|
|
|
#7 | |
|
Senior Member
Join Date: Dec 2009
Location: Netherlands
Posts: 179
Thanks: 15
Thanked 72 times in 51 posts
|
Quote:
![]() 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 |
|
|
|
|
|
|
#8 |
|
Junior Member
Join Date: Dec 2009
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
|
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?
Last edited by dr0832; 07-22-2012 at 11:43 AM.
|
|
|
|
|
|
#9 | ||
|
Senior Member
Join Date: Dec 2009
Location: Netherlands
Posts: 179
Thanks: 15
Thanked 72 times in 51 posts
|
Quote:
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:
Marco |
||
|
|
|
|
|
#10 |
|
Junior Member
Join Date: Dec 2009
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
|
How do I undelete it? I think I created that strategy and then in the middle of t I tried to create two new strategies with the same indicators and since they are linked it somehow was preventing me from compiling the original strategy since the other two were not complete. I thought I was suppose to backest on a basket of symbols but maybe I am mistaken. I will try just one symbol and see what happens.
|
|
|
|
|
|
#11 | ||
|
Senior Member
Join Date: Dec 2009
Location: Netherlands
Posts: 179
Thanks: 15
Thanked 72 times in 51 posts
|
Quote:
Quote:
|
||
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
Thanks for the assist marcow!
dr0832, are you able to compile your scripts well now? For the backtesting, you can basket test on the whole index list or on a single symbol. If you test for example the NT inbuild SampleMACrossOver strategy on your data, would you get more significant results reported? Thanks,
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Junior Member
Join Date: Dec 2009
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
|
Yes i believe I would get better results on a basket however I can't seem to get it to backtest correctly.
|
|
|
|
|
|
#14 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
Ok, so what if you backtest our default shipped strategy 'SampleMaCrossOver' - any results seen on your dataset?
Thanks,
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Junior Member
Join Date: Dec 2009
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
|
The backtest works correctly when id that.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |