Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set Take protit and Stop Loss orders strategy

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

    Set Take protit and Stop Loss orders strategy

    Hi guys, i'm managing how to set a take profit and stop loss inside a strategy but it seems to only takes 1 of the below orders at the same time.
    At some point of the code an entry is set, in this case a short one and then i try to set a BuyLimit to set the TP and a BuyStopMarket to set the stop loss but NT8 only set one of them.
    In this case the EnterLongLimit is set but not the EnterLongStopMarket, if i comment the EnterLongLimit of change the order, the EnterLongStopMarket is set but not the EnterLongLimit.

    I really don't get it, so anyone has a clue about it?

    Thanks!

    Code:
    .....
    else if (position.MarketPosition == MarketPosition.Short)
     {
          EnterLongLimit(lots, takeProfit, "BuyLimitEntry"); 
          EnterLongStopMarket(lots, stopLoss, "BuyStopMarketEntry");
    }

    #2
    When I am in a short position, I usually use ExitShortStopLimit() for my stop orders and ExitShortLimit() for my take profits.

    Comment


      #3
      Originally posted by rockmanx00 View Post
      When I am in a short position, I usually use ExitShortStopLimit() for my stop orders and ExitShortLimit() for my take profits.
      Thanks for the reply rockmanx, but i tried with those one and it does not work either. They are not set visually in the chart.

      Comment


        #4
        What does your code look like? It works fine for me?

        Comment


          #5
          If you are placing limit orders that aren't on the wrong side of price, it should stay there. So for it to not be set visually on the chart means they must not be triggering. I can't think of any other way they can be set without being set visually on the chart.

          Comment


            #6
            Hello Dyoser,

            The code you had shown is two entry orders in opposite directions which will be ignored. For a stop and target you would generally do something like this:


            SetProfitTarget(CalculationMode.Ticks, 10);
            SetStopLoss(CalculationMode.Ticks, 10);
            EnterLong();

            This will submit targets upon the entry filling.

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              Hello Dyoser,

              The code you had shown is two entry orders in opposite directions which will be ignored. For a stop and target you would generally do something like this:


              SetProfitTarget(CalculationMode.Ticks, 10);
              SetStopLoss(CalculationMode.Ticks, 10);
              EnterLong();

              This will submit targets upon the entry filling.
              Hi, Jesse thanks for the reply.
              What i'm trying to do here is, when i search for filled orders, in this code example let's say a filled buy market is there
              i want to set a sell limit and a sell stop limit around it but for some reason in the long code section only one of them is placed, the other one is not even listed in the orders list.
              The same happens if i set a sell market that is filled, the buy limit and buy stop limit are not set, only one of them.
              My question is how can i set those limits at the same time like the image attached?


              Code:
              // Verify executed positions
              foreach (var position in Account.Positions)
              {
                 if (position.MarketPosition == MarketPosition.Long)
                 {
                    Print($" TP set at {takeProfit}");
                    EnterShortLimit(position.Quantity, takeProfit, "SellLimitEntry");
              
                    Print($" SL set at {stopLoss}");
                    EnterShortStopMarket(position.Quantity, stopLoss, "SellStopMarketEntry");
                    break;
                }
                else if (position.MarketPosition == MarketPosition.Short)
                {
                  Print($" TP set at {takeProfit}");
                  EnterLongLimit(position.Quantity, takeProfit, "BuyLimitEntry");
                  Print($" SL set at {stopLoss}");
                  EnterLongStopMarket(position.Quantity, stopLoss, "BuyStopMarketEntry");
                  break;
                }
              }
              Click image for larger version

Name:	ninja_orders.jpg
Views:	124
Size:	66.1 KB
ID:	1335036
              Attached Files

              Comment


                #8
                Hello Dyoser,

                The code you are using is Entry orders not sell orders. You cannot submit two entry orders like you are. If you are trying to exit a position you need to use the methods that have "Exit" in their name.

                If we assume you entered log you need to submit an ExitLong order to exit that position.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                71 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                143 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                76 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                47 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                51 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X