Thank you for your post.
If you want your Stop Loss to move to breakeven at the same moment as you reach 50 ticks in proft, it sounds like you will need to calculate OnPriceChange. When calculating OnBarClose, the logic within OnBarUpdate() in the strategy will only be called on the close for every bar. This means that the check to see if the price moved 50 ticks in your favor will only happen once per bar, and the strategy would not be able to check the price and move the Stop Loss intra-bar. For more information about the Calculate property:
You mentioned that when you use OnPriceChange or OnEachTick, it results in a ton of entries being made. I would be curious about the conditions you are using to trigger entries, as well as whether you are using a signal name in your entry orders or not. There are internal order handling rules to prevent unwanted positions when using the Managed Approach in NinjaTrader, and the Strategy Builder strategies utilize the Managed Approach. The rules may be found here:
There is some information about signal names on entry orders in the Strategy Builder here:
As long as your entry orders have a signal name, if a condition to submit an entry is triggered and the signal name is not unique, the entry order will be ignored. Other tools you could keep in mind are the strategy settings for Entries per direction and Entry handling. The default settings may be set in the Strategy Builder on the "Default Properties" page, although the settings may be adjusted when adding the strategy to a chart or from the Strategies tab of the Control Center. When the entry handling is set to "AllEntries" then the strategy will process entry orders up until the number of Entries per direction is reached. If you have entry handling set to "UniqueEntries" then the strategy will process entry orders up until the number of Entries per direction is reached per each signal name.
Here is a screenshot of where they may be found in the Strategy Builder:
Here is a screenshot of where they may be found when adding a strategy from a chart:
There are tools for testing and debugging the behavior of a strategy, even when developing in the Strategy Builder, such as Trace Orders and Print() statements. Trace Orders may be enabled from the "Default Properties" page of the Strategy Builder by expanding "More Properties" and checking the box for Trace orders. With this enabled, information about orders will be printed to the NinjaScript Output window (Control Center > New > NinjaScript Output). This allows you to confirm when orders are placed or when they are ignored and why. For more information about Trace Orders:
For more information about using prints to debug your code, please see the following post and link to a video showing how to add prints in the Strategy Builder:
Please let us know if we may be of further assistance.

Comment