Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

New to strategy wizard

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

    New to strategy wizard

    Hi,

    I am just starting to use NT and am obviously making a few errors creating a strategy using the wizard.

    I want to program the following donchian trend breakout strategy:

    - Enter long trade at 20 day high (but only if 25 day EMA is above 350 day EMA)

    - Enter short trade at 20 day low (but only if 25 day EMA is below 350 day EMA)

    - Exit long trade at 10 day low

    - Exit short trade and 10 day high


    I've clearly got something wrong, as when I backtest there are no results. Here is the code that the wizard produced for me, it would be great if you could tell me where I'm going wrong!:


    Description("Enter the description of your strategy here")]
    public class DONCHIAN : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int dAY20HIGH = 20; // Default setting for DAY20HIGH
    private int dAY20LOW = 20; // Default setting for DAY20LOW
    private int dAY10LOW = 10; // Default setting for DAY10LOW
    private int dAY10HIGH = 10; // Default setting for DAY10HIGH
    private int eMA25 = 25; // Default setting for EMA25
    private int eMA350 = 350; // Default setting for EMA350
    // 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(DonchianChannel(20));
    Add(DonchianChannel(20));

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (EMA25 > EMA350
    && DAY20HIGH > DonchianChannel(20).Upper[0]
    && EMA25 == EMA(25)[0]
    && EMA350 == EMA(350)[0])
    {
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if (EMA25 < EMA350
    && DAY20LOW < DonchianChannel(20).Lower[0]
    && EMA25 == EMA(25)[0]
    && EMA350 == EMA(350)[0])
    {
    EnterShort(DefaultQuantity, "");
    }

    // Condition set 3
    if (DAY10LOW == LowestBar(DefaultInput, 10)
    && Position.MarketPosition == MarketPosition.Long)
    {
    ExitLong("", "");
    }

    // Condition set 4
    if (DAY10HIGH == HighestBar(DefaultInput, 10)
    && Position.MarketPosition == MarketPosition.Short)
    {
    ExitShort("", "");

    #2
    roq1000,

    First, welcome to the NinjaTrader Support Forums.

    What exactly is the behavior you are seeing instead when you say "it is wrong"?
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hi there,

      thanks for the quick response. No matter which instrument/stock I bactest the system on, I'm not getting any results - i.e. no trades are being taken - all the results stay at zero...? I must be doing something wrong I guess!

      Many thanks,
      Robbie

      Comment


        #4
        Robbie,

        Do you have data yet? You would need to be connected to a data provider.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Hi Josh,

          I do have data, I'm connected to yahoo and when I click on the chart tab it shows that...?

          Thanks for any advice you may be able to give!

          Robbie

          Comment


            #6
            roq1000,

            Quick test to see if strategy will work, add strategy to an open chart with a couple days of historical data, maybe 40 days in your case.

            If you see trades show up on the chart, backtesting should work.

            RJay
            RJay
            NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

            Comment


              #7
              Robbie,

              Please also ensure you are backtesting on daily time frame because Yahoo only provides you with daily data.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Many thanks for the replies so far, but having tried all suggestions, it's still not working. Any other ideas as to what can be wrong would be appreciated!

                Thanks,
                Robbie

                Comment


                  #9
                  Try to run a backtest on SampleMACrossOver. Does that work? If not then you are having data issues for sure and not strategy issues.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Josh, it works for the sampleMAcrossover. That's what made me think somehow I had got the strategy wrong. But I've downloaded a few other strategies from the internet though, written by people who presumably know Ninjatrader backwards and they aren't showing any results either!

                    I'd appreciate any other ideas you come up with that I can try/what setting I may have wrong.



                    Thanks for your patience!

                    Robbie

                    Comment


                      #11
                      Please provide exact steps of what you are doing.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks Josh, I'll send those over as soon as I've written them up!

                        Robbie

                        Comment


                          #13
                          Hi,

                          I start ninjatrader. Connect to Yahoo (File > Connect > Yahoo) The I go to File > New > Strategy Analyser. Then right-click on a stock and select backtest. Select a strategy from the drop-down list and make sure the data type is set to `day'. It works with sampleMAcrossover, but for all the other strategies (even the preinstalled samples), all the columns remain at zero. This is even the case if I select a simulated feed instead!

                          Do you think I should uninstall the software and reinstall it, in the hope that it might then work?

                          It's very frustrating.

                          Thansk for your help!

                          Comment


                            #14
                            roq1000,

                            Simulated feed will not provide you any historical data.
                            The only prebuilt strategy worthwhile for testing is the SampleMACrossOver. The rest are technical samples and not meant for backtesting.

                            You should check your Control Center logs for errors. Once you have connected to Yahoo and downloaded at least a years worth of daily data for the instrument you want to backtest on, disconnect from Yahoo.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Josh,

                              I've tried disconnecting from yahoo (after doiwnloading 10 years data) and the backtest still isn't giving any results! If you have any other things I can try, please let me know - I really can't get on with anything with this problem persisting. It couldn't be my coding could it - the code I posted a few days ago in this thread looks OK, does it?

                              There are no errors in the log.

                              Thanks,
                              Rob

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by BarzTrading, Today, 07:25 AM
                              2 responses
                              24 views
                              1 like
                              Last Post BarzTrading  
                              Started by devatechnologies, 04-14-2024, 02:58 PM
                              3 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by tkaboris, Today, 08:01 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post tkaboris  
                              Started by EB Worx, 04-04-2023, 02:34 AM
                              7 responses
                              163 views
                              0 likes
                              Last Post VFI26
                              by VFI26
                               
                              Started by Mizzouman1, Today, 07:35 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X