Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Positions[0] updated in Strategy BackTest?

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

    Positions[0] updated in Strategy BackTest?

    Hello ,

    I started backtesting a simple strategy using FDAX 12-09 on 1Minute bar time frame.

    My strategy has a stoploss handling which in this example allows 0,25% loss per trade.

    I set up the Backtest to run my Strategy to run from 20.00 to 20.30 from 1.1.2009 until 23.9.2009
    ExitOnClose is set to true, hence strategies exit after the 20.30 bar.

    Most results are OK, but there are a few places where the backtest gives a very strange behaviour:

    Have a look at trade 26:

    This trade has a loss of 4,7%, much more than my stoploss would allow.

    And StrategyAnalyzer reports an entry@3897 and an exit@3713 both happened at 20.02 on 5march2009 (pricesarebackajusted).

    Obviously something is wrong here:

    1. First point striking is that entry and exit happen on the same bar. Looking at the chart I cannot find a condition within the timespan in question that would trigger such a scenario

    2. I started checking the data: My data is OK, but I find out that the entry price od 3897 corresponds to the price of the day before at the same time, 4march2009 20.02

    3. I started Visual Studio 2008 debugger and had a look at my code:
    Under the debugger I find out that my entryOrder=EntryLongLimit(..) is triggered and filled and entryOrder.Filled=1.

    However I do a code check for Positions[0].MarketPosition, which should give me LONG as a result then (and it does in real trading) , but this Positions[0].MarketPosition returns flat all the time.



    Questions:

    1. What is going on here in the StrategyAnalyzer?
    2. Why is exit and entry taken in one single bar, but the entry price is taken from the previous day bar.
    3. Is it allowed to use Positions[0].MarketData in StrategyAnalyzer?


    Best regards
    Andreas
    Attached Files

    #2
    Andreas, is this a multiseries strategy? Positions should only be used in this context, if not please retry with Position.MarketPosition
    BertrandNinjaTrader Customer Service

    Comment


      #3
      It is a single instrument strategy, I use Positions[barsInProgress] only because I want to be ready for multi-instrument.

      I changed the code to Position.MarketPosition, but no change.

      The error/wrong bar data/single bar entry and exit persist.

      Andreas

      Comment


        #4
        Set() methods for stop loss or explicit exit orders?
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          SetStoppLoss and SetProfitTarget only...


          But in the above case I believe the problem is related to the wrong data for 5march2009 20.01.

          SA uses the data from the day before as entryprice, and then my strategy exits (usually) immediately because inside my strategy I use the correct data from 5march2009.

          How can it be that the data is delivered one day off?

          I have a complete 1 minute endless future contract of data.

          Now I have an Idea:
          My data is only 1 minute data, there is no day data or if there is it might not be complete. Could this be related?

          Comment


            #6
            If you only work with a single instrument 1 min strategy the incomplete daily data should not matter - have you tried running the same strategy directly from the chart to compare the results you get? This way you could also visually check the data on this date.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              It is not related to (eventually ) missing day data.

              My exits are SetStoppLoss and SetProfitTarget, and sometimes ExitOnclose generated by NinjaTrader.
              A strange observation regarding SetProfitTarget:

              After the first call of SetProfitTarget all subsequent Exits using SetProfitTarget indicate the same exit price.

              It seems that after one call to SetProfitTarget and related exit there is no longer an update done to SetProfitTarget internal structures.


              Any ideas how to fix this?


              Attached the backtest
              Attached Files

              Comment


                #8
                Andreas, is this all from Strategy Analyzer run started 'normally' in NT?

                Do you reset your Stops and Targets once flat?

                Please work with TraceOrders to explicitly see the order behavior your strategy generates - http://www.ninjatrader-support2.com/...ead.php?t=3627
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Bertrand,

                  yes I do use NinjaTrader by hand and mousclicks. No other background stuff active!

                  I checked the TraceOrders stuff, and all seems normal.

                  Comment


                    #10
                    Ok, is this a static stop / target or do you modify the price? In the later case, please ensure it's reset to some default when you're flat.

                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      My SetProfitTarget is called only once per trade, but I cannot call it in Initialize() but will call just a few seconds before the exit of the trade , as SetProfitTarget gets a GetCurrentAsk() + delta as a parameter.

                      I cannot find any reference to a SetProfitTarget reset in your example code.

                      My target price is reset before each new trade.

                      I traced down further, and the problem seems to be related to the ZigZag indicator. I call the second latest low but ZigZag gives a value relative to the day before!!

                      This triggers a trade which is then so far off that the NinjaTrader SetStopLoss will trigger immediately , hence within the same bar.
                      After such an event SetProfitTarget will not recover any more and will always exit at a fixed value and not at the value I give as a parameeter.



                      be called within the

                      Who knows...

                      Any tip!

                      Andreas

                      Comment


                        #12
                        That makes since with the ZigZag explanation, SetProfitTarget would 'recover' if you reset it after this to your default when flat value, for example -

                        Code:
                         
                        if (Position.MarketPosition == MarketPosition.Flat)
                        {
                        SetProfitTarget(CalculationMode.Ticks, 10);
                        }
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          OK, I will try,

                          but may I ask something on SetProfitTarget behaviour?


                          1. Multiple calls to SetProfitTarget, is this possible
                          (a) only when flat
                          (b) also when in position
                          (c) only in Initialize()
                          (d) only when Flat in Initialize()


                          2. How can I set an infinite Profit Target? Can I do 0 and Double.MaxValue as parameters?




                          I ask this because several month ago when I wrote the core of my strategies I had some woes with SetProfitTarget but I don't remember the details. Something with a second call to SetProfitTarget not working properly.


                          Best regards

                          Andreas
                          Last edited by zweistein; 09-25-2009, 10:12 AM.

                          Comment


                            #14
                            Sorry I was wrong,

                            must call SetProfitTarget(strentrySignal,CalculationMode.Tic ks,1000);
                            that resets SetProfitTarget


                            a.



                            Hello Bertrand,


                            I tried your advice and I put
                            SetProfitTarget(CalculationMode.Ticks,1000);
                            in my reset function,

                            but it does not work!

                            My experience tells me that you can call SetProfitTarget only one time for the lifetime of a strategy.
                            I cannot find a working reset of SetProfitTarget

                            Any ideas?

                            Thank you
                            Andreas
                            Last edited by zweistein; 09-25-2009, 10:29 AM. Reason: new fiindings:

                            Comment


                              #15
                              Thank you

                              SetProfitTarget reset is working!


                              Have a nice weekend

                              off
                              A

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by burtoninlondon, Today, 12:38 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post burtoninlondon  
                              Started by AaronKoRn, Yesterday, 09:49 PM
                              0 responses
                              13 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