Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Initialize() function problem?

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

    Initialize() function problem?

    Dear Mr/Ms,

    I am back testing my strategy for the period from 9/02/2013 to 9/04/2013. There is total 2 round trades. One in 9/02/2013, one in 9/03/2013, no trade in 9/04/2013. However, when I backtest on 9/04/2013 by the same strategy. There is one trade in 9/04/2013. Why there are these discrepancy?

    One possible reason I though maybe the initialize function. Is it called on at the beginning of each trading day?

    #2
    No Initialize is called only before OnUpdate. It is called several times, but before OnUpdate.
    I would speculate that your problem comes from indicators.
    You get values for your indicators from bars that are loaded. It differs if you load data from 09/02/13 or from 09/04/13. In the second scenario you don't have enough data.

    Comment


      #3
      Is there any function is called on each trading days before the OnBarUpdate, in which I can set my parameters dynamically?

      thanks

      Comment


        #4
        Originally posted by tedzzx View Post
        Is there any function is called on each trading days before the OnBarUpdate, in which I can set my parameters dynamically?

        thanks
        No, but what exactly do you want to do?

        Comment


          #5
          Thanks for the assist Baruch. For dynamic parameters for each day, I would just set them as needed on the first tick of the new session / session break tedzzx. That's the earliest point you could access before the new day unfolds...
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Calculate on bar close VS synthetic stoploss

            Dear Mr/Ms,

            In my strategy, the enter logic is based on 1 min bar. the Hong Kong Exchange does not support the stoploss order, so I want to write my synthetic stoploss order based on tick by tick data. How can I calculate the unrealized P&L within a 1 min OnBarCalculate() process?

            Thanks

            Comment


              #7
              tedzzx, you could for example use GetProfitLoss to monitor and pass in the Close price as market price - running the script on CalculateOnBarClose = false would give you this result tick by tick then - http://www.ninjatrader.com/support/h...tsub=GetProfit
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Thanks. One more question, if set the calculationOnBarClose=False, how to refer to the current bar' high low ?

                Comment


                  #9
                  Hello,

                  The Current bar would be referenced like this

                  High[0] //for the current high that is building in real time

                  If COBC were true High[0] would get the high of the bar that just closed (and wouldn't calculate on the bar that's still building)

                  This is a good sample for explaining how you can calculate with COBC = false



                  Let me know if I can further assist.
                  LanceNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by judysamnt7, 03-13-2023, 09:11 AM
                  4 responses
                  59 views
                  0 likes
                  Last Post DynamicTest  
                  Started by ScottWalsh, Today, 06:52 PM
                  4 responses
                  36 views
                  0 likes
                  Last Post ScottWalsh  
                  Started by olisav57, Today, 07:39 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post olisav57  
                  Started by trilliantrader, Today, 03:01 PM
                  2 responses
                  22 views
                  0 likes
                  Last Post helpwanted  
                  Started by cre8able, Today, 07:24 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post cre8able  
                  Working...
                  X