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...

          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

              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 Mindset, 04-21-2026, 06:46 AM
                  0 responses
                  118 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by M4ndoo, 04-20-2026, 05:21 PM
                  0 responses
                  166 views
                  0 likes
                  Last Post M4ndoo
                  by M4ndoo
                   
                  Started by M4ndoo, 04-19-2026, 05:54 PM
                  0 responses
                  85 views
                  0 likes
                  Last Post M4ndoo
                  by M4ndoo
                   
                  Started by cmoran13, 04-16-2026, 01:02 PM
                  0 responses
                  130 views
                  0 likes
                  Last Post cmoran13  
                  Started by PaulMohn, 04-10-2026, 11:11 AM
                  0 responses
                  89 views
                  0 likes
                  Last Post PaulMohn  
                  Working...
                  X