• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

State == State.Realtime

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

    State == State.Realtime

    Question 1)

    Code:
      if (State == State.Realtime)
    I read the guide:

    https://ninjatrader.com/support/help...neousPractices

    Can you please elaborate in laymans term what you mean by "transition from historical to real-time?" I mean I can guess what it might mean but why is this necessary? Please give an example of an issue it may cause if it's not used. I'm trying to understand the benefit of me adding this to my strategy and what changes it may cause to a strategy?

    side note;

    Code:
    if(State == State.Historical && Times[0][0].Date <= new DateTime(2018, 01, 8))
    			 return;
    I've added the above in my strategy to ignore data prior to this b/c I want to ignore those historical trades. Is state=realtime basically the same as saying:

    Code:
    if(State == State.Historical)
    			 return;
    Question 2)

    Say today is 8/30/2018 and I start a strategy with daily data and is COBC and that has the below

    Code:
    if(State == State.Historical && Times[0][0].Date <= new DateTime(2018, 08, 29))	 return;
    What happens to conditions that are offsetting in nature if those conditions by definition are looking at data prior to 8/29/2018 but are doing it today? For example:

    Code:
    Close[10]>Close[20]
    Will the strategy end up waiting until it has a min of 20 days for that condition to come true?

    Question 3)

    I basically have a condition that becomes true once every few months and then stays true for various months. It's a bool that becomes true/false. For this condition, I want the strategy to look at all historical data. But then there are other parts of the strategy (position/account values) that I do not want to look at all historical data, therefore, I have this condition: (but this causes an issue b/c the bool could be true today)

    Code:
    if(State == State.Historical && Times[0][0].Date <= new DateTime(2018, 08, 29))
    I'm wondering if it's possible to do under OBU:


    Code:
    if(State == State.Historical)
    {Set the conditions for my bool;}
    and then:

    Code:
    if(State == State.Historical && Times[0][0].Date <= new DateTime(2018, 08, 29))	 return;
    Would be bool carry forward? Any ideas on how I can do this? The only way I can accurately think of is manually creating a variable that sets my bool to true/false and I can just change it every time i turn on the strategy.
    Last edited by staycool3_a; 08-30-2018, 12:01 AM.

    #2
    Hello calhawk01,

    As a strategy is enabled it will process all of the historical data on a chart or with the Days to load setting if the strategy is added directly to the strategies tab. The State of the strategy will be State.Historical. If an order was placed in historical data its a historical order.
    Once the historical data has been processed the strategy will become (transition) State.Real-time and begin processing real-time data as it streams in. If an order submitted when the State.Historical remains working when the strategy transitions to State.Real-time this order will need to be run through GetRealtimeOrder().

    Below is a public link to the help guide on GetRealtimeOrder().
    https://ninjatrader.com/support/help...ltimeorder.htm

    And a link on Transitioning order references from historical to live.
    https://ninjatrader.com/support/help...storicaltolive

    Yes, in OnBarUpdate the State will either be State.Historical or State.Realtime.
    Using if (State == State.Realtime) { // trigger action } would allow only actions in the action block to be triggered in real-time while anything outside of the action block would be able trigger historically.
    Using if (State == State.Historical) return; would prevent any actions below that line in OnBarUpdate from triggering historically.


    When you mention:
    "What happens to conditions that are offsetting in nature if those conditions by definition are looking at data prior to 8/29/2018 but are doing it today?"
    I'm not quite sure what you are asking. What do you mean by offsetting in nature?

    With the condition:
    if (Close[10] > Close[20]) { // execute code }

    This condition would evaluate as true if the close from 10 bars ago is greater than the close of 20 bars ago.
    However, you would definitely want to wait until there are at least 20 bars before allowing this condition to be evaluated other wise there will be an indexing error if CurrentBar is less than 20.

    The strategy will only wait 20 days if you have programmed the script to do this.

    BarsRequiredToTrade defaults to 20, however, this would not prevent the condition from checked and would not prevent an indexing error but instead would prevent order methods from being triggered until there are 20 bars.
    https://ninjatrader.com/support/help...redtotrade.htm

    Further, on a minute chart, this would only prevent order methods from triggering for the first 20 minutes not the first 20 days.

    If you wanted a strategy to wait 20 days on a minute chart, you would need to program this logic into the script. You could have an int counter that increments on each new session to could the number of sessions and prevent trades until that counter is above 20.

    When you mention:
    "Would be bool carry forward?"

    Yes, if you set a bool in historical data, it will continue to have that value in real-time unless you set the value of the bool to something else.

    Below is a public link to a 3rd party educational site on bool.
    https://www.dotnetperls.com/bool
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello calhawk01,

      As a strategy is enabled it will process all of the historical data on a chart or with the Days to load setting if the strategy is added directly to the strategies tab. The State of the strategy will be State.Historical. If an order was placed in historical data its a historical order.
      Once the historical data has been processed the strategy will become (transition) State.Real-time and begin processing real-time data as it streams in. If an order submitted when the State.Historical remains working when the strategy transitions to State.Real-time this order will need to be run through GetRealtimeOrder().

      Below is a public link to the help guide on GetRealtimeOrder().
      https://ninjatrader.com/support/help...ltimeorder.htm

      And a link on Transitioning order references from historical to live.
      https://ninjatrader.com/support/help...storicaltolive

      Yes, in OnBarUpdate the State will either be State.Historical or State.Realtime.
      Using if (State == State.Realtime) { // trigger action } would allow only actions in the action block to be triggered in real-time while anything outside of the action block would be able trigger historically.
      Using if (State == State.Historical) return; would prevent any actions below that line in OnBarUpdate from triggering historically.


      When you mention:
      "What happens to conditions that are offsetting in nature if those conditions by definition are looking at data prior to 8/29/2018 but are doing it today?"
      I'm not quite sure what you are asking. What do you mean by offsetting in nature?

      With the condition:
      if (Close[10] > Close[20]) { // execute code }

      This condition would evaluate as true if the close from 10 bars ago is greater than the close of 20 bars ago.
      However, you would definitely want to wait until there are at least 20 bars before allowing this condition to be evaluated other wise there will be an indexing error if CurrentBar is less than 20.

      The strategy will only wait 20 days if you have programmed the script to do this.

      BarsRequiredToTrade defaults to 20, however, this would not prevent the condition from checked and would not prevent an indexing error but instead would prevent order methods from being triggered until there are 20 bars.
      https://ninjatrader.com/support/help...redtotrade.htm

      Further, on a minute chart, this would only prevent order methods from triggering for the first 20 minutes not the first 20 days.

      If you wanted a strategy to wait 20 days on a minute chart, you would need to program this logic into the script. You could have an int counter that increments on each new session to could the number of sessions and prevent trades until that counter is above 20.

      When you mention:
      "Would be bool carry forward?"

      Yes, if you set a bool in historical data, it will continue to have that value in real-time unless you set the value of the bool to something else.

      Below is a public link to a 3rd party educational site on bool.
      https://www.dotnetperls.com/bool
      I think I figured out a way to solve my problem:

      I'm just going to put in the block of code that i'd want to ignore historically and only be used going forward starting the day I go live using:
      Code:
      			if(State == State.Historical && Times[0][0].Date >= new DateTime(2018, 08, 29))
      			{
      BLOCK OF CODE;
      }
      The remaining logic will just remain with default state. This way my bool and main logic is analyzed on all data available.
      Last edited by staycool3_a; 08-30-2018, 11:30 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Rashid Garuba, Today, 11:37 AM
      0 responses
      7 views
      0 likes
      Last Post Rashid Garuba  
      Started by elkhatabi, Today, 11:19 AM
      0 responses
      5 views
      0 likes
      Last Post elkhatabi  
      Started by hurleydood, Today, 10:07 AM
      0 responses
      6 views
      0 likes
      Last Post hurleydood  
      Started by Irukandji, Today, 09:43 AM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_ThomasC  
      Started by TazoTodua, Today, 09:06 AM
      0 responses
      8 views
      0 likes
      Last Post TazoTodua  
      Working...
      X