Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

The name "IsFirstBarOnChart" does not exist in the current chart

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

    The name "IsFirstBarOnChart" does not exist in the current chart

    Team - I am new to the coding and trying to embed my custom code in the strategy and it give me the following error:
    The name "IsFirstBarOnChart" does not exist in the current chart
    The name "IsLastBarOnChart" does not exist in the current chart

    How do I fix this.The code is below:

    {

    if (IsFirstBarOnChart && Close[1] < Open[1])
    {
    Then...............
    }

    if (IsLastBarOnChart && Position.MarketPosition == MarketPosition.Long)
    {
    ​Then....


    Thanks and your help is much appreciated.
    Last edited by NRITV; 01-12-2024, 07:01 PM.

    #2
    Hello NRITV,

    Thanks for your post.

    IsFirstBarOnChart and IsLastBarOnChart are not supported NinjaScript methods or properties found in the help guide which is why the error messages are occurring.

    To check for the first bar on a chart you could consider creating a condition that checks if CurrentBar is equal to 0.

    CurrentBar returns the number of bars on the chart.

    Bars are counted from the leftmost bar to the rightmost bar on the chart. The first bar (leftmost bar) on a chart would have a bar index of 0.

    See this help guide page for more information about CurrentBar: https://ninjatrader.com/support/help...currentbar.htm

    Below is a link to a forum post with helpful information about getting started with NinjaScript.
    https://ninjatrader.com/support/foru...040#post786040

    I am also linking you to the Educational Resources section of the Help Guide to help you get started with NinjaScript:


    If you are new to C#, to get a basic foundation for the concepts and syntax used in NinjaScript I would recommend this section of articles in our help guide first:


    And the MSDN (Microsft Developers Network) C# Language Reference.
    https://ninjatrader.com/support/help...erence_wip.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    47 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    23 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    33 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    51 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X