Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

handling (if historical)

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

    handling (if historical)

    I have a problem.
    For some reason I do not want to my strategy to trigger an order (generated yesterday), therefore I am using if(Historical) return;
    But as my strategy set some variable X at 9:31.00 and I am running the strategy now. X gets the value 0, and my strategy triggers unwanted orders.

    Hoe can one deal with this problem?? Can I only run my stratgey in If (Historical) mode before opening bell???

    #2
    Hello dafonseca,

    I'm not quite sure I understand.

    You are getting historical orders, when using if (Historical) return; at the beginning of OnBarUpdate, is this correct?

    Can you make a sample that demonstrates this I can test?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      let me try to explain.
      If (Historical) return; is working fine. However, my strategy set some variable X at 9:31:00,,
      In case I run my strategy at 10:00:00, the variable X will not be initializeed and stays with zero value.
      As my strategy uses X to generate orders,, the order is wrongly generated.
      simple example:
      (not using if historical and start strategy at 10.00.000
      I am trading AAPL and X is AAPL price. at 9:31, X will bi initialized with the value 123,00. supposing my strategy sells AAPL if current price - X > 2,00 it will not generate any sell order (supposing AAPL is 124,00 at 10.00.00).
      (using if historical and starting at 10:00:00)
      I am trading AAPL and X is AAPL price. at 9:31, X will bi initialized with the value 0,00 (due if historical ). supposing my strategy sells AAPL if current price - X > 2,00 it will generate a sell order (124-0>2).

      Comment


        #4
        Hello dafonseca,

        So you need to set values historically, but only place trades in real-time, is this correct?

        If so, move the code where the values are set to before the if (Historical) return; part.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I see. I think it can work.

          Comment


            #6
            Originally posted by dafonseca View Post
            let me try to explain.
            If (Historical) return; is working fine. However, my strategy set some variable X at 9:31:00,,
            In case I run my strategy at 10:00:00, the variable X will not be initializeed and stays with zero value.
            As my strategy uses X to generate orders,, the order is wrongly generated.
            simple example:
            (not using if historical and start strategy at 10.00.000
            I am trading AAPL and X is AAPL price. at 9:31, X will bi initialized with the value 123,00. supposing my strategy sells AAPL if current price - X > 2,00 it will not generate any sell order (supposing AAPL is 124,00 at 10.00.00).
            (using if historical and starting at 10:00:00)
            I am trading AAPL and X is AAPL price. at 9:31, X will bi initialized with the value 0,00 (due if historical ). supposing my strategy sells AAPL if current price - X > 2,00 it will generate a sell order (124-0>2).
            There are a few ways to tackle it. the simplest might be to just process a time filter before the Historical condition.

            Psuedocode below:
            Code:
            if (Time[0] is between 9:29 and 9:32)
            {
            //set required initial values for day
            }
            if (Historical) return;
            // rest of code goes here

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            601 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            347 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            559 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            558 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X