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

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:



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


    And a link on Transitioning order references from historical to live.


    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.


    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.
    Test the bool type, which holds true or false. A bool occupies 1 byte of memory.
    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().


      And a link on Transitioning order references from historical to live.


      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.


      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 jeronymite, 04-12-2024, 04:26 PM
      3 responses
      44 views
      0 likes
      Last Post jeronymite  
      Started by Barry Milan, Yesterday, 10:35 PM
      7 responses
      20 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by AttiM, 02-14-2024, 05:20 PM
      10 responses
      179 views
      0 likes
      Last Post jeronymite  
      Started by ghoul, Today, 06:02 PM
      0 responses
      9 views
      0 likes
      Last Post ghoul
      by ghoul
       
      Started by DanielSanMartin, Yesterday, 02:37 PM
      2 responses
      13 views
      0 likes
      Last Post DanielSanMartin  
      Working...
      X