Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop strategy executing historical data

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

    Stop strategy executing historical data

    Sorry this is probably a really silly question, so I've got my demo account setup using current data, when I load a chart it loads historical data, which I want.....Like 3 days worth, but I don't want the strategy when its enabled to place a historical order per say.

    ie, AUDUSD is enabled, strategy is turned on and it has a order that was done on Friday. But it doesn't have an actually position, because it can't because it happened on Friday. I've setup an option to say don't execute live orders until flat.

    If I click "Flatten Everything" does that remove historical order and keep the strategies enabled?

    Man difference between live & replay data is huge I've had to re-write the code for my entries and everything!

    #2
    Hello happypappy,

    Thank you for your post.

    To prevent trades on historical data, just set the following at the beginning of the OnBarUpdate():
    Code:
    if(Historical)
    return;
    For information on Historical please visit the following link: http://www.ninjatrader.com/support/h...historical.htm

    Comment


      #3
      Patrick,

      Does this allow it to load previous data? I require 30 60min bars before it start trading, if I load 3 days historically it avoids a 30hr delay. I basically just don't want it to start entering until the data is live.

      Comment


        #4
        Yes, the data would be loading still as specified. What this check would avoid is seeing OnBarUpdate() calls on historical data.

        Comment


          #5
          So a combination of the following is still ok?

          Code:
          if(CurrentBar[0] <= 30 | CurrentBar[1] <=30)
          {
             return;
          }
          if(Historical)
          {
             return;
          }
          Ive had to change a few things to get the live code working, exciting times though :P

          Comment


            #6
            Hello happypappy,

            There are some syntax errors with your statement.

            If you are using a multi-timeframe strategy, then CurrentBar[0] should be CurrentBars[0], simlary CurrentBars[1], please see: http://www.ninjatrader.com/support/h...urrentbars.htm

            The use of a single"|" does not work, you need the "double pipes", || for the correct OR syntax. However, when checking CurrentBars it is better to use the AND logic, "&&" as you typically would not proceed until you had the minimum data loaded to do some function. So for example if using a 30 period SMA the currentBar check prevents the indicator from trying to access bar data when there isn't any prior to the 30th bar.

            Using the if (Historical) return statement says you do not want to perform any action below the line until you have live data.

            Comment


              #7
              Thanks, I moved the historical part to just before my entries. So basically it calculates the all sections within OnBarUpdate then prevents the order from taking place until the data is live.
              Last edited by happypappy; 11-17-2014, 06:11 PM.

              Comment


                #8
                Hello i want to clarify on the below on if (Historical) being used or not.

                In testing a strategy it helps to see the text markets on the historical where the strategy submits orders and the results of this. I considered adding a parameter to set to go through historical if in test mode and to NOT if live ie if running live the if (Historical) would be checked at the beginning.

                In going live the historical matters not but i want to check that if i dont include this check at top of onBarUpdate() or other location in code before it submits orders :

                is there a danger that orders are submitted on historical data?

                using 'wait until flat before executing live' is the option i would likely use with sync account position = false

                I am going over and over the documentation which can be a bit confusing in places

                any reassurance on this would be appreciated

                Comment


                  #9
                  Originally posted by soulfx View Post
                  Hello i want to clarify on the below on if (Historical) being used or not.

                  In testing a strategy it helps to see the text markets on the historical where the strategy submits orders and the results of this. I considered adding a parameter to set to go through historical if in test mode and to NOT if live ie if running live the if (Historical) would be checked at the beginning.

                  In going live the historical matters not but i want to check that if i dont include this check at top of onBarUpdate() or other location in code before it submits orders :

                  is there a danger that orders are submitted on historical data?

                  using 'wait until flat before executing live' is the option i would likely use with sync account position = false

                  I am going over and over the documentation which can be a bit confusing in places

                  any reassurance on this would be appreciated
                  Hey mate, so I set it up to not place orders in historical data, using it live as well. This allows me to load say 5 days of data and the strategy only orders on active days, but loads all information prior to starting.

                  In my code the *maths* per say that determines when to enter etc is sitting outside of the Historical section, and the orders are within it.

                  Comment


                    #10
                    Thanks i did that yesterday bracketed the area for the 'maths' and previous bar data i need to submit orders and bracket the actual order submission within the If Historical.

                    What i wanted to more clearly understand that is lacking in the documentation is what would happen if you did not have that statement would the strategy try to fire orders on old data ie previous time? This isnt clear add to the fact they have settings in options ie 'wait til flat'.

                    To my mind why would you want to fire orders on historical data in the first place and i would expect the strategy manager to have the intelligence of what is past and now live?
                    So it seems we need to put in the safeguard ourselves.

                    Yes for test mode we want to see what orders 'would have been' submitted and i have added a parameter to denote if in live or test mode.

                    Thanks for help on this but would like some clarification from ninja as to why - perhaps the strategy manager has no way of knowing if it is live data or history and needs this setting. If that is the case then i will accept that is how it is. Id rather not find out the consequences of running live without it and would like some more information on this having searched around. Im noticing and realising the strategy documentation on going live and what to be mindful of is scattered and actually not well presented in a coherent manner.

                    thanks happy over to ninja

                    Comment


                      #11
                      Hello Happypappy and soulfx,

                      Thanks for the posts, questions and discussion.

                      Under Tools>Options>Strategies>Ninjascript are two selections for how a real time (live) strategy starts up, "wait until flat before executing live" and "Immediately submit live working historical orders"

                      Regarding "Wait until flat before executing live" the help guide advises: "When starting a NinjaScript strategy that relies on historical data for calculating its current positions and order states, it will wait until the strategy position has reached or crossed a flat position before executing any live orders. All trading done before this condition will be virtual, simulated trades."

                      Regarding, "Immediately submit live working historical orders", the help guide advises: "When starting a NinjaScript strategy that relies on historical data for calculating its current position and orders states, it will immediately submit live any working orders that reflect the current strategy's overall order state. It is IMPORTANT to understand that the position of the strategy reported in the Strategies tab may not reflect the actual account-based position reported in the Accounts tab at the time the strategy is started. In this scenario, it is highly recommend that the account position be synced to the strategy position."

                      (Here is the link to the relevant help guide section: http://www.ninjatrader.com/support/h...tegies_tab.htm)

                      To complete the information, please also review these two sections:



                      Comment


                        #12
                        Thanks Paul but i was hoping for a bit more in the way of a reply to my question and examples and not just a cut and paste and referral to document links i have read numerous times.
                        For example the limitation of a strategy not being able to query the account position on startup (informed with be available in NT8) has to my mind led to these 'workarounds' to manage a strategy position. I still am not clear on a few things here - if i have worked on complex bank systems and cannot decipher this it makes me wonder how others can follow all of this - perhaps it is just me.
                        I dont feel this is well presented - it is wordy and not coherently presented and i know for a fact a colleague whose english is good but not 100% (ie not native) struggles to comprehend the wordy notation. Is this written for traders or programmers - i would like it written from a traders perspective and with clearer examples of why you would do this; yes there are brief vague examples but its not enough.

                        Can you please read my question before and see that your links to help do not answer them.
                        Ill take this as a point to suggest NT8 enhances the documentation for this kind of thing. Yes it is critical to understand as you state at beginning of these links thus please make it clearer.

                        thanks

                        Comment


                          #13
                          Thank you for providing your feedback on our documentation. I am one of the team members responsible for writing and updating the information for the upcoming release of NinjaTrader 8 and I'll be sure to review this area of our documentation with your comments in mind.

                          Originally posted by soulfx View Post
                          What i wanted to more clearly understand that is lacking in the documentation is what would happen if you did not have that statement would the strategy try to fire orders on old data ie previous time? This isnt clear add to the fact they have settings in options ie 'wait til flat'.
                          If you did not return on historical data, your strategy will simply process as it does in a backtest. The wait until flat/immediately submit option will just work to determine at which point it starts executing live orders when live data is received.

                          'Wait until flat' will not submit any sort of additional orders that may be used to manage your position until the strategy has determined it would be flat. This would be from use of exit orders you have programmed. The risk of using this option is if you have not exited your position via code, and a new entry condition is satisfied, but your strategy is waiting until it is flat, it would not take the new position. You can simply return on historical data for the order management section of your strategy with this setting to prevent this from happening.

                          In contrast, using 'Immediately submit' your strategy will take position as it has been programmed based on your strategy rules. Any 'Exit' orders would be processed immediately and used against your live account. This could potentially put in an unwanted position and get your strategy out of sync, so this is why you would want to add additional logic to your specific strategy to handle these scenarios.

                          Originally posted by soulfx View Post
                          To my mind why would you want to fire orders on historical data in the first place and i would expect the strategy manager to have the intelligence of what is past and now live?
                          So it seems we need to put in the safeguard ourselves.
                          One common example is for position or risk management. If your strategy uses historical performance to determine how and when to fire new orders, you would want the strategy to process orders as they do in the backtest up until the point your strategy was started. If this historical market performance was not ideal for your strategy rules, you may not want it to fire live orders. On the other hand, the historical performance of your strategy may determine that the current market conditions favor your strategy, so in that case you would want it to place these live orders.

                          More importantly, these strategy options processes historical orders and positions to help manage your strategy in the case you need to restart. For example, if you were running your strategy starting at 9:30AM and at 10AM, you were in position with a few conditional orders to protect it and at this time, your computer crashes or your internet goes out, at the time you recover and restart the strategy, it would be helpful to know what position your strategy 'should' be in order to properly calculate and manage your position.

                          Another important reason is in the common case that your strategy was started in the middle of what would be considered a position. Depending on your strategy, you may get several conditions throughout the day that would trigger an entry order. These conditions can also be true in the middle of a position. If your strategy is programmed to only take position on the first condition, and ignore other triggers while your strategy is in position, the historical processing is helpful in ensuring your strategy does not take orders unexpectedly. Another reason I can think of off the top of my head is that you may want to scale in or scale out during these periods, however if you were not in position to begin with, it would not make sense for this position management logic to take place. If you used 'Wait until flat' in this case, it would not do so until the strategy was finally flat.
                          Last edited by NinjaTrader_Matthew; 12-11-2014, 09:42 AM.
                          MatthewNinjaTrader Product Management

                          Comment


                            #14
                            Thank you for providing your feedback on our documentation. I am one of the team members responsible for writing and updating the information for the upcoming release of NinjaTrader 8 and I'll be sure to review this area of our documentation with your comments in mind.
                            If you did not return on historical data, your strategy will simply process as it does in a backtest. The wait until flat/immediately submit option will just work to determine at which point it starts executing live orders when live data is received.
                            'Wait until flat' will not submit any sort of additional orders that may be used to manage your position until the strategy has determined it would be flat. This would be from use of exit orders you have programmed. The risk of using this option is if you have not exited your position via code, and a new entry condition is satisfied, but your strategy is waiting until it is flat, it would not take the new position. You can simply return on historical data for the order management section of your strategy with this setting to prevent this from happening.
                            Regarding above do you mean if on processing historical and through programming error and exit was missing or not fired it could leave open position albeit on historical and thus render strategy not flat and not able to proceed on live real time data?
                            By including the If (Historical) on order section this would mitigate this issue?

                            In contrast, using 'Immediately submit' your strategy will take position as it has been programmed based on your strategy rules. Any 'Exit' orders would be processed immediately and used against your live account. This could potentially put in an unwanted position and get your strategy out of sync, so this is why you would want to add additional logic to your specific strategy to handle these scenarios.
                            One common example is for position or risk management. If your strategy uses historical performance to determine how and when to fire new orders, you would want the strategy to process orders as they do in the backtest up until the point your strategy was started. If this historical market performance was not ideal for your strategy rules, you may not want it to fire live orders. On the other hand, the historical performance of your strategy may determine that the current market conditions favor your strategy, so in that case you would want it to place these live orders.
                            Interesting idea - i presume if i wanted to determine the strategy position on the historical you use the Performance.AllTrades to access the trades. So for example i have a pre session period or 1 day prior of historical i could assess the performance profit / loss and use the value of this to determine whether to proceed this trading day with the live data. I notice the first real time trades could contain a synthetic entry execution if the strategy was not flat at time you start the strategy - again is this to catch out potential errors in logic where exit orders arent processed in the historical backtest processing before live entries. I see there are subtleties to this i hadnt appreciated so thank you for taking the time to elaborate. In away the documentation presently doesnt do justice to the capabilites of the historical feature as it is lacking in examples which stirs ideas and creativity. Perhaps this is covered in the educational sessions somewhere.

                            More importantly, these strategy options processes historical orders and positions to help manage your strategy in the case you need to restart. For example, if you were running your strategy starting at 9:30AM and at 10AM, you were in position with a few conditional orders to protect it and at this time, your computer crashes or your internet goes out, at the time you recover and restart the strategy, it would be helpful to know what position your strategy 'should' be in order to properly calculate and manage your position.
                            Another important reason is in the common case that your strategy was started in the middle of what would be considered a position. Depending on your strategy, you may get several conditions throughout the day that would trigger an entry order. These conditions can also be true in the middle of a position. If your strategy is programmed to only take position on the first condition, and ignore other triggers while your strategy is in position, the historical processing is helpful in ensuring your strategy does not take orders unexpectedly. Another reason I can think of off the top of my head is that you may want to scale in or scale out during these periods, however if you were not in position to begin with, it would not make sense for this position management logic to take place. If you used 'Wait until flat' in this case, it would not do so until the strategy was finally flat.
                            thank you for taking the time to cover this and hopefully others will benefit from this too.
                            I will await response to above before other questions i may have but want to distill this information.

                            thanks you appreciated

                            Comment


                              #15
                              Hello,

                              Regarding above do you mean if on processing historical and through programming error and exit was missing or not fired it could leave open position albeit on historical and thus render strategy not flat and not able to proceed on live real time data?
                              By including the If (Historical) on order section this would mitigate this issue?
                              Correct. When you enable the strategy it will process the historical data just like a back test up the most recent bar. If there is a left open position when it hits the last bar this will cause the strategy to be a yellow state on the Strategies Tab, meaning it is waiting to be flat state before processing live.
                              Using if(Historical) return; will stop the strategy from processing historical data and only focus on the live data.

                              Interesting idea - i presume if i wanted to determine the strategy position on the historical you use the Performance.AllTrades to access the trades. So for example i have a pre session period or 1 day prior of historical i could assess the performance profit / loss and use the value of this to determine whether to proceed this trading day with the live data.
                              You are correct here as well. This will allow you to determine the prior performance and if the performance is good enough to continue trading or to stop.

                              Let me know if I can be of further assistance.
                              Cal H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              673 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              379 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              111 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              578 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              582 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X