Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need Help with Strategy error

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

    Need Help with Strategy error

    I am making a mechanical counter-trend strategy for trading futures contracts. The strategy uses the MBox Algo indicator, filtering for Springs and Upthrusts in a counter-trend direction, to identify potential trades.
    These are the rules
    • Use the MBox Algo indicator and filter for Springs and Upthrusts in a counter-trend direction.
    • Enter trades when the price breaks the previous swing high or low.
    • Exit trades at a 1:1 risk-reward ratio.
    • Only trade between 9:30 AM and 12:00 PM.
    ​ The issue is It fires multiple trades, where it shouldn't.

    The MBoxUpthrust is the original file that was working fine
    It isnt until I pasted it in a blank strategy template (with stops, time zones etc) that it stopped working properly.
    So I think I could be in trade management, but I'm not sure.​
    The AlgoMbox is the new file

    Could someone please help me out to find whats the bug in the new file thats causing it. Thanks
    Attached Files

    #2
    Hello Adam Klaus,

    Thanks for your post.

    To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.


    Further, you could use bools to control the logic in the script for placing trades. For example, you could create a bool (initially set to true) in your script and check if the bool is true in your condition to place a trade. You would call your entry order method within that condition to place the trade and set the bool to false. By doing so, the trade would only be placed when the bool is true. Note that you would need to create a condition to reset the bool to true, such as resetting the bool to true when you are in a flat position (Position.MarketPosition == MarketPosition.Flat).
    <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
      Hi Adam, just learned about this : https://youtu.be/dprA_LefyhQ​ . AI code generator for NT : https://quantwisetrading.com/coder.php , it could debug your code too
      mcosta72
      NinjaTrader Ecosystem Vendor - Quant-Wise

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      90 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      137 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      120 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X