Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Compiling Error CS106

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

    Compiling Error CS106

    # Help Needed: Compilation Errors

    Hello NinjaTrader Community,

    I'm developing a strategy for NinjaTrader 8, and I've run into some compilation errors that I can't seem to resolve. I'm hoping someone can help me understand what I'm doing wrong and how to fix it.

    ## The Issues

    When I try to compile my strategy, I get the following errors:

    ```
    NinjaScript File;Error;Code;Line;Column;
    SweepyBotcs;'BarsPeriod' does not contain a definition for 'SecondsPerBar' and no accessible extension method 'SecondsPerBar' accepting a first argument of type 'BarsPeriod' could be found (are you missing a using directive or an assembly reference?);CS1061;205;70;
    SweepyBotcs;'BarsPeriod' does not contain a definition for 'SecondsPerBar' and no accessible extension method 'SecondsPerBar' accepting a first argument of type 'BarsPeriod' could be found (are you missing a using directive or an assembly reference?);CS1061;213;70;
    ```

    ## The Code

    Here are the relevant parts of my code where the errors occur:

    ```csharp
    private void PlaceBuyOrder()
    {
    double entryPrice = Low[0] - EntryLimitOffset * TickSize;
    entryOrder = EnterLongLimit(0, true, 1, entryPrice, "Long Entry");
    entryOrderExpirationTime = Time[0].AddSeconds(BarsPeriod.SecondsPerBar * DeleteLimitAfter);
    }

    private void PlaceSellOrder()
    {
    double entryPrice = High[0] + EntryLimitOffset * TickSize;
    entryOrder = EnterShortLimit(0, true, 1, entryPrice, "Short Entry");
    entryOrderExpirationTime = Time[0].AddSeconds(BarsPeriod.SecondsPerBar * DeleteLimitAfter);
    }
    ```

    The errors are pointing to the `BarsPeriod.SecondsPerBar` part in both methods.

    ## Questions

    1. Why am I getting these errors? Is `BarsPeriod.SecondsPerBar` not a valid property in NinjaTrader 8?
    2. If it's not valid, what's the correct way to get the number of seconds per bar in NinjaTrader 8?
    3. Are there any other issues you can spot in the provided code snippets?

    ## Additional Information

    - I'm using NinjaTrader 8 (latest version as of August 14, 2024)
    - The strategy is intended to work with various timeframes (1 minute, 5 minutes, etc.)
    - I've included all the necessary `using` statements at the top of my file

    Any help or guidance would be greatly appreciated. If you need any more information or code snippets, please let me know.

    Thank you in advance for your assistance!​
    Attached Files

    #2
    Hello donchidonald,

    Thank you for your post.

    BarsPeriod does not have a SecondsPerBar property. Below is the Help Guide documentation for BarsPeriod:



    There is an existing sample script which demonstrates how to calculate a bar's time in seconds:



    Essentially the formula is:

    totalTime = (Time[0] - Time[1]).TotalSeconds;

    Please let us know if you have any further questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    19 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    119 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    63 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    41 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    45 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X