Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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).
    Brandon H.NinjaTrader Customer Service

    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 fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,404 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      95 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      8 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      159 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Yesterday, 09:29 PM
      0 responses
      8 views
      0 likes
      Last Post Belfortbucks  
      Working...
      X