Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using DailyLossLimitExample_NT8

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

    Using DailyLossLimitExample_NT8

    Hello ,

    I found this code (Attachments) in this thread (Daily loss limit examples - NinjaTrader Support Forum​) and i modified it for my needs,
    Basically, I have basic knowledge in programming and just wanted to make sure I did the right modifaication.
    This Strategy needs to close active positions if the daily loss P/L reached to the stop limits.
    Alternatively, it needs to stop me from placing a new positions when the P/L reached to the daily loss limit.

    The changes I've made :
    Line 38 : Calculation.OnBarClose ------> Calculation.OnEachTick.
    Line 41 : LossLimit : 500 ------> LossLimit : 350

    I'm not quite sure about the reset condition - Line 53 - "IsFirstBartOfSession" does it indicates on a new trading day ?

    After I imported it and made the modifications for my needs and after I enabled it - it looks like it still doesn't work..
    I have entered the right instruments - using Sim1 account in order to check it but it it doesn't seems to work..
    Any idea ?
    Click image for larger version

Name:	image.png
Views:	107
Size:	38.1 KB
ID:	1232706
    Click image for larger version

Name:	image.png
Views:	148
Size:	20.7 KB
ID:	1232705​Thanks in advance .

    #2
    Hello guysabati97,

    Thanks for your post.

    IsFirstBarOfSession checks if the bar processing is the first bar of a trading session. When the processing bar is the first bar in a new trading session, IsFirstBarOfSession will return true.

    IsFirstBarOfSession: https://ninjatrader.com/support/help...rofsession.htm

    I see in the screenshot you shared that the strategy name is yellow in the Strategies tab.

    When a strategy is yellow (or orange on some monitors) in the Strategies tab of the Control Center, this means that the strategy entered a historical (theoretical) position in the historical data that has been loaded.

    It also means that you have "Wait until flat" selected for the 'Start behavior' option in the strategy parameters which can be seen in the screenshot you shared..

    This means that once the strategy has finished processing the historical data and has transitioned to real-time, it will wait until there is a real-time order submission that will cause the strategy to become flat. This also includes changing from a long position to a short position or vice versa as the position would pass through flat.

    This also applies to secondary instruments if there are added series to the script. All positions must be flat before real-time orders will begin.

    You can change the start behavior to "Immediately submit" in the parameters of the strategy. Immediately Submit automatically submits working orders from when the strategy processed historical data, and assumes the strategy position and account position are where you want it when you enable the strategy. This is typically used to have a strategy resume a position after disabling/enabling. If the strategy already had live orders running, the orders will resume with the new enablement of the strategy if they match the historically calculated orders. If the orders calculated from historical data do not match the live working orders, the live working orders will be cancelled and replaced by those calculated from historical data.

    Sync Account Positions is an additional option that has NinjaTrader submit an order to sync the account position to the position calculated by the strategy. (Not the other way around.)

    If you do not want the strategy to calculate a position from processing historical data. Simple add if (State == State.Historical) return; to the top of your strategy logic so historical processing is skipped. The strategy will then always start from a flat position because it has not calculated any orders.

    See the help guide documentation below for more information.
    Strategy vs. Account Position — https://ninjatrader.com/support/help..._account_p.htm
    Start Behaviors — https://ninjatrader.com/support/help..._positions.htm

    Additional information could be found in this forum thread - https://ninjatrader.com/support/foru...ion#post811541

    Let us know if we may assist further​
    <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 argusthome, 03-08-2026, 10:06 AM
    0 responses
    85 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    47 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    29 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    32 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    67 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X