Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding Timeframe removes all trades

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

    Adding Timeframe removes all trades

    Hello All,

    Just adding another timeframe to my strategy removes all my existing trades, without even doing anything with the added timeframe data.

    I started with a simple strategy that buys on stochastics lows en sells on stochastics highs on a 1 minute chart. Very simple and works fine. I use a stop entry, then enter with 3 trades, use profittargets for the first two trades and a trailing stop for the last trade.

    I clearly see all trades visualised in my 1 minute chart and these are confirmed by printing the the total trades value in the output window.

    Now here is the strange thing: I would like to add a 5 minute timeframe to this strategy and only enter a trade when the stochastics in both timeframes point in the same direction. But just adding this 5 minute timeframe in the Initialize method, (so without doing anything with the data in this new barsarray), removes ALL of my existing trades! This is also confirmed in my output window saying my strategy has generated 0 trades, where previously there where more than a hundred.
    Removing the line "Add(PeriodType.Minute, 5);" is enough to get the strategy working properly again.

    What am I doing wrong? Would just adding a second timeframe mean that the conditions for a trade on the first timeframe (in array 0) change somehow?

    I work in simulation mode, with a simulated data feed and with calculateonbarclose=true. I have this problem both in backtesting and in live simulation testing.

    Thanks in advance for helping me out on this.
    Last edited by ArjanV; 04-23-2010, 04:24 AM.

    #2
    Welcome to our forums ArjanV, if you're using the added series in the code you should ensure it's not accidentially used as you're not working in correct BarsInProgress context as far as the OnBarUpdate() calls go. Try this in it to not process any events for the added, secondary series -

    Code:
    if (BarsInProgress != 0) return;

    Comment


      #3
      Thanks for the quick reply Bertrand,

      Adding this code to the onbarupdate method doesn't change the outcome. I carefully checked the code and there are no commands which use the added timeframe. I also already tried to :

      1- explicitly get the stochastics data from the primary(0) timeframe by adding the barsarray[0] code to this indicator.

      2- Only use the code when the primary timeframe updates by adding it in a "if barsinprogess == 0 " section.

      Both solutions and yours do not change the outcome. In the end it just depends on the add timeframe line being in the initialize method. When it's there,the code doesn't work, when I remove it, it works again.

      Another strange thing is that when I change the second timeframe from 5 minutes to 1 minute (i.e. the same as the primary timeframe [0]) the strategy starts working again. So just using any other timeframe than the one used in the primary timeframe kills the strategy. I really have no clue as to what is going on.

      Comment


        #4
        You're welcome, could please post the snippet you use? You can wrap code tags around it to make it easier readable.

        Also: any errors in the log tab as this occurs on your end?

        Thanks

        Comment


          #5
          Bertrand,

          No errors in the Log tab. I have attached the code snippet. If you need the complete code, let me know.

          Hope this helps.
          Attached Files

          Comment


            #6
            By the way, I am using Ninjatrader 7. Maybe this matters somehow.

            Comment


              #7
              ArjanV, thanks see nothing 'standing out' so if you send me full code to run to support at ninjatrader dot com Attn Bertrand I would appreciate it.

              Comment


                #8
                Hi Ray / ArjanV

                Was this issue resolved eventually? I seem to have run into the same exact problem

                Thanks

                Comment


                  #9
                  andreneoh, welcome to our forums here - which NT version are you working on as this issue surfaces? Would you mind posting a snippet of how you've structured you're code along with a brief description what exactly happens?

                  Thanks

                  Comment


                    #10
                    Using NT7 because of multi-timeframe support.

                    I'm trying to exit trades on a shorter timeframe after having entered on a longer timeframe. So far, all the NT help seems to suggest using "Add(PeriodType)" to cast a second time series array.

                    I have also explicitly made sure that the secondary array is referenced properly through the use ofBarsArray[1] or Opens[1][1] for eg during the exits.

                    Although my code compiles without syntax errors, I run into the problem of
                    "Add(PeriodType)" causing my strategy to not effect any trades at all.

                    Thanks

                    Comment


                      #11
                      andreneoh, multitime frame support was added for indicators in NT7, however 65 already supports this in a strategy environment.

                      For your entries and exits, are specifically submitting them to the correct BIP index?

                      For example for a market order -

                      Code:
                      EnterLong(int barsInProgressIndex, int quantity, string signalName)

                      Comment


                        #12
                        For your entries and exits, are specifically submitting them to the correct BIP index?

                        I have tried to specifically cast the entry order to the primary bars , and the exit order to the secondary bars but no dice. is there another setting?

                        eg,
                        EnterShort(0, "Quantity", "EntryName");
                        ExitShort (1, "ExitName", "EntryName");

                        Comment


                          #13
                          No, that should be sufficient, you can check for example into the SampleMultiTime / MultiInstrument strategies we ship per default with NT.

                          Any errors in the log you spot?

                          What kind of time frame are you adding and which min bars required setting are you using?

                          Comment


                            #14
                            Finally solved the above-mentioned issue. Apparently all I have to do is to ensure that NT Gui.Chart is declared properly. Without this declaration, Add(PeriodType) does not work for some reason.

                            Thanks

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            648 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            369 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            108 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            572 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            573 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X