Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Double contracts at StopLoss

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

    Double contracts at StopLoss

    Is there a way in NT to reverse entry with double contract size at SL touch? (reversing the entry bias)

    Im doing manually but I would like to do it with the ATM, is that possible?

    #2
    Hello DoomNM,

    This is posted in the General Development section of the forums.

    To confirm are you developing an Addon using the Account object to submit orders, or is this a NinjaScript Strategy you are developing?

    From an Addon, you can attach an event handler method to the <Account>.ExecutionUpdate event, and when the stop order fills, submit the new entry order order with double the quantity.


    If you are using StartAtmStrategy() to use an Atm Strategy, you would need to use the addon approach to determine the Atm stop loss has filled. The name of the order will be 'STOP1'.
    You may find the AtmStrategyIdentifier has similar code you may find helpful.
    This indicator serves to provide labels for Atm strategies that are present on your chart. Each new Atm strategy will rotate through the colors defined in your Brush Collection. Simply add to a chart, select the data series you want to have labels added to, choose your font and add all the brushes/colors you want [&#8230;]


    From a NinjaScript Strategy you can determine the stop loss has filled in OnExecutionUpdate() and then send a new entry order with double the quantity. However, this would not work if the orders are being submitted with AtmStrategyCreate() and would only work with stop orders submitted directly by the strategy with SetStopLoss() or ExitLongStopMarket() / ExitShortStopMarket().

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Im sorry but I don't understand the solutions you provided, I think I don't have enough computer knowledge for that.

      I just simply searching for ATM option that reverses entries but instead 1 contract, entering with double size of previous entry.

      If this is not integrated in NT would be really helpful imo

      Comment


        #4
        Hello DoomNM,

        Thank you for clarifying. I've moved this thread to the Desktop Platform Technical Support section of the forums as this does not pertain to development (programming in C#).

        Unfortunately, there is not a feature with Atm strategies to double the quantity when reversing. Something such as this would have to be custom programmed as a NinjaScript.

        You would need to manually change the order quantity on the stop and limit orders on the Orders tab of the Control Center (double click the quantity field for the order row to modify the quantity).
        Or you would need to manually place the new entry order with a different quantity.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Oh I see.
          Anyways I asked to ChatGPT to know how to make the ninjascript and this is what it said (I suppose its wrong)

          region Using declarations using NinjaTrader.Cbi;
          using NinjaTrader.Gui.Tools;
          using NinjaTrader.NinjaScript.StrategyAnalyzer;
          using NinjaTrader.Data;
          using NinjaTrader.NinjaScript.Strategies;
          using NinjaTrader.NinjaScript.StrategyAnalyzerColumn;
          #endregion

          namespace NinjaTrader.NinjaScript.Strategies
          {
          public class DoubleContractAtStopReverse : Strategy
          {
          private int entrySize = 1; // Initial contract size
          private double stopLoss = 20; // Stop loss in ticks
          private double profitTarget = 40; // Profit target in ticks
          private double stopPrice;
          private bool stopHit = false;

          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = "Strategy reverses with double size when stop loss is touched";
          Name = "DoubleContractAtStopReverse";
          Calculate = Calculate.OnEachTick;
          EntriesPerDirection = 1;
          EntryHandling = EntryHandling.AllEntries;
          IsExitOnSessionCloseStrategy = true;
          ExitOnSessionCloseSeconds = 30;
          IsFillLimitOnTouch = false;
          MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
          StopTargetHandling = StopTargetHandling.ByStrategyPosition;
          StartBehavior = StartBehavior.WaitUntilFlat;
          }
          }

          protected override void OnBarUpdate()
          {
          // Ensure strategy runs in real-time and we have enough data
          if (CurrentBars[0] < 1 || State != State.Realtime)
          return;

          // Check if there is no open position
          if (Position.MarketPosition == MarketPosition.Flat)
          {
          // Enter an initial long position with entry size 1
          EnterLong(entrySize, "InitialLong");

          // Set stop loss and profit target for the initial position
          stopPrice = Close[0] - stopLoss * TickSize;
          SetStopLoss("InitialLong", CalculationMode.Price, stopPrice, false);
          SetProfitTarget("InitialLong", CalculationMode.Ticks, profitTarget);
          }

          // Check if stop loss has been touched and the position was closed
          if (Position.MarketPosition == MarketPosition.Flat && stopHit)
          {
          // Reverse with double contract size
          EnterShort(entrySize * 2, "ReversedShort");

          // Set stop loss and profit target for reversed position
          stopPrice = Close[0] + stopLoss * TickSize;
          SetStopLoss("ReversedShort", CalculationMode.Price, stopPrice, false);
          SetProfitTarget("ReversedShort", CalculationMode.Ticks, profitTarget);

          stopHit = false; // Reset stop hit flag
          }
          }

          protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
          {
          // Check if stop loss was hit
          if (execution.Order != null && execution.Order.Name == "Stop loss")
          {
          stopHit = true;
          }
          }
          }
          }

          This would be valid for what im searching for?

          Comment


            #6
            Hello DoomNM,

            The general logic here looks pretty good. The reversal would not be immediate and would require another bar update since it's in OnBarUpdate() instead of OnExecutionUpdate().
            The entry is made anytime the position is flat instead of with some criteria.

            The SetStopLoss() and SetProfitTarget() methods should be called before the entry order method not after.

            But yes, this is basically what I was suggesting.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Could you fix the ChatGPT ninjascript errors to do what we are talking about? Or tell to ChatGPT to fix whats wrong.

              All these parameters sounds to Chinese to me.

              Thx

              Comment


                #8
                Hello DoomNM,

                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 or one on one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates.

                Through email or on the forum we are happy to answer any specific questions you may have about NinjaScript if you decide to code this yourself. We are also happy to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

                You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.​

                This thread will remain open for any community members that would like to create your script as a convivence to you.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                606 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                353 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                105 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                560 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                561 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X