Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

{NinjaScript} - Stop Orders

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

    {NinjaScript} - Stop Orders

    Hello,

    I am trying to create stop orders, both sales and purchases.

    They must be able to be created no matter if a previous stopOrder already exists, whenever OnBarUpdate () is executed, the order that is written in the code must be created..

    even if they are opposing sales and purchases, they must always be created.

    Here is my code, but is not working as I described:

    protected override void OnBarUpdate()
    {
    if(condition1)
    {
    SetStopLoss(signalName,CalculationMode.Price,sl,fa lse);
    SetProfitTarget(signalName,CalculationMode.Price,t p);
    EnterLongStopMarket(0,true,10000,stopPrice,signalN ame);
    }
    if(condition2)
    {
    SetStopLoss(signalName,CalculationMode.Price,sl,fa lse);
    SetProfitTarget(signalName,CalculationMode.Price,t p);
    EnterShortStopMarket(0,true,10000,stopPrice,signal Name);
    }

    }

    Please, could you help me?

    #2
    Hello fscabrera03,

    Are you trying to place a buy stop entry and sell stop entry at the same time?

    This would violate the internal handling rules for the managed approach.

    "Methods that generate orders to enter a position will be ignored if:
    The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction"


    The unmanaged approach would be necessary to place orders in opposite directions.
    Below is a link to an example.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you Chelsea,
      How works Stop Orders when fundamentals are happening? There are some coding tip to handle stop orders in that kind of volatile scenarios to protect the account and the strategy when price is changing so fast?
      Any recomendation?

      Comment


        #4
        Hello nandocabrera87,

        Welcome to the NinjaTrader forums!

        Fundamental data received in OnFundamentalData will not affect orders.

        Stop order will become a market or limit when the stop price is reached.

        I don't have any custom logic I can provide you for dealing with fast markets.

        Is there a specific error you having an issue with?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you!
          Yes, My strategy are having trouble when market moves fast.
          Im attaching the chart, the orders, positions, logs and 3 error windows that opens when the price is where the grafic shows.
          Can you help me?
          Site doesnt let me upload xlsx files for executions and orders but I can share you by drive if you can.
          I cant undestand what is happening.
          Thank you so much

          Attached Files

          Comment


            #6
            Hello fscabrera03,

            I suggest using debugging prints to check the price of p, when the strategy enters and the rejection is seen. You may use the Playback Connection to reproduce behaviors that have happened with realtime data.

            Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

            Playback Connection - https://ninjatrader.com/support/help...connection.htm

            Buy Stops must be above the ask and Sell Stops must be below the bid. You may use GetCurrentBid/GetCurrentAsk to check the bid/ask prices and ensure the stops will be submitted at an appropriate level.

            GetCurrentBid - https://ninjatrader.com/support/help...currentbid.htm

            GetCurrentAsk - https://ninjatrader.com/support/help...currentask.htm

            I may also suggest protecting your entry conditions with a position check so that if condition2 becomes true after you entered long, the stop loss does not get modified.

            Position.MarketPosition - https://ninjatrader.com/support/help...etposition.htm

            We look forward to assisting.

            Comment


              #7
              Hi
              I've noticed many times that stop losses and take profits do not happen after x pips once it is reached in my custom strategies and strategies that come with NT8. Why is this not happening?
              Could you help?

              Comment


                #8
                Hello honest-trader,

                Is the order in a working state with a stop or limit price at the time the current price reaches the order?

                Have you enabled TraceOrders and added prints to show when the condition to place the order is true?

                Below is a link to a forum post that demonstrates how to use Print() and TraceOrders to understand behavior.


                Please save the output from the NinjaScript Output window to a text file and include this with your next post.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  So you need to know coding for this by inserting the print output! Is it notpossible to modify the strategy using the builder and insert this print?

                  Comment


                    #10
                    Hello honest-trader,

                    Please review the forum post I have linked which includes the video 'Debugging using prints with the Strategy Builder'.

                    No, you do not need to know C# coding to use the Strategy Builder.

                    TraceOrders is enabled in the Defaults. This will require removing and re-adding the instance of the script as noted in the forum post linked.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Today, 05:17 AM
                    0 responses
                    44 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    124 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    65 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    42 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    46 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X