Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need some help debuging my first basic strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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 Files

    #2
    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

    Comment


      #3
      Thanks for taking a look. Here is the screenshot you requested.
      Attached Files

      Comment


        #4
        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

        Comment


          #5
          The strategy worked this time. Thank you for your help. Can you suggest any guides on learning Ninjatrader programming?
          Attached Files
          Last edited by dr0832; 07-22-2012, 11:16 AM.

          Comment


            #6
            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

            Comment


              #7
              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

              Comment


                #8
                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 Files
                Last edited by dr0832; 07-22-2012, 11:43 AM.

                Comment


                  #9
                  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 ?


                  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

                  Comment


                    #10
                    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.

                    Comment


                      #11
                      How do I undelete it
                      Unless you shift-deleted the file, in the windows explorer window rightclick -undo delete- ? Or maybe the file is still in the recycle bin ?

                      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
                      Very unlikely that was the cause of the problem.

                      Comment


                        #12
                        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,

                        Comment


                          #13
                          Yes i believe I would get better results on a basket however I can't seem to get it to backtest correctly.

                          Comment


                            #14
                            Ok, so what if you backtest our default shipped strategy 'SampleMaCrossOver' - any results seen on your dataset?

                            Thanks,

                            Comment


                              #15
                              The backtest works correctly when id that.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              666 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              376 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              110 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              575 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              580 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X