Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Developing a Basic Strategy Structure

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

    Developing a Basic Strategy Structure

    I am developing a basic strategy and I've got a few problems I need help with. I don't think I was clear in my first post hence the 'edit'.

    1. I only want to Enter 'Once' when an indicator (RSI & MACD) goes Long. When it hits Breakeven or Stop Loss or TrailStop I don't want to re-enter on the same run until there's another Long Run.
    I have tried 'BarsSinceExit' and 'BarsSinceEntry' but maybe there is a better way?? Cause I only want a single entry on indicator confirmation.

    2. I'm trying to Exit (profit target) when price 'crosses below' EMA of 14. And I can't seem to figure out the coding for this. I thought this would be simple to do but I've tried everything I could think of.
    Technically, I would like to exit when ((RSI & MACD) != Long) but that doesn't seem to work. I would settle for either TBH

    3. When I use the Breakeven Example code, than the Trailstop/Profit Target in State.Configure no longer functions and vice versa.

    Please help.
    Last edited by Fbraun378; 09-30-2023, 01:15 PM.

    #2
    Hello Fbraun378,

    Thanks for your post.

    A bool could be used to control a strategy's logic to place one trade when the condition to place the trade is true. You could create a bool variable called something like 'OkToTrade'. The variable could be set to true when you are in a Flat market position (Position.MarketPosition == MarketPosition.Flat). Then, in your condition to place the entry order check if the bool is true. One line after calling your Entry order method to place the trade, set the bool to false.

    That way, the Entry order would only be placed when the bool is true and the bool would be false after the Entry order is placed and resets to true when you are in a Flat market position.

    You could check if you are in a Long market position (Position.MarketPosition == MarketPosition.Long) and create a condition checking if the Close price crosses below EMA(14) indicator and call ExitLong() to exit the Long position.

    Position.MarketPosition: https://ninjatrader.com/support/help...etposition.htm
    Creating Crossover conditions: https://ninjatrader.com/support/help...on_builder.htm

    My colleague Chelsea has created educational examples of strategy builder breakeven and trailing stop in the strategy builder here:
    https://ninjatrader.com/support/forum/forum/suggestions-and-feedback/suggestions-and-feedback-
    aa/103992-request-breakeven-functions-in-strategy-builder#post806596

    These reference samples could be reviewed to see how to set up breakeven and trailing stop logic in your script. Note that Set methods (SetStopLoss()/SetProfitTarget()/SetTrailStop()) cannot be used with Exit methods as this would go against the Managed Approach Internal Order Handling rules noted on the help guide page below.

    Managed Approach Internal Order Handling Rules: https://ninjatrader.com/support/help...d_approach.htm

    To understand exactly how your logic in a strategy is behaving when the strategy is not working as expected, debugging steps should be taken. ​Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121
    <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


      #3
      Thank You BrandonH.
      Lots of helpful information here I will look into.

      Another question just came up, I want to put (Long Trades = bool on the conditions UI side but how would I connect the logic to the actions or variable UX side? Any ideas?
      The strategy builder only has variable bools on the variable (actions) bottom side so calling a UI bool... IDK

      Comment


        #4
        Hello Fbraun378,

        Thanks for your notes.

        To clarify, you want to create a user-defined bool property called LongTrades in your strategy. Is that correct?

        You could create a user-defined input on the 'Inputs and Variables' screen of the Strategy Builder. The input would be created in the 'Inputs' section of this screen, not the 'Variables' section.

        After creating the user-defined input, you could use it in the strategy's logic, such as creating a condition that checks if the bool input is true or false.

        See this help guide documentation below for more information about Strategy Builder Screens: https://ninjatrader.com/support/help...er_screens.htm

        <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 NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        67 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        142 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        76 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        47 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        51 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X