Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Backtesting and ordering

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

    Backtesting and ordering

    This issue relates to backtesting my strategy only. Real time things work as I expect.
    Currently I use:
    AtmStrategyCreate(OrderAction.Buy,OrderType.Market ,A1M_PENDING_Entry,0,TimeInForce.Day,all_Order_ID, A1M_PENDING_ATM,all_Order_ID);
    To place orders in the strategy.

    Also,
    The order "signal" is produced by an indicator and sent to the strategy via a global string variable.
    public class GlobalString{public static string command = "EMPTY";}

    My question/s:
    1. Is there anything related to using a string command as shown (indicator signals the strat to trade) that will prevent backtesting a strategy using such an approach?
    To be clear, this indicator is NOT being loaded with Initialize (and I don't want that for a host of reasons). Said, indicator sets the GlobalString = BUY and the strategy does the rest.

    2. If I recode and use IOrder instead of AtmStratCreate will that support backtesting?

    Thanks in advance!
    Best regards,
    Sean

    #2
    Hi JohnQ,

    I would not expect that a public string made by an indicator would be updated for your strategy to use in backtest. (Everything in backtest is asynchronous and happens very quickly).

    This is also not supported by NinjaTrader.

    Also, the AtmStrategy commands do not work in backtest or with historical data.
    Yes, if you use IOrders and do the Atm Strategy logic with your code, this will work in backtest.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hi JohnQ,

      I would not expect that a public string made by an indicator would be updated for your strategy to use in backtest. (Everything in backtest is asynchronous and happens very quickly).

      This is also not supported by NinjaTrader.
      Ok,
      I am sorry, the explanation you gave about the string command confuses me.
      My understanding is that code processes line by line, that seems irrespective of "speed" to me. Does NT not process code in written sequence when backtesting?

      That said, what does NT support in the prospect of sending order commands from an indicator to a running strategy? This seems like something folks need to do so along the way I must have missed how NT supports doing this.

      I am not looking for a bunch of code, just a verbal workflow of how this happens. This is important to me because I _NEED_ it to work this way. (indicator tells strategy to "do")

      Thank you for the support and clarification.
      Best regards,
      Sean

      Comment


        #4
        Hello JohnQ,

        No, the OnBarUpdate() method is purely event driven and is asynchronous.

        However, what I am getting at is that if an indicator is setting a value and the indicator itself is not being called from the strategy, it is a separate instance and will run in a separate thread. This means the strategy will not wait for the indicator to set a value.

        When backtesting, strategies are run in a separate thread.

        NinjaTrader allows for you to call an indicator to return a value. You can use this value to trigger an action in a strategy.

        Below is a link to the help guide which demonstrates calling the value of the SMA.
        http://www.ninjatrader.com/support/h...simple_sma.htm
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you for taking the time to help me. Clearly I am doing a poor job of explaining what I am trying to accomplish. Sorry I am doing a poor job.

          The example you provide is about reading a value from an indicator. That I completely understand and do it with my code often...

          At the end of the day what I want is:
          A strategy that does order management only (the management of inputs from several indicators).
          Indicators that tell the strategy it's time to do something.

          NEED:
          The indicator to [tell the strategy something]
          DON"T NEED:
          The strategy to [look at the indicator for the data]

          Those are very different things and I suspect the disconnect in my ability to ask the question better, if NT doesn't support doing that with a Global variable so be it. How does NT support doing that in a way that is backtest-able?

          I am struggling with the concept that all NT has is "go read a plot"....



          Best regards,
          Sean

          Comment


            #6
            Hello JohnQ,

            You will need to set a public variable in your indicator and call this from the strategy. This can be a plot, such as setting the plot to 0, 1, 2, 3, etc and having each value trigger a different action in the strategy. Or you can use any public variable.

            You strategy will make a decision based on the value of the variable using an if statement.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Again, thanks for your continued help.
              Some google searching led me to this:


              Can I do the same thing I currently do with the above mentioned string class?

              If I am reading correctly with regards to the above linked information that approach would support back testing and not be all that much different in concept (as I need it) than what I am doing now.

              I don't see it as a big deal to have a string class declared at the indicator if I call poll the data at will from the strategy. Especially if that gets backtesting to work.

              Sorry for the aspects of my questions that are likely obvious to yourself and others.
              I come from something close to fortran...

              Best regards,
              Sean

              Comment


                #8
                Hi JohnQ,

                Using the StringSeries, BoolSeries, DateTimeSeries, etc classes are all acceptable.

                You can also use a non series variable. You will just need to make sure that you are calling the variable from the indicator.

                For example if you have a variable MyString that is a public variable that is within the scope of the indicator namespace. You can call this with an updated value using:
                string indicatorStringValue = MyIndicatorName(9).MyString;

                By calling the indicator and returning a value, this ensures that the indicator runs before the strategy calls the value for it.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ZeroKuhl, Today, 04:31 PM
                0 responses
                15 views
                0 likes
                Last Post ZeroKuhl  
                Started by Vulgoth_t_Destroyer, 05-09-2022, 04:45 PM
                54 responses
                5,337 views
                0 likes
                Last Post Gaterz
                by Gaterz
                 
                Started by ETFVoyageur, 05-07-2024, 07:05 PM
                11 responses
                76 views
                0 likes
                Last Post -=Edge=-  
                Started by _Zero_, 04-10-2020, 03:21 PM
                145 responses
                7,902 views
                6 likes
                Last Post johng2
                by johng2
                 
                Started by TheTradingMantis, 01-19-2023, 02:05 AM
                43 responses
                923 views
                0 likes
                Last Post jmagaia
                by jmagaia
                 
                Working...
                X