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

BarsRequiredToTrade - How to use it properly?

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

    BarsRequiredToTrade - How to use it properly?

    Hi guys,

    I really cannot get my head around this BarsRequiredToTrade property. Technically I think I understand it: it does nothing more than ignoring trade orders that are issued before the bar count of BarsRequiredToTrade is reached.

    But I don't really understand the purpose of this property and how to use it properly. I am especially confused about the fact that the user is supposed to set this property to a value _he_ defines (and not the strategy internally).

    So some questions please:
    - what is the use case of that property? Why would the _user_ use it to refuse orders the _strategy_ decided to issue? Is there maybe an example of what a good use case is for it?

    - it is not meant to define the number of bars the strategy needs _technically_ to be able to work, right? So when a strategy uses an SMA(15), the strategy should handle that internally without the user having to set BarsRequiredToTrade, right?

    #2
    Hello _vbs_,

    The intention of this is to prevent trades until there is enough historical data for calculations.

    Another intention of this is to prevent a common mistake made by NinjaScript creators that use indexes improperly. For example calling Close[1] on the first bar would cause an error as there is no bar one bar ago.
    So using if (CurrentBars[0] < BarsRequiredToTrade) return; would prevent that error from occurring.
    NinjaTrader defaults this to 20 to allow for up to 20 barsAgo to be called without error which prevents a large portion of these mistakes.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your answer but sorry I have still a question.

      Originally posted by NinjaTrader_ChelseaB View Post
      The intention of this is to prevent trades until there is enough historical data for calculations.
      Ok, so "BarsRequiredToTrade" in NT8 really is meant as a replacement for NT7's "BarsRequired". I always wondered why this property can be changed by the user as IMO only the strategy itself can know how many bars it needs to trade.
      For example if a strategy NEEDS 17 bars before being able to work then, I assume, it will put 17 as the default for BarsRequiredToTrade. What reason could there be for the user to either increase or decrease this property when running the strategy? Decrease will probably crash the strategy and increasing would mean valid early trade orders by the strategy would be ignored by NT.
      As a user I would think I should never touch it and just rely on the strategy to put a sensible default value, no?

      Comment


        #4
        Hello _vbs_,

        The user may have the ability to change the length of an SMA. Lets say this gets changed to 200 bars. To ensure a proper calculation, preventing the script from trading until there are 200 bars can be done by setting BarsRequiredToTrade to 200.

        This is one situation where the user would want to change the BarsRequiredToTrade. There may be other situations where the programmer may have other inputs that would need the BarsRequiredToTrade to be adjusted as well.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by inanazsocial, Today, 01:15 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by rocketman7, Today, 02:12 AM
        0 responses
        10 views
        0 likes
        Last Post rocketman7  
        Started by dustydbayer, Today, 01:59 AM
        0 responses
        2 views
        0 likes
        Last Post dustydbayer  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        23 views
        0 likes
        Last Post trilliantrader  
        Started by Davidtowleii, Today, 12:15 AM
        0 responses
        3 views
        0 likes
        Last Post Davidtowleii  
        Working...
        X