Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop Losses and Targets not being placed

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

    Stop Losses and Targets not being placed

    Hi,

    I'm having trouble debugging this piece of code. When I run this code in strategy analyzer (GBPCHF as the instrument), for some reason, when I take short trades the stop loss and profit targets are not placed. When I take long trades, the stop loss is placed but not the target. Can anyone find what is causing this?

    Thanks.
    Attached Files

    #2
    Hello Sudonega,

    Thanks for your post.

    If the expected trade(s) are not appearing, this would indicate that the condition to place the order is not evaluating as true or the order is being ignored for other reasons.

    I see that you have not yet added any debugging prints in the code you shared.

    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).

    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.
    <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 Brandon,

      Thanks for your reply.

      I did previously add print statements to try and debug the issue but I then removed them for the purpose of sharing the code. What is really odd is that the SetStopLoss, SetProfitTarget and EnterShort/EnterLong statements seem to be running fine in the NinjaScript Output when I run the strategy in strategy analyzer and when I use print statements but in reality, when I look at the trades that the strategy takes it doesn't seem to be working correctly at all. I've tried to debug this but I haven't managed to find what the issue is, any help would be greatly appreciated.

      Comment


        #4
        Hello Sudonega,

        Thanks for your note.

        Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services in our support. This is so that we can maintain a high level of service for all of our clients as well as our partners.

        That said, I do not see anything specifically wrong with the script you shared. You would need to add prints to the script that print out all of the values being used to trigger the placement of your Stop/Target orders to determine if/how the orders are being submitted. Also, prints should be added that print out the price that the stop/target is being submitted to for comparison.

        TraceOrders should also be enabled which will let you know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

        Note the NinjaScript Output window and the Log tab of the Control Center when running your strategy for any issues that may arise.

        Let us know if we may assist further.
        <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 argusthome, 03-08-2026, 10:06 AM
        0 responses
        71 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        43 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        25 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        28 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        56 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X