Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

issues with getting the reversal to trigger

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

    issues with getting the reversal to trigger

    Hello ChelseaB,

    I've come onto the forum today to query a similar issue and found this recent thread. Similarly to webus, I'm trying to attach a reversal order to just above a stop limit order, but I'm trying to do it in State.Realtime. I am using a managed approach, and have similar issues with getting the reversal to trigger. The error commonly received is: Order '9832749823749827492834' can't be submitted: the OCO ID 'insert string of numbers here' cannot be reused. Please use a new OCO ID: affted Order: Sell 1 Limit @ 11204.5'. So I've tried using an OCO counter to assign a new OCO string, but the error remained the same. The example here:
    "private string GetUniqueOCOId()
    {
    string ocoId = ocoCounter.ToString();
    ocoCounter++;
    return ocoId;
    }​"
    Is it impossible to reverse an order on stop without using an unmanaged approach?

    Also, I found the video example to be extremely helpful and enlightening. Is there a repository of these videos somewhere?

    Didn't mean to hijack the thread, but just add something similar and relevant.

    Thanks,
    J

    #2
    Hello J,

    I've moved your post to a new thread, as this error is not related to GetRealtimeOrder() and instead an issue with re-using an OCOID.
    https://forum.ninjatrader.com/forum/...eorder-concept

    You've mentioned:
    I am using a managed approach
    The managed approach cannot specify OCOIDs. Are you certain you are not using the unmanaged approach?

    With the unmanaged approach OCO IDs cannot be re-used with new orders once an order using that OCO ID has filled, been cancelled, or was rejected and a new OCO ID must be used.

    I generally recommend using GetAtmStrategyUniqueId() to generate a new unique id.

    See the UnmanagedOCOBracketExample_NT8 and ProfitChaseStopTrailUnmanagedExample_NT8 examples below that demonstrates using OCO with the unmanaged approach.
    https://ninjatrader.com/support/foru...579#post770579
    https://ninjatrader.com/support/foru...269#post802269
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      ChelseaB,

      First, thank you so much for moving this to a dedicated post.

      Second, nearly all of the feedback and responses from you are above and beyond. I have learned so much from reading through your posts; your responses along with help from a LLM basically have taught me all the C#/NinjaScript needed to put together my algorithm in script format so far, so I can't thank you enough.

      Onto the subject at hand... I was able to find an old example you used when sharing how to set a ProfitChaseStopTrail, including an example of an unmanaged approach method; attached herewith. Upon review of this I thought: whoa, this is way over my head. To that end, it seemed like a lot of code was necessary to take an unmanaged approach, but yes in an ideal world I'd rather take an unmanaged approach without being overly complex and with the ability to build it around my algorithm.

      I see that the thread you posted here is probably going to be helpful to me and as it's 8 pages it will take some time to fully peruse. In the interim maybe I can explain my goal and you can tell me if it's accomplishable without hiring a developer. I'll give you the conditions and steps I've taken so far if you would be kind enough to give some feedback.

      1. Position is taken either long or short based on conditions - coded and working
      2. Trailing stop is placed that correctly trails open profit for every tick using a Trail Size and Trail Frequency of 1 tick - coded and working
      3. If stop is hit, take a reversal in the opposite direction but using the same trailing stop - not coded
      4. If stop is hit again, take a reversal in the opposite direction but using the same trailing stop - not coded
      5. If stop is hit again, no reversal taken, resume to original conditions for long and short trades - not coded

      The way I see it is that I need to set a flag for each time a stop is hit. So I dedicated a flag for the initial stop and the second - currently private bool isReversal & isReverseReversal. Both operate as false, but want to flag true if 1st stop and then 2nd is hit, then no stop for the 3rd, and a return to my original conditions. I'm now seeing in the previous thread that this came from that it's possible to name entryOrder so I can tie them all together to flag true/false. I feel like I'm on the right track to accomplish this, just missing some knowledge.

      Having said all this, are you saying it is possible to do this in the way of an ATM? Currently, I'm running the strategy as is on a separate account, then taking manual trades via another account with ATM managing the trail stop and reverse conditions and then on the 2nd reversal removing the buy/sell order, which will keep the conditions for the original entries true. If it's possible to do this without 300 lines of code, or I have the option to code it directly into the strategy, it would be heaven sent.

      Again, your wisdom and guidance has been truly helpful.

      J
      Attached Files

      Comment


        #4
        I just want to add to this too, that I'm using Calculate.OnBarClose intentionally so whatever I'm designing has to work for that. The way that I created the stop trail is working within OnBarClose. This is a necessary aspect of the algorithm.

        Comment


          #5
          Hello J,

          I appreciate the kind words.

          My hope is that the example provides a few key ideas for a successful script, that can reduce the time it takes to learn.

          Where you have mentioned:
          3. If stop is hit, take a reversal in the opposite direction but using the same trailing stop - not coded
          By 'using the same trailing stop', you simply mean the logic only in reverse for the opposite position, is this correct?
          Use a different set of conditions for the short entry order than the long entry order.
          Code:
          if (longEntryOrder != null && execution.Order == longEntryOrder)
          Code:
          if (shortEntryOrder != null && execution.Order == shortEntryOrder)

          Check for the long position's limit or long stop order to be the order filled in OnOrderUpdate separately from the short positions limit and stop. Submit the entry in the opposite direction when the exit order orderstate is orderstate.filled.

          With the short position, for the limit instead of adding ticks to the limit price subtract them.
          Code:
          currentPtPrice    = execution.Order.AverageFillPrice - ProfitTargetDistance * tickSizeSecondary;
          Code:
          currentPtPrice    = Close[0] - ProfitTargetDistance * tickSizeSecondary;
          For the stop instead of subtracting ticks to the stop price add them.
          Code:
          currentSlPrice    = Close[0] + StopLossDistance * tickSizeSecondary;
          Code:
          currentSlPrice    = execution.Order.AverageFillPrice + StopLossDistance * tickSizeSecondary;
          Where you have mentioned:
          4. If stop is hit again, take a reversal in the opposite direction but using the same trailing stop - not coded
          5. If stop is hit again, no reversal taken, resume to original conditions for long and short trades - not coded
          Increment a integer as a counter each time ​an exit order fills. In the condition that submits the reversal order check that the values is less than 3. In the entry conditions if the value is 0 or is 3, allow for a new entry.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hi Chelsea,

            Thanks so much for your response. I think we're on the same page re: using the same trailing stop, that is that I don't want to create a new stop and trailing conditions each time a stop is hit, rather use the same stop_price, target, etc.

            I like the idea of adding an increment integer to count the exit order fills, but before implementing that I am having a little issue understanding how to implement the code you're suggesting. I am handling the stop conditions upon entry long/short within OnBarUpdate. I am then using OnExecutionUpdate to manage the order state, and lastly OnMarketData to manage the trailing stop. Are you able to tell within the code where I might be going wrong? I'm not sure how to input your suggestions into what I currently have coded.

            Code:
            private double Stop_Price;
            private double Stop_Trigger;
            private double Target_Price;​
            private Order longEntryOrder = null; // Track the long entry order
            private Order shortEntryOrder = null; // Track the short entry order
            private Order stopOrder = null; // Track the stop loss order
            private Order targetOrder = null; // Track the profit target order
            private int sumFilled = 0; // Variable to track the quantities of each execution making up the entry order
            private OrderState longEntryOrderState = OrderState.Unknown;
            private OrderState shortEntryOrderState = OrderState.Unknown;​
            
                            shortEntryOrder = EnterShort(Convert.ToInt32(DefaultQuantity), ""); // Enter short trade
                            longEntryOrder = EnterLong(Convert.ToInt32(DefaultQuantity), ""); // Enter long trade
            
            
            protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)
            {
                if (orderState == OrderState.Filled)
                {
            
                }
            }
            
            protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time)
            {
                // Check if the executed order is the long entry order
                if (longEntryOrder != null && execution.Order == longEntryOrder)
                {
                    longEntryOrderState = execution.Order.OrderState;
            
                    // Update the trailing stop for the long entry
                    if (longEntryOrderState == OrderState.Filled || (longEntryOrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                    {
                        // We sum the quantities of each execution making up the entry order
                        sumFilled += execution.Quantity;
            
                        // Submit exit market order for partial fills
                        if (longEntryOrderState == OrderState.Filled && sumFilled < execution.Order.Filled)
                        {
                            stopOrder = ExitLong("MyStop", "");
                            targetOrder = ExitLong("MyTarget", "");
                        }
            
                        // Resets the entryOrder object and the sumFilled counter to null / 0 after the order has been filled
                        if (sumFilled == execution.Order.Filled)
                        {
                            longEntryOrder = null;
                            sumFilled = 0;
                        }
                    }
                }
            
                // Check if the executed order is the short entry order
                if (shortEntryOrder != null && execution.Order == shortEntryOrder)
                {
                    shortEntryOrderState = execution.Order.OrderState;
            
                    // Update the trailing stop for the short entry
                    if (shortEntryOrderState == OrderState.Filled || (shortEntryOrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                    {
                        // We sum the quantities of each execution making up the entry order
                        sumFilled += execution.Quantity;
            
                        // Submit exit market order for partial fills
                        if (shortEntryOrderState == OrderState.Filled && sumFilled < execution.Order.Filled)
                        {
                            stopOrder = ExitShort("MyStop", "");
                            targetOrder = ExitShort("MyTarget", "");
                        }
            
                        // Resets the entryOrder object and the sumFilled counter to null / 0 after the order has been filled
                        if (sumFilled == execution.Order.Filled)
                        {
                            shortEntryOrder = null;
                            sumFilled = 0;
                        }
                    }
                }
            
                // Check if the executed order is the stop loss order for the long position
                if (stopOrder != null && orderId == stopOrder.OrderId && marketPosition == MarketPosition.Long && execution.Order.OrderState == OrderState.Filled)
                {
                    // Submit the market order for short position after the stop is filled
                    shortEntryOrder = EnterShort(stopOrder.Quantity, ""); // Enter short trade in the opposite direction
                    stopOrder = null; // Reset the stop order object after the order has been filled
                }
            
                // Check if the executed order is the stop loss order for the short position
                if (stopOrder != null && orderId == stopOrder.OrderId && marketPosition == MarketPosition.Short && execution.Order.OrderState == OrderState.Filled)
                {
                    // Submit the market order for long position after the stop is filled
                    longEntryOrder = EnterLong(stopOrder.Quantity, ""); // Enter long trade in the opposite direction
                    stopOrder = null; // Reset the stop order object after the order has been filled
                }
            }
            
            
                    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
                    {
                    // Print some data to the Output window
                    if (marketDataUpdate.MarketDataType == MarketDataType.Last)
                    {
                        if ((Position.MarketPosition == MarketPosition.Long)
                             && (Stop_Price != 0)
                             && (marketDataUpdate.Price >= Stop_Trigger))
                        {
                            Stop_Price = (marketDataUpdate.Price - (Trail_Size * TickSize)) ;
                            Stop_Trigger = (marketDataUpdate.Price + (Trail_frequency * TickSize)) ;
                            SetStopLoss("", CalculationMode.Price, Stop_Price, false);
                            Print("Setting Stop Longs ="+Stop_Price);
            
                        }
            
                        if ((Position.MarketPosition == MarketPosition.Short)
                             && (Stop_Price != 0)
                             && (marketDataUpdate.Price <= Stop_Trigger))
                        {
                            Stop_Price = (marketDataUpdate.Price + (Trail_Size * TickSize)) ;
                            Stop_Trigger = (marketDataUpdate.Price - (Trail_frequency * TickSize)) ;
                            SetStopLoss("", CalculationMode.Price, Stop_Price, false);
                            Print("Setting Stop Shorts ="+Stop_Price);
                        }
                    }
            
                    }​
            ​In this context, should currentPtPrice be Target and currentSlPrice be Stop_Price? Where stopOrder and targetOrder exist I've tried to EnterShort /EnterLong rather than exit and that doesn't work. If you could give some guidance on how to fit your suggestions into the current context of the code it would be most helpful.

            Thanks,
            J

            Comment


              #7
              Hello J,

              You cannot re-use the stop and limit order from a previous trade. You will have to submit new orders.

              The counter would be in OnOrderUpdate() (or could be in OnExecutionUpdate() if you really wanted..) when the entry order has filled.

              if (order.OrderState == OrderState.Filled && (order.Name == "longEntry" || order.Name == "shortEntry")
              {
              myCounter++;
              }

              currentPtPrice is a double variable that holds the limit price that will be used when calling SubmitOrderUnmanaged for the sell limit order in the case of a long position, or for the buy limit order in the case of a short position.

              currentSlPrice is a double variable that holds the stop price that will be used for the stop order.

              These variables just hold the price value that will be submitted for the limit and stop orders.

              Where stopOrder and targetOrder exist I've tried to EnterShort /EnterLong rather than exit and that doesn't work.
              Unfortunately, I'm not understanding what this means..

              Are you trying to submit an entry in the opposite direction when an exit order fills in OnOrderUpdate() (or OnExecutionUpdate())?

              if (longProfitTarget.OrderState == OrderState.Filled)
              {
              EnterShort();
              }
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi Chelsea,

                Thanks for the response again. I am not trying to create the counter at this point and that is not included in my code example.

                I am not using a limit order for my entry, they are market orders or at least I believe they are according to the help guide.
                Example of Entry: shortEntryOrder = EnterShort(Convert.ToInt32(DefaultQuantity), "")

                I am using the following as Profit Target and Stop Loss:
                SetProfitTarget("", CalculationMode.Price, Target_Price);
                SetStopLoss("", CalculationMode.Price, Stop_Price, false);​

                I believe this sets a Limit order for the ProfitTarget and Stop Market Order for the Stop Order, also according to the help guide.

                I've provided the code that I'm using to turn the StopLoss into a trailing stop within OnMarketData.

                With regard to your examples, I recognize that currentPtPrice and currentSlPrice are variables, to which I provided the variables I'm already using within the code example and asked if you could relate these two variables to what I'm using.

                currentPtPrice is a double variable that holds the limit price that will be used when calling SubmitOrderUnmanaged for the sell limit order in the case of a long position, or for the buy limit order in the case of a short position.

                currentSlPrice is a double variable that holds the stop price that will be used for the stop order.

                These variables just hold the price value that will be submitted for the limit and stop orders.​
                That makes sense. But if I'm using a trailing stop, that is, a stop that moves based on price action (not SetTrailStop), and I use a limit order, how will I move that limit order in conjunction with the stop price? With regard to SubmitOrderUnmanaged, this was not used in your example previously and it is not used in the code. If that's what I should be using, is there a relevant example you can point me towards?

                Where stopOrder and targetOrder exist I've tried to EnterShort /EnterLong rather than exit and that doesn't work.
                Unfortunately, I'm not understanding what this means..
                This is in reference to the code example provided, however I'm unsure as to how relevant the onExecutionUpdate in the example actually is.

                Set aside the counter issue, all I'm trying to do is follow a stoploss around as it moves, and set a trade in the same direction as the stop loss, but opposite the trade. So to your example, yes, if I'm in a short position, and I have a buy profit target, and a buy stop loss, I'd like to place a buy limit above the stop loss, and I need that buy limit to follow along the stop loss as it moves down and I can offset the buy limit by a tick or two (offset above the stoploss). If I was short, and I'm stopped out, and therefore in a new long position, I want that long position to have the same size profit target, and same type of trailing stop. If I have to duplicate the stop and name it, that's fine. If I have to name each entry trade, that's fine. If I have to name every profit target, that's fine. I just need to know that that's what is required to make this possible.

                If you have an example that you can point to in which this specific setup occurs, submitting a limit order in the same direction as the OCO orders already on the field in which one of those orders trails and the order submitted also trails, that would be great. In the initial example you provided, I believe it specifically is for submitting orders that are in opposing directions and pairing them as an OCO. Rather, I'll have two OCOs on the field in the same direction, and want to add a 3rd above/below the stop that will not cancel when the stop loss is hit, but will cancel if the profit target is hit.

                How can I accomplish this? I feel the examples provided are not fully encompassing of how to create this effect.

                Thanks,
                J

                Comment


                  #9
                  Hello wisdomspoon,

                  But if I'm using a trailing stop, that is, a stop that moves based on price action (not SetTrailStop), and I use a limit order,
                  I'm not quite sure what you are asking.

                  'if I'm using a trailing stop' ... 'and I use a limit order'..

                  How are you using a limit order with a trailing stop? This is not quite making sense to me.
                  Are you using a limit order as the entry and using a stop market order for the exit?
                  Are you referring to a Stop Limit order and not a Stop Market order?

                  'how will I move that limit order in conjunction with the stop price?'
                  Which limit are you referring to?
                  Are you referring to the profit target?
                  Are you referring to the limit price of a Stop Limit order?
                  How do you to want move the limit? (Meaning why does does the limit have to move for a trailing stop?)


                  all I'm trying to do is follow a stoploss around as it moves
                  What does this mean?
                  How are you 'following' a stop loss?
                  Are you trying to print the stop price of a stop order submitted SetStopLoss() each time you modify the price? (Why not just print the calculated price before calling the set method?)
                  Are you

                  set a trade in the same direction as the stop loss
                  What does this mean?
                  By 'Set a trade' do you mean if the stop order is a sell order, you want to submit another sell order as an entry when the exit order fills?

                  if I'm in a short position, and I have a buy profit target, and a buy stop loss, I'd like to place a buy limit above the stop loss
                  You are wanting to submit a buy limit above the buy stop order before the buy stop order has filled?
                  This wouldn't make much sense, a buy limit order above the market price will fill instantly. A limit order fills at the specified price or better. This means the limit would fill even if the stop does not.
                  Are you clear on what side of the market each order type is used on?
                  You can do this, but that order will fill instantly and the stop likely will not.

                  I need that buy limit to follow along the stop loss as it moves down and I can offset the buy limit by a tick or two
                  This would not be possible. Placing a buy limit above the current ask will immediately fill at market price. You will not be able to adjust an order that has filled.

                  If I was short, and I'm stopped out, and therefore in a new long position, I want that long position to have the same size profit target, and same type of trailing stop.
                  Don't assign new values for the trail distance variables and it will be the same.

                  If you have an example that you can point to in which this specific setup occurs, submitting a limit order in the same direction as the OCO orders already on
                  I do not have an example of this. This would be an extremely confusing script to give someone as it would be placing limit orders on the wrong side of the market which would fill immediately.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Chelsea,

                    I don't understand why you're having such a difficult time understanding the concept and need so much clarification. I may have used some ineffective words or communicated this poorly so here's a video explanation with a direct example of what I'm trying to accomplish. Other trading platform languages have no problem coding this concept. C# is vastly robust, but NinjaScript seems it is lacking some fundamentals that would make coding this much easier. This is why I'm asking for help.



                    J

                    Comment


                      #11
                      Hello J,

                      I am not able to access the link to google drive you have provided.

                      If this is a link to a video, I cannot watch the video.


                      Which limit are you referring to?

                      Clarifying the specific limit you are referring to may help for me to understand how you want the limit to change prices.


                      The confusion is coming from the information provided.

                      You've previously provided sample code of just a market order and SetStopLoss() and SetProfitTarget().

                      Example of Entry: shortEntryOrder = EnterShort(Convert.ToInt32(DefaultQuantity), "")

                      I am using the following as Profit Target and Stop Loss:
                      SetProfitTarget("", CalculationMode.Price, Target_Price);
                      SetStopLoss("", CalculationMode.Price, Stop_Price, false);​


                      The only limit order that would be used here is the SetProfitTarget(). So I have to assume you are talking about the profit target limit.

                      However, the profit target limit does not have to change prices.

                      If you want the profit target limit order to change prices you can.
                      How would want this to be in relation to the stop market order submitted with SetStopLoss()?
                      For each trail of the stop loss do you want to chase the same with the profit target? (Meaning the stop loss stop price moves up and the profit target limit price moves down)
                      Are you wanting to remove SetStopLoss() and only use a profit target and chase the market price?


                      But you have asked:
                      'how will I move that limit order in conjunction with the stop price?'
                      I guess it wouldn't if you don't want the profit target limit to move. You can just leave it at the price it is at.


                      all I'm trying to do is follow a stoploss around as it moves
                      To print the stop price of the stop market order set with SetStopLoss(), add the following to the OnOrderUpdate() override:

                      if (order.Name == "Stop loss")
                      {
                      Print("Stop loss stop price: " + order.StopPrice.ToString());
                      }​
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Chelsea,

                        The video is rather relevant. When I initially uploaded the video, it did take a while to process but it is now processed and working and I think I made it private which I have now fixed. I also uploaded to a separate unused Youtube Channel of mine in case the Google Drive video still doesn't work for you (works fine for me). For Youtube link, set quality to 4K so it's visibly clear.

                        Youtube: https://www.youtube.com/watch?v=GVenWPtZhEY
                        GoogleDrive: https://drive.google.com/file/d/1RGe...ew?usp=sharing

                        In the post this originally came from regarding GetRealTime - you made it clear to the user how important it was that he watch your video to fully understand the concept and to answer his questions. I would implore you to do the same in this case with my video and I've made them as accessible as possible.

                        But to go even further the answers:
                        Which limit are you referring to?
                        The limit is the profit target, that doesn't move. When referring to a "reversal" I think I did state it was a limit, but it should actually be a stop market. The video makes this clear even though I mispoke. The stop is what moves. The profit target does not.

                        How would want this to be in relation to the stop market order submitted with SetStopLoss()?
                        For each trail of the stop loss do you want to chase the same with the profit target? (Meaning the stop loss stop price moves up and the profit target limit price moves down)
                        Are you wanting to remove SetStopLoss() and only use a profit target and chase the market price?
                        In order respectively:
                        1. No, profit target doesn't move.
                        2. No, we're not chasing profit target with stop loss, we're moving stop based on it's relative position to profit target with a frequency of 1 tick.
                        3. No.

                        Video is less than 3 minutes and makes it crystal clear exactly what I'm trying to accomplish. I may have used incorrect verbiage to describe this previously in relation to the buy stop/buy limit, etc. I take responsibility for this in that it may have caused unnecessary confusion. I hope this can help you understand exactly what I'm trying to accomplish with the code.

                        ​J

                        Comment


                          #13
                          Hello J,

                          When referring to a "reversal" I think I did state it was a limit, but it should actually be a stop market.
                          This very much clarifies my confusion.

                          As you have made clear in the video, you are not placing a limit order.

                          A limit order cannot be placed above that stop.

                          In the video you are showing a second stop order, to be used as an entry order, above the stop order used as an exit order. This will actually work, whereas a limit order would not work.
                          (Hence you can understand my confusion. What you are asking in your previous posts is not possible.)


                          So for a stop order, supply the calculated price you are supplying to the stop loss as the stop price.

                          I would expect however, that you will not be able to use SetStopLoss() and have an entry stop order working at the same time, as this will violate the internal order handling rules.

                          From the help guide:
                          "Methods that generate orders to enter a position will be ignored if:
                          A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction​"



                          In the unmanaged approach, you would just supply the same stop price variable for both orders submitted with SubmitOrderUnmanaged and they will both trail the same.


                          I also missed one your previous questions.
                          With regard to SubmitOrderUnmanaged, this was not used in your example previously and it is not used in the code. If that's what I should be using, is there a relevant example you can point me towards?
                          In post # 2 I have provided a link to examples. May I confirm that you have downloaded the 'ProfitChaseStopTrailUnmanagedExample_NT8 ' example and that you are viewing the code?
                          The SubmitOrderUnmanaged() call is on lines 160, 168, 192, 242, and 252.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi Chelsea,

                            Thank you for reviewing the video and getting us on the same page. Yes, I did actually provide that script that I had been reviewing in Post #3. The entirety of this query comes from my inability to understand how to implement this into my script. Your specific mentions of where the relevant calls are in the script is very helpful. I know that you can't write the script for me, but perhaps we can build a conversation around this script where my my understanding is lacking.

                            Let's assume I use this script for entries and stops based on my conditions. So we're on the same page, the script I'm referring to is: ProfitChaseStopTrailUnmanagedExample_NT8

                            If I wanted to create the reversal effect, would I simply create a quantity of 2 (bolded in code) instead of 1? This would be that so I have a buy/sell stp to reverse the position. Line 245 through 252
                            Code:
                                            if (UseStopLoss)
                                            {
                                                if (PrintDetails)
                                                    Print(string.Format("{0} | OEU | placing stop loss", execution.Time));
                            
                                                currentSlPrice    = execution.Order.AverageFillPrice - StopLossDistance * tickSizeSecondary;
                                                stopLoss        = placeHolderOrder;
                                                SubmitOrderUnmanaged([B]2[/B], OrderAction.Sell, OrderType.StopMarket, execution.Order.Filled, 0, currentSlPrice, ocoString, "stop loss");​​
                            If the answer is yes, because I want to count these "reversals", is it better to duplicate this and give it a different name? While I like your initial counter idea, I would ideally like to create flags as true/false so I can see reversal 1, reversal 2, then reset.

                            If the answer is no, please point me to the relevant areas of the script that would be necessary to update to incorporate what you now understand I want to accomplish.

                            I appreciate you working with me to bring my vision to fruition.

                            Thanks,
                            J

                            Comment


                              #15
                              Hello J,

                              You could technically use a quantity of 2 with the exit stop order and this would reverse a long position with a quantity of 1.

                              But for proper tracking I would recommend detecting the stop order has filled in OnOrderUpdate() and then submitting a market entry in the opposite direction. (This would ensure the sequence the orders fill in)

                              How you approach this is up to you.

                              If you want to use bools to know events have happened instead of using a counter you could choose to do this.
                              Yes, you could set a bool or set of bools to true when the exit orders fill.

                              Below is a link to using bools you might find helpful.
                              Hi, To improve a strategy, I would like the condition to enter a trade to be triggered only after a second crossing happens. Meaning, for instance we have a sthocastics crossing, but the strategy would only trigger when a crossing between 2 emas happen. Would the looking back N bars work? Can it be done within the builder



                              please point me to the relevant areas of the script that would be necessary to update to incorporate what you now understand I want to accomplish.
                              Line 252 is where the stop market order is initially submitted. The a second stop market would likely also be submitted here.
                              Line 216 is where the stop price is modified. You would also modify the stop price of the second stop market order here using the same currentSlPrice variable for both calls to ChangeOrder().
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Today, 05:17 AM
                              0 responses
                              39 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
                              64 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              41 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