Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why exitlongstop order didin't work?

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

    Why exitlongstop order didin't work?

    Hello,

    Why exitlongstop order didin't work and didin't close transaction?

    This is a code and screenshot of example where there was no stop loss order.

    protected override void Initialize()
    {
    SetProfitTarget("", CalculationMode.Ticks, 72);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (High[0] < High[1]
    && Low[0] > Low[1])
    {
    EnterLongStop(DefaultQuantity, High[0] + 1 * TickSize, "dluga");
    ExitLongStop(High[0] + -36 * TickSize, "dluga_stop", "dluga");
    }
    }


    Thanks for help
    Attached Files

    #2
    Hello DanielJ,

    You can't have an exit order in the same block as your entry order. It will be ignored the first time through since the entry order has not been proccessed. The conditions then have to be true on the next pass in order to submit the order.

    If you want ExitLongStop() to function as a stoploss order, you could, for example, tie it to a BarsSinceEntry() condition.

    if (BarsSinceEntry() >= 1)
    ExitLongStop(High[0] + -36 * TickSize, "dluga_stop", "dluga");
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Sorry for question, but this is 2nd day with ninja script.

      Can you show me the place where I should paste it in my code?

      Thank you

      Comment


        #4
        Sure. It goes in OnBarUpdate() but outside of your entry block. If you only have one statement to execute after an if block, then you don't need the curly brackets { }.

        protected override void OnBarUpdate()
        {
        // Condition set 1
        if (High[0] < High[1]
        && Low[0] > Low[1])
        {
        EnterLongStop(DefaultQuantity, High[0] + 1 * TickSize, "dluga");
        }

        if (BarsSinceEntry() >= 1)
        ExitLongStop(High[0] + -36 * TickSize, "dluga_stop", "dluga");

        }
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Ok thank you. I pasted the code like you show but unfotrunatly the transaction from the first post wasn't closed.I compiled and run strategy again an there is no stop loss order 36 ticks below entry point.

          Daniel

          Comment


            #6
            Daniel,

            TraceOrders is useful for debugging strategy order submission issues. Add this line to your initialize() method:
            TraceOrders = true;

            You'll then see output by clicking Tools > output window.

            Print values you're checking for, such as Print(BarsSinceEntry());

            Additional help for debugging is available here:
            Debugging your NinjaScript Code
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            662 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            376 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            110 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            580 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X