Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy development modes

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

    Strategy development modes

    I have an NT8 strategy that I'd like to analyze, could someone advise me if I have the right steps ...

    1. I need to backtest in NT8

    2. I need to use my Interactive Brokers papertrade account to test in realtime or can I do this also in NT8?

    Thank you.

    #2
    Hello delTik and thank you for your query.

    In order to backtest a strategy, you will need to perform these steps :

    1. NinjaTrader Control Center -> New -> Chart -> Hourglass button near the top -> Select the instrument you would like to add to the chart -> OK -> OK
    2. Strategies button at the top of the chart (a circle) -> double-click your strategy in the upper left -> Configure your strategy with the options on the right -> Check "Enabled" (if you can not check this, connect to your data feed provider) -> Apply -> OK
    3. Right-click on your chart -> Strategy Performance -> <your strategy> -> Real Time and Historical

    You can now review your strategy using the pulldown menu next to "Display". Try for instance selecting "Trades" to see where your strategy performed all its trades. You can right-click any data that you see here and Export it to a Microsoft Excel spreadsheet.


    You can do all this connected to either your Live or Paper Trading accounts with Interactive Brokers, or you can do this purely from within NinjaTrader with the Simulated Data Feed or Market Replay connections. As long as your NinjaTrader Control Center -> Tools -> Global Simulation Mode option is checked, none of the trades your strategy makes will be real trades.


    Please let us know if there is any other way we could help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      thank you.

      can I ask what happens when historical bars process say enterLong()?

      in my strategy should I add a backtest parameter true|false? and ,,,

      to backtest
      if State == State.Historical && backtest == true then enterLong()

      to trade real-time:
      if State == State.Realtime && backtest == false then enterLong()

      or

      to backtest
      if GlobalSimulation enabled && State == State.Historical enterLong() (simulated)

      to trade real-time:
      if GlobalSimulation disabled && State == State.Realtime then enterLong() (real trading)

      (can GlobalSimulation be detected in script?)

      apologies if my question appears basic, still learning.
      Last edited by delTik; 04-21-2016, 08:09 AM.

      Comment


        #4
        Hello delTik,

        Please ask as many questions as you can, we are here and happy to help you learn.

        can I ask what happens when historical bars process say enterLong()
        Here is a quote from the Help Guide section on the EnterLong method

        Originally posted by http://ninjatrader.com/support/helpGuides/nt8/en-us/enterlong.htm
        Definition
        Generates a buy market order to enter a long position.
        in my strategy should I add a backtest parameter true|false?
        I would recommend against this. It's best to have your strategy work the same way in testing as it does live. If you need to set up tests or a test environment, I would recommend using the Tools -> Historical Data Manager to edit historical data so that it matches the conditions you would like to test for.

        If you are just wanting your script to run differently on historical vs live data, I am including a link to the Help Guide section on the State member, with code examples



        to backtest
        if State == State.Historical && backtest == true then enterLong()

        to trade real-time:
        if State == State.Realtime && backtest == false then enterLong()
        First, these will need parenthesis. Second, in NinjaTrader 8, we would like to group all the state logic for a state together. I would recommend the following with all of the above in mind :

        Code:
        [FONT=Courier New]if (State == State.Historical)
        {
            // Code that runs on historical data
            EnterLong();
        }
        else if (State == State.Realtime)
        {
            // Code that runs on live data
            EnterLong();
        }
        [/FONT]
        If you have decided to use your backtest parameter keeping the above in mind, that would instead look like


        Code:
        [FONT=Courier New]if (State == State.Historical)
        {
            if (backtest)
            {
                // Code that runs on historical data
                EnterLong();
            }
        }
        else if (State == State.Realtime)
        {
            if (! backtest)
            {
                // Code that runs on live data
                EnterLong();
            }
        }
        [/FONT]
        can GlobalSimulation be detected in script?
        The variable SimOptions.Options.GlobalSimulationMode should let you know whether you are in Global Simulation Mode.


        to backtest
        if GlobalSimulation enabled && State == State.Historical enterLong() (simulated)

        to trade real-time:
        if GlobalSimulation disabled && State == State.Realtime then enterLong() (real trading)
        These would then become

        Code:
        [FONT=Courier New]if (State == State.Historical)
        {
            if ([/FONT][FONT=Courier New]SimOptions.Options.GlobalSimulationMode)
            {
                // Simulated mode
                EnterLong();
            }
        }
        else if (State == State.Realtime)
        {[/FONT]
        [FONT=Courier New][FONT=Courier New]    if ([/FONT][FONT=Courier New]! SimOptions.Options.GlobalSimulationMode)
            {
        [/FONT]        // Real trading mode
                EnterLong();
            }
        }
        [/FONT]
        Please let us know if there are any other ways we can help.
        Last edited by NinjaTrader_JessicaP; 04-21-2016, 12:13 PM.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          I have to admit getting a bit confused?

          Do you have any guides on testing strategies and running (live) strategies. Backtest, Simulation, Playback, Historical, Realtime, etc - you probably have a way of managing all of this.
          Last edited by delTik; 04-22-2016, 05:03 AM.

          Comment


            #6
            Originally posted by delTik View Post
            I have to admit getting a bit confused?

            Do you have any guides on testing strategies and running (live) strategies. Backtest, Simulation, Playback, Historical, Realtime, etc - you probably have a way of managing all of this.
            Yes. It is called the NT Help manual, and can be accessed with the standard Windows Help function key, F1, from any window in NT while the program is running.

            Comment


              #7
              Originally posted by delTik View Post
              I have to admit getting a bit confused?

              Do you have any guides on testing strategies and running (live) strategies. Backtest, Simulation, Playback, Historical, Realtime, etc - you probably have a way of managing all of this.
              other than the supplied strategies is there any other code I can look at or something that you could recommend?

              I noticed that one strategy has

              if(State == State.Historical)
              return;

              but the others don't and I think this is perhaps what's confusing me? again, apologies if these questions appear as too basic.
              Last edited by delTik; 04-22-2016, 08:04 AM.

              Comment


                #8
                What the lines of code you quoted are doing in plain language is this :

                Code:
                [FONT=Courier New]if (we are processing historical, rather than live, bars)
                don't do anything else;
                [/FONT]
                Please let us know if that helps, or if we can go into further detail to clear the examples up.
                Jessica P.NinjaTrader Customer Service

                Comment


                  #9
                  thanks JessicaP, are there times when you would want to process orders during historical bars?

                  and what does this do

                  if (CurrentBar < BarsRequiredToTrade)
                  return;

                  if I include

                  if(State == State.Historical)
                  return;

                  will that stop trades during backtest?
                  Last edited by delTik; 04-22-2016, 08:16 AM.

                  Comment


                    #10
                    thanks JessicaP, are there times when you would want to process orders during historical bars?
                    There are. Backtesting a strategy against known historical data to see how well it would perform is the most frequent use case.

                    and what does this do

                    if (CurrentBar < BarsRequiredToTrade)
                    return;
                    A lot of strategies and indicators do math to test how values change over time. In order to do so, they need there to be a lot of data points at different points in time to work. This line of code is saying "if we don't yet have enough data points, don't do anything else until we do".
                    Jessica P.NinjaTrader Customer Service

                    Comment


                      #11
                      ok thanks, starting to understand ...

                      so would I need something like

                      if not backtesting and State == State.Historical
                      return;

                      or

                      if !SimOptions.Options.GlobalSimulationMode and State == State.Historical
                      return;

                      and

                      if (CurrentBar < BarsRequiredToTrade)
                      return

                      just makes sure enough data is there for the code to make correct decisions?
                      Last edited by delTik; 04-22-2016, 08:26 AM.

                      Comment


                        #12
                        I believe your understanding is correct. The code I provided earlier does essentially this, with a few key differences :

                        • if statements are going to require ( and ) around the conditions you are testing
                        • because there are a lot of things that you need to do during each state, I broke up

                          if not backtesting and State == State.Historical

                          into

                          if State == State.Historical
                          {
                          if not backtesting :
                          return;
                          // you can do other State == State.Historical stuff here
                          }

                        With this understanding, I would like to ask that you review the code sample I provided earlier again, and let us know if there is anything else we can help clarify.
                        Jessica P.NinjaTrader Customer Service

                        Comment


                          #13
                          ok thanks again JessicaP for your patience, it helps a lot.

                          yes I'm aware of c# code just short handing but does NT have something that will tell me if its backtesting?

                          or does it require a parameter like

                          IncludeHistoricalTrades true|false

                          so when backtesting it would be set to true ...

                          if (State==State.Historical && !IncludeHistoricalTrades)
                          return;
                          Last edited by delTik; 04-22-2016, 10:06 AM.

                          Comment


                            #14
                            koganam is correct though, you need to wade through the manual to start with. Second, download the sample and provided indicators and strategies on this forum. That is how I started. You download, import, and run them on your machine and see how things go together. You will learn lots from this. Third, sign up for Big Mike Trading site too as an Elite member, there are lots of examples there you can download.

                            I would start with NT8 myself if I was starting new. I am sure we are about to get NT8 beta 11 very soon, and this would be a good starting point.

                            Your questions are basic, and expected for someone new to NT, but we do expect you to do your homework too. There is no substitute for wading through this stuff first. Time in.

                            Comment


                              #15
                              Account.Name == "Backtest"

                              works to differentiate Historical bars on a chart from a backtest environment.
                              Jessica P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by burtoninlondon, Today, 12:38 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post burtoninlondon  
                              Started by AaronKoRn, Yesterday, 09:49 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post AaronKoRn  
                              Started by carnitron, Yesterday, 08:42 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Yesterday, 07:51 PM
                              0 responses
                              13 views
                              0 likes
                              Last Post strategist007  
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              44 responses
                              3,982 views
                              3 likes
                              Last Post jhudas88  
                              Working...
                              X