Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Do 0 Calculations Before live

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

    Do 0 Calculations Before live

    Hi there. I was looking to see if there was a way to have NT8 do 0 calculations before the strategy goes live. Currently I'm using the following block of code at the beginning of my strategy but it will still (rarely) say it's already in a long or short position when the strategy becomes active and therefore not execute a future trade that it should.


    Code:
    //Historical is a bool that is false when live and true when backtesting.
    
    #region Trading??
    //LIVE
    if ((State == State.Historical && !Historical
    && ToTime(Time[0]) < ToTime(startTime))
    || Time[0].Date < DateTime.Today.AddDays(0)
    || Close[0] < 2 || Close[0] > 200) return;
    
    //BACKTESTING
    if ((State == State.Historical && Historical
    && Time[0].Date < DateTime.Today.AddDays(0))
    || Close[0] < 2 || Close[0] > 200) return;
    
    if (CurrentBars[1] < BarsRequiredToTrade)
    {return;}
    
    if (BarsInProgress != 0)
    return;
    
    #endregion
    Is there something wrong with my code, is it perhaps a bug, or is there another way to have NT always start flat?

    #2
    Hello magnatauren,

    Thank you for your post.

    It seems that your conditions may allow for historical orders to happen between certain time frames.

    The simplest way to start flat is to modify your script so that it only places orders if the data is real-time data. To do this you will need to edit the code of your script directly, as the Historical property is not available to the Strategy Builder.

    The code needed would be something like:

    if (State != State.Realtime) return;

    This condition checks to see if the script is not processing real-time data (meaning it is processing historical data) and if true will stop any code appearing after it in the same method from evaluating.

    Here is a link to the Help Guide on the 'State' NinjaScript property — http://ninjatrader.com/support/helpG...n-us/state.htm

    Also, here is a link to a NinjaTrader Forum post with more information — https://ninjatrader.com/support/foru...541#post811541

    Please let us know if we may further assist.
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by kschuble, Today, 01:16 PM
    0 responses
    3 views
    0 likes
    Last Post kschuble  
    Started by ashleen, Today, 12:19 PM
    0 responses
    3 views
    0 likes
    Last Post ashleen
    by ashleen
     
    Started by wooofad, Today, 11:34 AM
    0 responses
    13 views
    0 likes
    Last Post wooofad
    by wooofad
     
    Started by tonynt, Today, 10:06 AM
    1 response
    17 views
    0 likes
    Last Post bltdavid  
    Started by Kediil, Yesterday, 09:26 AM
    1 response
    28 views
    0 likes
    Last Post NinjaTrader_ThomasC  
    Working...
    X