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:	64
Size:	38.1 KB
ID:	1232706
    Click image for larger version

Name:	image.png
Views:	103
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​
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by ageeholdings, Today, 07:43 AM
    0 responses
    7 views
    0 likes
    Last Post ageeholdings  
    Started by pibrew, Today, 06:37 AM
    0 responses
    4 views
    0 likes
    Last Post pibrew
    by pibrew
     
    Started by rbeckmann05, Yesterday, 06:48 PM
    1 response
    14 views
    0 likes
    Last Post bltdavid  
    Started by llanqui, Today, 03:53 AM
    0 responses
    6 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    12 views
    0 likes
    Last Post burtoninlondon  
    Working...
    X