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

problem CalculateOnBarClose = true in multipletimeframe strategy

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

    problem CalculateOnBarClose = true in multipletimeframe strategy

    Hi,

    I am having some issues with a multi timeframe strategie
    that is based on crossovers to trigger a buy or sell signal

    1)
    When I do use CalculateOnBarClose = false, it is working correctly

    When I do use CalculateOnBarClose = true, I am getting multiple exections within one second. (3-5)

    Is it maybe bacause a crossover can happen several times intrabar? Or in fact it takes 1 or 2 seconds for NT until the crossover has happend in reality?
    What can I do to stop this behavior if CalculateOnBarClose = true? I want only one execution within one bar if a crossover occurs. (not at the end)

    2)
    The number of maximum entries per direction is not being reached, even if the conditions are met. I am getting only about 1/3 in reality.
    Means when I specify 10 executions in one direction, I am getting maximum 3 - when I specify 32 per direction, I am getting maximum 10 executions in one direction.
    I added 4 bar objects, same instrument, different timeframes.
    I am using BarsInProgress == 1 as overall condition before any other condition is analysed.

    any idea where the problem is?

    thx

    #2
    azuul,

    I believe you have your settings mixed up. CalculateOnBarClose = false is what would allow multiple intrabar crossovers to trigger multiple trades. There would only be one crossover if you used CalculateOnBarClose = true. If you are working intrabar you are definitely using CalculateOnBarClose = false. If you only want to trade the first cross that may occur inside that bar, use flag variables.

    Untested code.
    Code:
    if (Position.MarketPosition == MarketPosition.Flat && flag == false)
         flag = true;
    
    if (CrossAbove(Close, SMA(20), 1) && flag)
    {
         EnterLong();
         flag = false;
    }
    2. You need to check your EntryHandling setting as well. Entries per direction works in conjunction with entry handling. Working orders that are not filled yet still counts as an entry too.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hi Josh

      Sorry for my late reply - yes you are right, in my post I confused the settings - it was meant the other way round:

      When I do use CalculateOnBarClose = true, it is working correctly

      When I do use CalculateOnBarClose = false, I am getting multiple exections within one second. (3-5)

      But anyways I have to take back the first statement, CalculateOnBarClose = true does NOT work correctly with live data - I am getting several intrabar fills for ONE crossover ! (seems for every tick I am getting a fill until maximum entries per direction is reached)

      I tried to tackle this Problem today by flagging, but the problem persists!

      I am using a multitimeframe/multiinstrument strategy

      My plan is to enter up to 4 Positions in one direction, but not in one crossover - now

      (Position.MarketPosition == MarketPosition.Flat && flagbuy == false)


      would not do the correct thing anyways since I could only have one entry in one direction -

      I tried it nevertheless - but I am still getting the maximum number of executions (4) on one crossover when I try using CalculateOnBarClose = false!
      maybe it has something to do with the extra added barobjects?
      (I am using the flags/crossover on the barobject 1 - since I want my strategy independet from the timepattern in the chart)

      2)

      There should be no working orders that are not filled, I only have market orders with a rather simple IF condition - I think it has to do something with the number of barobjects!
      When I add 1 Barobject, I have to use the double number of "entries per direction" as I really want. E.g. 10 means I am getting max 5 entries!

      I think it works the following the actual chart = barobject 0 + the added 1 barobject means I have to multiply by 2.

      I tried adding 4 barojects (barobject 0 + 4 added barobects =5 ) - means when I want to have up to 4 entries per direction I need to enter 20 in the strategy field "entries per directoin" - is this the way it is meant to function? Or is this a bug ?
      Last edited by azuul; 05-27-2009, 10:58 AM.

      Comment


        #4
        azuul,

        You need to use the whole code snippet. The first if-condition is when you should RESET your flag. It is not your entry condition. If you want additional trades you need to work out how to use additional flags to get your desired behavior.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I understood what your code was supposed to do - and I think I used it correctly - I am not even getting the right behavior with CalculateOnBarClose = true in simulation with live data! ( I edited my other post in bold letters)

          The problems seems to come with the added barobjects (multipletimeframes)

          Comment


            #6
            azuul,

            I guarantee you CalculateOnBarClose = true only processes ONCE at the end of each bar. Please ensure you are using the correct settings.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              I thought so too!!!

              I will try removing the barobjects in order to debug - since I dont see any other source of error!

              Do you have any idea concerning the strange behaviour with "entries per direction"?

              Comment


                #8
                azuul,

                You will need to iron it out on your end since I guarantee you these features work as expected. Entries per direction allows you how many entry trades you can place to build up a position. You need to check your EntryHandling setting.

                I suggest you use TraceOrders = true to figure out what is going on with your orders. I also suggest you start simple and slowly layer on functionality.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  ok the output screen indicated that the update was processed at the end of the bar - so the problem is still that I am getting multiple entries per direction for ONE crossover (no matter what my CalculateOnBarClose value is) - but only with live data - with historic data everything is running as it should!

                  the entry handling issue is 100% related to the added barobjects - and on this issue I am not sure where to find the relevant background information to understand exactly how NT is processing things there!
                  Last edited by azuul; 05-27-2009, 11:28 AM.

                  Comment


                    #10
                    Please use TraceOrders = true.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      CalculateOnBarClose fills

                      I have an additional question about the CalculateOnBarClose property that may be related.

                      Noticed that for a backtest, when CalculateOnBarClose = true and my specified entry price is somewhere between the open and close of the current bar, limit orders placed at that time fill at the bar's close price, market orders fill at the bar's open price, and stop limit orders are ignored.

                      1_ What's the rationale behind where fills happen for different kinds of orders for historical backtests when CalculateOnBarClose = true ?

                      2_ If one were to use tick data, setting CalculateOnBarClose to false, will the fills happen around the specified price instead of being ignored or filling strictly at the open or close of the bar ?

                      Comment


                        #12
                        In backtesting, setting CalculateOnBarClose has no bearing. It is always true for a backtest.

                        1. Not sure I follow your observations. Limit orders fill at the limit price. Market orders fill at open of next bar. Stop-limit orders fill at limit price if stop price is penetrated.

                        2. Orders placed on the signal bar are filled at the open of the trade bar. You are processing with CalculateOnBarClose = true always in a backtest.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          CalculateOnBarClose fills -- follow up

                          OK, my observation about the limit order filling on bar close was mistaken -- my stated price coincidentally matched the bar close in the instance I was reviewing.

                          For backtests, then, it always calculates on bar closes, so if there's a "CalculateOnBarClose = true" in there it's basically ignored ?

                          Does that mean the only way to test against ticks instead of bars is with a market replay, not a backtest or optimization ?

                          Comment


                            #14
                            Shogun,

                            That is correct. Backtests ignore whatever you set CalculateOnBarClose to and will always use it in a true state.

                            If you want tick granularity you can either backtest with added granularity through a multi-series strategy (demonstrated here: http://www.ninjatrader-support2.com/...ead.php?t=6652) or you can use Market Replay. Tick granularity is essentially forward testing and for forward testing I do recommend the Market Replay functionality.
                            Josh P.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by sdauteuil, 09-23-2021, 10:16 AM
                            4 responses
                            1,208 views
                            0 likes
                            Last Post jacobpescaia44  
                            Started by agclub, 04-21-2024, 08:57 PM
                            5 responses
                            34 views
                            0 likes
                            Last Post agclub
                            by agclub
                             
                            Started by ESHunter, Yesterday, 08:06 PM
                            2 responses
                            18 views
                            0 likes
                            Last Post ESHunter  
                            Started by ETFVoyageur, 05-07-2024, 07:05 PM
                            19 responses
                            150 views
                            0 likes
                            Last Post ETFVoyageur  
                            Started by ETFVoyageur, 05-11-2024, 10:13 PM
                            3 responses
                            26 views
                            0 likes
                            Last Post ETFVoyageur  
                            Working...
                            X