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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X