Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop and Target Profit using Conditions and Actions

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

    Stop and Target Profit using Conditions and Actions

    I am using the strategy builder to automate my stop loss and take profit order.

    The code works well when I use only the stop order. It places the stop market order 1 tick below Low[1].

    The code doesn't work when I apply both of the actions. Any time I take an entry, the position is automatically closed. I assume that is because there is an error and the strategy builder is rejecting my orders. However, if the conditions for entry are still met, the strategy will continue to open new positions and automatically close them until the conditions are no longer met.

    The take profit order is designed to be The Entry Price + 3* ATR (ex. if I enter long at 4000 and the ATR is 5, the TP would be placed at 4015).

    How can I apply both of these orders with the strategy builder? It is essentially the same thing as using an ATM strategy based on the variables of Low[1] and ATR.

    ​ ​​
    Attached Files

    #2
    Hello RallySquirrel,

    Thanks for your post.

    Do you see any error messages occurring in the Log tab of the Control Center when the order is expected to be placed? If so, what does the error(s) report?

    To clarify, do you mean that the entry order is submitted by calling something like EnterLong() and the entry is closed by the ExitLongLimit() order?

    Or, is the Entry or Exit method being closed at the end of a bar?

    Note from the help guide linked below: "By default, orders submitted via Entry() and Exit() methods automatically cancel at the end of a bar if not re-submitted"

    Managed Approach: https://ninjatrader.com/support/help...d_approach.htm

    I have attached an example script that demonstrates using Exit methods to submit profit target and stop loss orders using the Strategy Builder you could view.

    Ultimately, debugging prints should be added to the strategy to understand exactly how the script is processing logic and placing orders.

    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.

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

    Also, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.​

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

    https://ninjatrader.com/support/foru...121#post791121

    Let us know if we may assist further.​
    Attached Files
    <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
      Originally posted by NinjaTrader_BrandonH View Post
      Hello RallySquirrel,

      Thanks for your post.

      Do you see any error messages occurring in the Log tab of the Control Center when the order is expected to be placed? If so, what does the error(s) report?

      To clarify, do you mean that the entry order is submitted by calling something like EnterLong() and the entry is closed by the ExitLongLimit() order?

      Or, is the Entry or Exit method being closed at the end of a bar?

      Note from the help guide linked below: "By default, orders submitted via Entry() and Exit() methods automatically cancel at the end of a bar if not re-submitted"

      Managed Approach: https://ninjatrader.com/support/help...d_approach.htm

      I have attached an example script that demonstrates using Exit methods to submit profit target and stop loss orders using the Strategy Builder you could view.

      Ultimately, debugging prints should be added to the strategy to understand exactly how the script is processing logic and placing orders.

      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.

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

      Also, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.​

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

      https://ninjatrader.com/support/foru...121#post791121

      Let us know if we may assist further.​
      I reviewed the code from your example and I was able to fix the problem. Thanks for your help!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by granny24, Today, 07:43 AM
      0 responses
      2 views
      0 likes
      Last Post granny24  
      Started by granny24, Today, 07:40 AM
      0 responses
      2 views
      0 likes
      Last Post granny24  
      Started by granny24, Today, 07:39 AM
      0 responses
      3 views
      0 likes
      Last Post granny24  
      Started by jpkulkarni, Yesterday, 10:12 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by dpolyakov, 03-29-2024, 11:30 AM
      14 responses
      2,458 views
      3 likes
      Last Post larkmail  
      Working...
      X