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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    43 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    29 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    46 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    38 views
    0 likes
    Last Post CarlTrading  
    Working...
    X