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

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 Karado58, 11-26-2012, 02:57 PM
            8 responses
            14,828 views
            0 likes
            Last Post Option Whisperer  
            Started by Option Whisperer, Today, 09:05 AM
            0 responses
            1 view
            0 likes
            Last Post Option Whisperer  
            Started by cre8able, Yesterday, 01:16 PM
            3 responses
            11 views
            0 likes
            Last Post cre8able  
            Started by Harry, 05-02-2018, 01:54 PM
            10 responses
            3,204 views
            0 likes
            Last Post tharton3  
            Started by ChartTourist, Today, 08:22 AM
            0 responses
            6 views
            0 likes
            Last Post ChartTourist  
            Working...
            X