Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stoplimit orders

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

    Stoplimit orders

    Hi,

    I am testing the order methods offered by the Managed Aproach.

    I use the method EnterLongStopMarket() to define the entry price for long position. When the order is executed, at the same time should enter two orders; a target (ExitLongLimit) and the stop (ExitLongStopLimit) but it does not work, How can I solve these issues?

    Thanks,

    Richard Martínez M.

    Code:
    protected override void OnBarUpdate()
    		{
                if (State == State.Historical)
                    return;
    
                if (CurrentBar < BarsRequiredToTrade)
                    return;
    
                if (BarsInProgress == 1)
                {
                    if (Position.MarketPosition == MarketPosition.Flat)
                    {
                        if (entryOrder != null)
                        {
                            if (stopPrice.ApproxCompare(Close[0]) == 1)
                            {
                                CancelOrder(entryOrder);
                            }
                        }
                    }
                    else if (Position.MarketPosition == MarketPosition.Long)
                    {
                        if (isEntry)
                        {
                            Print("Target Order Position");
                            ExitLongLimit(targetPrice, "Target", "entryOrder");
                            Print("Target Order Colocda");
    
                            Print("Target Order position");
                            ExitLongLimit(stopPrice, "Stoploss", "entryOrder");
                            Print("Stop Order Colocda");
    
                            isEntry = false;
                        }
                    }
                }
    
                if (BarsInProgress == 0)
                {
                    if (Position.MarketPosition == MarketPosition.Flat)
                    {
                        if (entryOrder == null && Close[0] > Open[0] && !isEntry)
                        {
                            Print("Enter Long Block Start - " + Time[0]);
                            EnterLongStopMarket(Close[0] + 2 * TickSize, "entryOrder");
                            barEntry = CurrentBar;
                            targetPrice = Close[0] + 10 * TickSize;
                            stopPrice = Close[0] - 5 * TickSize;
                            isEntry = true;
                            Print("Enter Long Block End - " + Time[0]);
                        }
                        else if (barEntry + 1 == CurrentBar)
                        {
                            Print("Cancel Long Block Start - " + Time[0]);
                            CancelOrder(entryOrder);
                            isEntry = false;
                            Print("Cancel Long Block End - " + Time[0]);
                        }
                    }
                }
    		}

    #2
    Hello Richardmm,

    Thank you for the post.

    I wanted to further clarify the problem here. You did not mention the result of the prints you have shown, are your prints showing up but the orders are not? What specifically is happening when this is run in regard to the orders and prints?

    If you are not seeing the orders submit, and you are seeing prints, have you tried using TraceOrders to see if you are hitting a managed order error?


    I look forward to being of further assistance.

    Comment


      #3
      Thank you for the suggestion. I will try with TraceOrders. However, I have other question, When I use ExitLongStopLimit or ExitLongLimit these orders are sent to the broker or they are executed internally by NinjaTrader?

      Richard Martínez M.

      Comment


        #4
        Hello Richardmm,

        These would be sent to the broker as the type of order they are. If you are trying to use simulated (hidden) orders, you would need to either use logic and submit market orders or use the SetStopLoss with the Simulated overload.

        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        68 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        41 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        24 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        27 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        54 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X