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

Overwrite Price Data within the strategy

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

    Overwrite Price Data within the strategy

    Hi,

    I tried to overwrite price data within OnBarUpdate
    by a syntax like this:
    Open[0]= some double value
    Seems like those data are read only.

    Any way to accomplish that?
    If not, I need another approach to do the following:
    I want to test strategies on a high number of random price data.
    Therefore manually generating those data, setting up instruments and importing
    those data by txt-files is not the way to go.

    I need a way to automatically create (and import, if necessary) the price data everytime a strategy script is executed.

    Thanks in advance for any recommendations.

    #2
    Originally posted by Stephan123 View Post
    Hi,

    I tried to overwrite price data within OnBarUpdate
    by a syntax like this:
    Open[0]= some double value
    Seems like those data are read only.

    Any way to accomplish that?
    If not, I need another approach to do the following:
    I want to test strategies on a high number of random price data.
    Therefore manually generating those data, setting up instruments and importing
    those data by txt-files is not the way to go.

    I need a way to automatically create (and import, if necessary) the price data everytime a strategy script is executed.

    Thanks in advance for any recommendations.
    Seems a bit strange that you want to generate random price data for Strategy testing, when you have actual data available. However, if that is what you want to do, then you will have to generate your own ohlc data, by creating and populating 4 separate DataSeries. If you want to generate charts from the data, you will need to use a Custom Plot.

    Comment


      #3
      Originally posted by koganam View Post
      However, if that is what you want to do, then you will have to generate your own ohlc data, by creating and populating 4 separate DataSeries. If you want to generate charts from the data, you will need to use a Custom Plot.
      How to "tell" NT within the strategy script, that the created data series are the new OHLC-data? NT has to use them for placing exits, entries and calculation of trade performance.

      Comment


        #4
        Originally posted by Stephan123 View Post
        How to "tell" NT within the strategy script, that the created data series are the new OHLC-data? NT has to use them for placing exits, entries and calculation of trade performance.
        No need to. It is what it is. You code to your ersatz DataSeries instead of the the original OHLC data.

        If you call your ersatz close MyClose for example, then you code your Strategy to make decisions based on the value of MyClose[0] instead of Close[0] etc.. An entry is an entry; an exit is an exit. NT will calculate statistics based on the entries and the exits, not on the DataSeries that is the basis of the entries and exits.

        Comment


          #5
          Originally posted by koganam View Post
          No need to. It is what it is. You code to your ersatz DataSeries instead of the the original OHLC data.

          If you call your ersatz close MyClose for example, then you code your Strategy to make decisions based on the value of MyClose[0] instead of Close[0] etc.. An entry is an entry; an exit is an exit. NT will calculate statistics based on the entries and the exits, not on the DataSeries that is the basis of the entries and exits.
          To my knowledge entriey exits are always based on a dataseries contained in BarsArray.
          By default the primary barsobject is used. It's possible to generate signals
          based on custum dataseries, but entry and exit prices will always be calculated
          based on the price data! E.G., if the value of "MyOpen" is 2000 and the value of the primary bars object Open[0]=3000, Entry price will be 3000 and not 2000.
          Therefore the suggested approach wouldn't work, as far as my knowledge goes.

          Comment


            #6
            Originally posted by Stephan123 View Post
            To my knowledge entriey exits are always based on a dataseries contained in BarsArray.
            By default the primary barsobject is used. It's possible to generate signals
            based on custum dataseries, but entry and exit prices will always be calculated
            based on the price data! E.G., if the value of "MyOpen" is 2000 and the value of the primary bars object Open[0]=3000, Entry price will be 3000 and not 2000.
            Therefore the suggested approach wouldn't work, as far as my knowledge goes.
            Entries and exits are at the stated price. Whatever you state is the price you want to buy or sell at is the price at which the order is entered.

            Are you saying that if you make an order to enter at 1200, NT will enter you at 1257 (for example), because that is the Open or whatever of the bar? That makes no sense. You state the limit price you want; that is the price you get. Market orders are a different kettle of fish.

            Comment


              #7
              Originally posted by koganam View Post
              Are you saying that if you make an order to enter at 1200, NT will enter you at 1257 (for example), because that is the Open or whatever of the bar? That makes no sense. You state the limit price you want; that is the price you get. Market orders are a different kettle of fish.
              When using limit orders in managed approach for long entries,
              they will be automatically canceled if the the real Close of the bar where the order is submitted at is higher than the Limit.
              Stop orders for long entries will be canceled if the Stop is lower than the Close of the order submitting bar.

              Furthermore, if the real price data have gaps at the stop and limit prices, the fill wouldn't happen at the specified limits.

              At least in my opinion it's not that easy.
              But may be there is an easy way of solving those problems I'm not aware of?

              Comment


                #8
                Originally posted by Stephan123 View Post
                When using limit orders in managed approach for long entries,
                they will be automatically canceled if the the real Close of the bar where the order is submitted at is higher than the Limit.
                Stop orders for long entries will be canceled if the Stop is lower than the Close of the order submitting bar.

                Furthermore, if the real price data have gaps at the stop and limit prices, the fill wouldn't happen at the specified limits.

                At least in my opinion it's not that easy.
                But may be there is an easy way of solving those problems I'm not aware of?
                You can always use LiveUntilCanceled.

                Regardless, I am still not getting the point. If you want to use random values rather than the real prices, NT already provides the Simulated Feed that does that. Now if you want to generate your own prices (as opposed to just OHLC values), then you are going to have to construct your own data feed (essentially little different from the NT Simulated Feed), and connect to your custom feed as the data source. In which event, of course, all processing will be relative to that data source that you have created. I believe that is the purpose of the Data source labeled External ?

                Comment


                  #9
                  Can the simulated feed be used within backtests with the free NT-version?
                  I prefer / need during the backtest "live" created random data.
                  Everytime the backtest is run the data needs to be different
                  and automatically being created.
                  LiveUntilCanceled is my standard setting and it does not stop NT from discarding the orders directly after placement if one of the above mentioned conditions is true.

                  Comment


                    #10
                    Originally posted by Stephan123 View Post
                    Can the simulated feed be used within backtests with the free NT-version?
                    I prefer / need during the backtest "live" created random data.
                    Everytime the backtest is run the data needs to be different
                    and automatically being created.
                    LiveUntilCanceled is my standard setting and it does not stop NT from discarding the orders directly after placement if one of the above mentioned conditions is true.
                    Not for BackTests. BackTesting uses historical data.

                    The Simulated Feed is used for quasi-live (dry run) testing under controlled conditions (mainly being able to set the strength of the trend).

                    Comment


                      #11
                      Originally posted by koganam View Post
                      Not for BackTests. BackTesting uses historical data.

                      The Simulated Feed is used for quasi-live (dry run) testing under controlled conditions (mainly being able to set the strength of the trend).
                      My question is regarding backtests, though.

                      Comment


                        #12
                        I will do some checking tomorrow but you should be able to 'Data Scramble' your existing data in a spread sheet. You can export your data to excel or other similar product and use the sampling function, you will only need OHLC of ea bar.

                        Relationship between the 2nd bar and the first using the close of the first as the ref.

                        delta O = O - C[1],
                        delta H = H - C[1],
                        delta L = L - C[1],
                        delta C = C - C[1].

                        use a random number generator to scramble bars, once you have a new sequence start with the prior close.

                        new bar is derived from the prior close thus

                        new C = C[1] + delta C,
                        new H = C[1] + delta H,
                        new L = C[1] + delta L,
                        new O = C[1] + delta O.

                        new data can then be imported into NT and used for testing.

                        I can give you the full system tomorrow some time.

                        Comment


                          #13
                          Thanks, but that's not what I look for, as described in the first post.
                          I need a method to live-generate the price data, since I will conduct a very large number of
                          backtests and it's too time consuming to manually import txt-data each time.

                          Comment


                            #14
                            Originally posted by Stephan123 View Post
                            Thanks, but that's not what I look for, as described in the first post.
                            I need a method to live-generate the price data, since I will conduct a very large number of
                            backtests and it's too time consuming to manually import txt-data each time.
                            Then, short of actually repopulating the NT database with values that you generate, I cannot see how else you will be able to do it.

                            Comment


                              #15
                              Right but once you have the formula set up in excel you can generate 100+ years of data from 6 years worth (or there abouts). Since this will generate patterns you are likely to see in future from current data it is considered to be the most rigorous form of back testing you can do. Ask any CTA worth his salt !! This isn't txt data either its all csv format. As past performance is no indication of future etc you only want to establish how your system performs in different markets, trending, ranging etc etc and given a certain time frame you might be able to get some indication of max drawdown, length of drawdown and recovery time expected win loss ratio etc. This will only give you some anticipated performance parameters in order for you to decide whether to run with the strategy or not based on your own expectations, account size, risk tolerance etc.
                              Whether the data is a live feed to your desktop or generated on your desktop seems to be of little relevance if you get peace of mind and the confidence to execute your strategy. Sorry I couldn't help.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by BIOK.NT, Today, 01:56 PM
                              2 responses
                              11 views
                              0 likes
                              Last Post BIOK.NT
                              by BIOK.NT
                               
                              Started by i2ogu3, Today, 11:31 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post i2ogu3
                              by i2ogu3
                               
                              Started by RDTrader16, Today, 10:19 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post RDTrader16  
                              Started by gemify, 03-08-2023, 08:02 AM
                              9 responses
                              149 views
                              0 likes
                              Last Post culpepper  
                              Started by elirion, Today, 10:03 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post elirion
                              by elirion
                               
                              Working...
                              X