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

Why use int instead of double for declaring

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

    Why use int instead of double for declaring

    A few questions,

    1) Cannot I just always use 'double' instead of 'int' for declaration?

    2) Been using this to test start of today. The calculation starts at the new day, but the plot runs on from previous day. Do you have to reset the plot to new day? What do you use?

    DateTime nowDate =DateTime.Now;
    if (Time[0].Date == nowDate.Date)
    {calculation;}

    3) The data series I am using has the 256 default maxbarslookback. So if I begin calculating data at the start of the day, it doesn't appear until after 256 bars. How do I fix that?

    Thanks

    #2
    Hello Ninat,

    Thanks for opening the thread.

    1) Cannot I just always use 'double' instead of 'int' for declaration?
    This generally would not be a problem to use a type double in place of type integer. You will use more memory for doubles than integers so that would be one downside to doing this.

    Also keep in mind that any double that is assigned to an integer will have to be type casted and there may be data loss when converting a double to an integer.

    2) Been using this to test start of today. The calculation starts at the new day, but the plot runs on from previous day. Do you have to reset the plot to new day? What do you use?

    DateTime nowDate =DateTime.Now;
    if (Time[0].Date == nowDate.Date)
    {calculation;}
    The code above compares the current date to the date of the current bar. It should always be true.

    To detect a new day within your code, I would suggest to add an additional data series for daily data and when the bar iterates for a new day, perform any tasks that should be performed daily.

    There is sample code that demonstrates this here:

    If this does not resolve your inquiry, please provide some additional information for what exactly you are trying to do so I can provide further direction.

    3) The data series I am using has the 256 default maxbarslookback. So if I begin calculating data at the start of the day, it doesn't appear until after 256 bars. How do I fix that?
    Max bars lookback would only control how many bars will be available historically in that data series. This would not impact how many bars it takes for your strategy to start trading. Please make sure you are not limiting your strategy to wait for 256 bars.

    Some possible scenarios to limit strategy logic to wait 256 bars:

    Having BarsRequiredToTrade equal 256

    Having a return condition for 256 bars:
    Code:
    if (CurrentBar < 256)
      return;
    Programming education is outside of the scope of services that we provide in the support department, but we do have some basic programming concepts documented in the NinjaTrader 7 help guide that can provide a strong foundation for programming NinjaScripts. I will provide a link for reference.

    NinjaTrader 7 programming concepts - http://ninjatrader.com/support/helpG...g_concepts.htm

    Please let me know if I may be of further assistance with your inquiry.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by cre8able, 02-11-2023, 05:43 PM
    3 responses
    232 views
    0 likes
    Last Post rhubear
    by rhubear
     
    Started by frslvr, 04-11-2024, 07:26 AM
    8 responses
    111 views
    1 like
    Last Post NinjaTrader_BrandonH  
    Started by stafe, 04-15-2024, 08:34 PM
    10 responses
    44 views
    0 likes
    Last Post stafe
    by stafe
     
    Started by rocketman7, Today, 09:41 AM
    3 responses
    8 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by traderqz, Today, 09:44 AM
    2 responses
    5 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Working...
    X