Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling Entry and Exit Trade Logic

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

    Calling Entry and Exit Trade Logic

    My multi-timeframe trading strategy has over 250 lines of entry logic and 220 lines of exit logic. What's the typical code structure to organize the logic code so as to isolate entry and exit trade logic? ... so that...

    - entry logic is only calculated when flat, and
    - exit logic is calculated when long.

    Any examples? Do all the calculations need to be performed within the same Ninjatrader.strategy namespace or be limited to class "strategy"?

    #2
    Hello borland,

    Thank you for writing in.

    If you wish for specific logic to run only if your strategy is flat or long, you would want to check the Positions' MarketPosition property, where x would be the Bars index of the instrument:

    Code:
    // if the strategy is currently in a long position, execute this logic
    if (Positions[x].MarketPosition == MarketPosition.Long)
         // do stuff
    
    // if the strategy is currently in a flat, execute this logic
    if (Position[x].MarketPosition == MarketPosition.Flat)
         // do stuff


    You would want to keep these calculations within your strategy's class.
    Zachary G.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

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