Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Managed Stop not updating

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

    Managed Stop not updating

    Can someone tell me why this Managed Stop order does not actually update the stop despite it being calculated (per the Output log)? What am I missing? (It works with "SetStopLoss" but I would like to use Exit orders instead). Note: I am using SetProfitTarget for the Targets - would that cause the issue? Do I need some CancelOrder() logic somewhere as I move from one stop to another?

    As always....any help is appreciated.

    Code Snippet:

    public class BigTAutoStrategy_V2 : Strategy
    {
    private Order StopLongOrder = null;
    private Order StopShortOrder = null;

    ...
    protected override void OnBarUpdate()
    {

    if (High[0] > Position.AveragePrice * 1.0045)
    {
    StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop", "Long1");
    StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop", "Long2");
    StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop", "Long3");
    StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop", "Long4");
    StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop", "Long5");
    StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop", "Long6");
    StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop", "Long7");
    }
    }

    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
    {
    if (order.Name == "LongStop")
    {
    if (orderState != OrderState.Filled)
    {
    StopLongOrder = order;
    }
    }

    if (StopLongOrder != null && StopLongOrder == order)
    {
    if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
    {
    StopLongOrder = null;
    }
    }
    }

    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    if (StopLongOrder != null && StopLongOrder == execution.Order)
    {
    if (execution.Order.OrderState == OrderState.Filled)
    {
    StopLongOrder = null;
    }
    }
    }

    #2
    Hello BigT4X,

    First, you will need to assign order objects from OnOrderUpdate() and not directly from the method call.

    This assignment of StopLongOrder:
    StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop", "Long1");

    Should be in OnOrderUpdate()
    if (order.Name == "

    From the help guide:
    "OnOrderUpdate() will run inside of order methods such as EnterLong() or SubmitOrderUnmanaged(), therefore attempting to assign an order object outside of OnOrderUpdate() may not return as soon as expected. If your strategy is dependent on tracking the order object from the very first update, you should try to match your order objects by the order.Name (signal name) from during the OnOrderUpdate() as the order is first updated."

    Also, see the code example under the heading 'Properly assigning order object values'.


    Below is a link to examples that properly assign order objects.



    Second, it appears you are attempting to update the order 7 times extremely quickly using the same signal name and switch the entry the order is attached to by rapidly changing the fromEntrySignal of the order. This is not going to work. The order is only going to be attached to a single entry.

    In case you are not aware, re-using a signal name causes the existing order to be updated and does not generate a new order.

    Either, just call the exit method once, and attach this to entry Long7, or use different signal names for the exits to make these unique and separate orders, (but continue using the fromEntrySignals for the entries they are being attached to).

    ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop1", "Long1");
    ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop2", "Long2");
    ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop3", "Long3");
    ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop4", "Long4");
    ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop5", "Long5");
    ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop6", "Long6");
    ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop7", "Long7");


    Next, what you do mean it's not updating? Do you meaning the order is a working state but you are unable to update the price and update the order?


    Last, enable TraceOrders and use Print() to understand any behavior.
    Below is a link to a forum post that demonstrates using Print() and TraceOrders to understand behavior.


    Are you getting messages from TraceOrders when attempting to update the working order's price?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks NinjaTrader_ChelseaB very much!! I appreciate your answers. I will try your suggestions. Here are some quick answers to your questions....any other suggestions based on the below I will be happy to look at.

      Side note: all of this logic works without issue using "SetStopLoss" (no OnOrderUpdate/OnExecutionUpdate) but I am trying to move to ExitLongStopMarket and ExitShortStopMarket formats so that I can also get "Reverse on Stop" working from my other post. I am trying to break down the issues.

      I have Trace orders on....and some prints....the math is calculating (can see that in the log) but it is not actually updating the actual order and the chart display of the trade shows it never changed too. So what you said: "unable to update the price and update the order"

      The stop orders logic are in OnBarUpdate because each bar as it closes I need it to reevaluate rather than only on an Order update. That is why the stop logic is there. And using SetStopLoss it captures it and moves the stop as expected.

      I tried a variation of LongStop1, LongStop2, etc....but it did not work either. I have 7 order entry types (some execute on Open, some on crosses of various lines or levels, etc) and 10 various stop levels to move things up as criteria is met. At any one time there is only 1 of the 7 orders "working" (trying to keep it at 1 contract before I even think of adding contracts) so to isolate each of them I have 7 order names rather than 7 entry rules all mapping to one order name "Long". This is because (1) some of them will not use every stop level of the 10 and (2) initial stop is different on all of them (I did not provide the initial stop logic that is sitting in OnExecutionUpdate). So there is a few reasons for having Long1, Long2, Long3, etc.

      Try to picture......when Close above A then Long 1 OR when Open is X then Long2. OR when Close > Line Y then Long 3.....OR when Close > Level Z then Long 4. etc etc etc. BUT at any one time only 1 of those is the Active order. Now that we are in an order (one of the 7).......take this example above.....it moves up 1.0045....move the stop up to 1.002 for whatever order that is live.

      I hope that helps understand what I am trying to do.
      Last edited by BigT4X; 08-02-2022, 08:45 AM.

      Comment


        #4
        NinjaTrader_ChelseaB

        Here are my first 3 stops of 10 in OnBarUpdate - for these they all 7 orders share them.

        I have tried to make LongStops1 for the first one (all 7), LongStops2 for the second one (all 7) and LongStops3 (for the third) - that was my variation attempt previously. Currently they are all just LongStop. I will try LongStops 1, 2, 3....7 for each of the 3 Stop levels as per your example.

        My Question: I will put the assignment of those LongStops 1-7 in OnOrderUpdate. Should I also put all the Stop logic in OnOrderUpdate......instead of OnBarUpdate and if so.....then how do I get it to check each level on each close of the bar?

        //Exit Rules
        //Long Stop Step Trailing
        if (Position.MarketPosition == MarketPosition.Long)
        {
        if (LongStop1 == false) //true or false counter that helps skip the step if already proven true. This part is working.
        {
        if (High[0] > Position.AveragePrice * 1.0033)
        {
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStop", "Long1"); //will change LongStop to LongStops1
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStop", "Long2"); //will change LongStop to LongStops2
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStop", "Long3"); //will change LongStop to LongStops3
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStop", "Long4"); //will change LongStop to LongStops4
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStop", "Long5"); //will change LongStop to LongStops5
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStop", "Long6"); //will change LongStop to LongStops6
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStop", "Long7"); //will change LongStop to LongStops7

        LongStop1 = true;
        }
        }

        if (LongStop1 == true && LongStop2 == false)
        {
        if (High[0] > Position.AveragePrice * 1.0045)
        {
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop", "Long1"); //will make same changes above here too
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop", "Long2");
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop", "Long3");
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop", "Long4");
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop", "Long5");
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop", "Long6");
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStop", "Long7");

        LongStop2 = true;
        }
        }

        if (LongStop2 == true && LongStop3 == false)
        {
        if (High[0] > Position.AveragePrice * 1.007)
        {
        CancelOrder(StopLongOrder);
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.004, "LongStop", "Long1"); //will make same changes above here too
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.004, "LongStop", "Long2");
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.004, "LongStop", "Long3");
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.004, "LongStop", "Long4");
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.004, "LongStop", "Long5");
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.004, "LongStop", "Long6");
        StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.004, "LongStop", "Long7");

        LongStop3 = true;
        }
        }

        Comment


          #5
          Hello BigT4X,

          Where you have mentioned:
          "I have tried to make LongStops1 for the first one (all 7), LongStops2 for the second one (all 7) and LongStops3 (for the third)"
          I'm not actually understanding what this means..
          Can you clarify this?

          "Currently they are all just LongStop"
          There is only 1 order. You are just updating that same order over and over and over again. There are not multiple stops here. If the signal name is the same, it updates the existing order, there is no new order created. You are just modifying the same order 7 times very rapidly.

          "My Question: I will put the assignment of those LongStops 1-7 in OnOrderUpdate. Should I also put all the Stop logic in OnOrderUpdate......instead of OnBarUpdate and if so.....then how do I get it to check each level on each close of the bar?"
          You can place the stops immediately when entry fills in OnOrderUpdate() or OnExecutionUpdate().
          Are you able to follow the code in the example I have provided you?
          Last edited by NinjaTrader_ChelseaB; 08-02-2022, 11:35 AM.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            If there is a way we can chat verbally then let me know.....would be easier but regardless....Here are your answers:

            Where you have mentioned:
            "I have tried to make LongStops1 for the first one (all 7), LongStops2 for the second one (all 7) and LongStops3 (for the third)"
            I'm not actually understanding what this means..
            Can you clarify this?


            Used to look like this (this also did not work):
            ....
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStops1", "Long1"); //will change LongStop to LongStops1
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStops1", "Long2"); //will change LongStop to LongStops2
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStops1", "Long3"); //will change LongStop to LongStops3
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStops1", "Long4"); //will change LongStop to LongStops4
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStops1", "Long5"); //will change LongStop to LongStops5
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStops1", "Long6"); //will change LongStop to LongStops6
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStops1", "Long7"); //will change LongStop to LongStops7

            ....
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStops2", "Long1"); //will make same changes above here too
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStops2", "Long2");
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStops2", "Long3");
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStops2", "Long4");
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStops2", "Long5");
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStops2", "Long6");
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 1.002, "LongStops2", "Long7");

            And so on for each of the 10 levels of stops......

            This works without issue:
            SetStopLoss("Long1", CalculationMode.Price, Position.AveragePrice * 1.002, true);
            SetStopLoss("Long2", CalculationMode.Price, Position.AveragePrice * 1.002, true);
            SetStopLoss("Long3", CalculationMode.Price, Position.AveragePrice * 1.002, true);
            SetStopLoss("Long4", CalculationMode.Price, Position.AveragePrice * 1.002, true);
            SetStopLoss("Long5", CalculationMode.Price, Position.AveragePrice * 1.002, true);
            SetStopLoss("Long6", CalculationMode.Price, Position.AveragePrice * 1.002, true);
            SetStopLoss("Long7", CalculationMode.Price, Position.AveragePrice * 1.002, true);

            I tried what you suggested above but that has not worked either.....but I am still trying your changes to see if I missed anything and what the logs are saying.....so not quite done yet.

            "Currently they are all just LongStop"
            There is only 1 order. You are just updating that same order over and over and over again. There are not multiple stops here. If the signal name is the same, it updates the existing order, there is no new order created. You are just modifying the same order 7 times very rapidly.


            Ok - I wrote it like this because I cannot know (or I am not good enough at this to know) which of the 7 entry types triggered initially and since there are differences AFTER these first 3 stop levels and also on the initial stops too (see below initial stops logic)

            "My Question: I will put the assignment of those LongStops 1-7 in OnOrderUpdate. Should I also put all the Stop logic in OnOrderUpdate......instead of OnBarUpdate and if so.....then how do I get it to check each level on each close of the bar?"
            You place the stops immediately when entry fills in OnOrderUpdate() or OnExecutionUpdate().
            Are you able to follow the code in the example I have provided you?


            So far yes but so far still not working either as mentioned.....Here below are my initial stops that I did not include initially in the post.....they are set immediately....then I move to my stair step stop logic above through OnBarUpdate. So I already have initial stops.....I am trying to get the Stop steps logic that works with SetStopLoss to work with ExitLong/Short instead so that I can move on to "Reverse on Stop" on some of these.

            protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
            {
            if (execution.Order.Name == "Long1" && execution.Order.OrderState == OrderState.Filled)
            {
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, BigT_Level2[0], "LongStops1", "Long1");
            SetProfitTarget("Long1", CalculationMode.Price, BigT_TargetLevel[0], true);
            }

            if (execution.Order.Name == "Long2" && execution.Order.OrderState == OrderState.Filled)
            {
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, BigT_Level2[0], "LongStops2", "Long2");
            SetProfitTarget("LongReverse", CalculationMode.Price, BigT_TargetLevel[0], true);
            }

            if (execution.Order.Name == "Long3" && execution.Order.OrderState == OrderState.Filled)
            {
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, BigT_Level1[0], "LongStops3", "Long3");
            SetProfitTarget("Long3", CalculationMode.Price, BigT_TargetLevel[0], true);
            }

            if (execution.Order.Name == "Long4" && execution.Order.OrderState == OrderState.Filled)
            {
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, BigT_Level1[0], "LongStops4", "Long4");
            SetProfitTarget("Long4", CalculationMode.Price, BigT_TargetLevel[0], true);
            }

            if (execution.Order.Name == "Long5" && execution.Order.OrderState == OrderState.Filled)
            {
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, BigT_Level3[0], "LongStops5", "Long5");
            SetProfitTarget("Long5", CalculationMode.Price, BigT_TargetLevel[0], true);
            }

            if (execution.Order.Name == "Long6" && execution.Order.OrderState == OrderState.Filled)
            {
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, BigT_Level3[0], "LongStops6", "Long6");
            SetProfitTarget("Long6", CalculationMode.Price, BigT_TargetLevel[0], true);
            }

            if (execution.Order.Name == "Long7" && execution.Order.OrderState == OrderState.Filled)
            {
            StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, BigT_Level6[0], "LongStops7", "Long7");
            SetProfitTarget("Long7", CalculationMode.Price, BigT_TargetLevel[0], true);
            }

            if (StopLongOrder != null && StopLongOrder == execution.Order)
            {
            if (execution.Order.OrderState == OrderState.Filled)
            {
            StopLongOrder = null;
            }
            }
            }
            Last edited by BigT4X; 08-02-2022, 11:21 AM.

            Comment


              #7
              Hello BigT4X,

              What are you trying to do?

              Are you trying to submit 7 different exit orders to attach to 7 different entry orders, or are you trying to submit 1 order and modify this several times?

              Where you have "Used to look like this (this also did not work):" this is possibly expected, it depends on what you expecting to happen.
              The code you are suggesting has several issues which I have noted in posts #2 and #5.

              Where you have mentioned:
              "I tried what you suggested above but that has not worked either.....but I am still trying your changes to see if I missed anything and what the logs are saying.....so not quite done yet.I tried what you suggested above but that has not worked either.....but I am still trying your changes to see if I missed anything and what the logs are saying.....so not quite done yet."

              What code did you try?
              What is not working?
              Is the position Long 7 from the 7 entries? (Meaning have you already adjusted the EntryHandling/EntriesPerDirection?)
              Have you submitted unique exits with different signal names?
              May I have the output from TraceOrders? (Attach the output saved to a text file)

              I don't recommend mixing set methods and exit order methods.
              If you are using ExitLongStopMarket(), use ExitLongLimit() as well for the target, don't use SetProfitTarget() or SetStopLoss(), and vice versa.


              If you are going to reverse, you could reverse with a stop entry in the opposite direction. With the managed approach NinjaTrader will managed the reversal by auto generating a Close position order to exit the current position and then the entry will enter into the reverse position.

              Or you would need to exit the current position, wait for the position to update in OnPositionUpdate, before placing an order in the opposite direction.


              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Responses:
                What are you trying to do?

                I have 7 ways to enter a Long trade and 7 ways to enter short. Each of them have their own Initial Stop loss that is different depending on the Entry used. All of them use Stair-Step stops after the initial but not all use all 10 of the Stair Step Stops. Some use Initial + 5 or 6. Some use all Initial + 10. All of them use the first 3 as they are price based. For that reason Each entry I have a Order name (Long1, Long2, Long 3, etc) to identify them. I initially tried to identify the 10 different stops with their own name (LongStops1, LongStops2, etc). Then I tried just one name (LongStop). Now I am trying to identify the Stop name and Order name in combination as suggested. Only 1 of the 7 is ever live at one time currently - I did not want to complicate it more.

                What code did you try?
                See below - looking to see what else I missed.

                Applied this red text on all 10 Stair Step Stops (Just showing the first one):
                StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStops1", "Long1");
                StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStops2", "Long2");
                StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStops3", "Long3");
                StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStops4", "Long4");
                StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStops5", "Long5");
                StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStops6", "Long6");
                StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStops7", "Long7");

                Added this red text to OnOrderUpdate: Should I have also added the Entry Names here too (not just the stop names)?
                if (order.Name == "LongStops1" || order.Name == "LongStops2" || order.Name == "LongStops3" || order.Name == "LongStops4" || order.Name == "LongStops5" || order.Name == "LongStops6" || order.Name == "LongStops7")
                {
                if (orderState != OrderState.Filled)
                {
                StopLongOrder = order;
                }
                }


                if (StopLongOrder != null && StopLongOrder == order)
                {
                Print(order.ToString());
                if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                {
                StopLongOrder = null;
                }
                }

                Made my Initial Stops have unique Stop Names too:
                protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
                {
                if (execution.Order.Name == "Long1" && execution.Order.OrderState == OrderState.Filled)
                {
                StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, BigT_Level2[0], "LongStops1", "Long1");
                SetProfitTarget("Long1", CalculationMode.Price, BigT_TargetLevel[0], true);
                }

                if (execution.Order.Name == "Long2" && execution.Order.OrderState == OrderState.Filled)
                {
                StopLongOrder = ExitLongStopMarket(0, true, QuantitySize, BigT_Level2[0], "LongStops2", "Long2");
                SetProfitTarget("LongReverse", CalculationMode.Price, BigT_TargetLevel[0], true);
                }

                What is not working? Stop prices are not updating
                Is the position Long 7 from the 7 entries? (Meaning have you already adjusted the EntryHandling/EntriesPerDirection?) Yes
                Have you submitted unique exits with different signal names? Yes

                I don't recommend mixing set methods and exit order methods.
                If you are using ExitLongStopMarket(), use ExitLongLimit() as well for the target, don't use SetProfitTarget() or SetStopLoss(), and vice versa.


                I will make this change also. I will change all my stops and Targets on Longs and Shorts to Exit formats instead of SetStop/SetTarget format. I am using both formats currently.

                If you are going to reverse, you could reverse with a stop entry in the opposite direction. With the managed approach NinjaTrader will managed the reversal by auto generating a Close position order to exit the current position and then the entry will enter into the reverse position.

                This was my thoughts also.....I tried using EnterShortStopMarket() (instead of ExitLongStopMarket) and EnterLongStopMarket() (instead of ExitShortStopMarket) but that was not successful either. I believe I need to resolve this Update logic first for the "Reverse on Stop" logic to work.

                May I have the output from TraceOrders?
                Attached is a relevant example:
                Attached Files
                Last edited by BigT4X; 08-02-2022, 02:59 PM.

                Comment


                  #9
                  Hello BigT4X,

                  As mentioned in post #2, you cannot assign an order method to a order variable. You will need to assign that from OnOrderUpdate().
                  If you want to assign these orders to variables, you are going to need different variables to hold them.

                  Once an order is assigned to a variable, you can use ChangeOrder() to change the order or just call the order method again using the same signal name to update it to a new price.

                  From the out I am seeing an ingored message.

                  2022-06-29 10:15:00 AM Strategy 'BigTAutoEquilibriumFT_V2/253999646': Ignored SubmitOrderManaged() method at 2022-06-29 10:15:00 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=11709.25 SignalName='LongStops1' FromEntrySignal='Long1' Reason='Invalid order price, please see log tab'

                  This a sell stop that must be below the current bid price. The stop price is 11709.25. What is the bid price?

                  It looks like you are using BigT_Level2[0] as the stop price. Are you verifying this is 1 tick less than the bid price?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    As mentioned in post #2, you cannot assign an order method to a order variable. You will need to assign that from OnOrderUpdate().
                    If you want to assign these orders to variables, you are going to need different variables to hold them.


                    This wording (definition) I am getting lost on for sure. I will try to read the explanations/definitions again to get the difference. I am thinking you mean I need also this or only this needs to be added:

                    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
                    {
                    if (order.Name == "Long1" || order.Name == "Long2" || order.Name == "Long3" || order.Name == "Long4" || order.Name == "Long5" || order.Name == "Long6" || order.Name == "Long7")
                    {
                    if (orderState != OrderState.Filled)
                    {
                    EntryLongOrder = order;
                    }
                    }


                    Another words no Assignment of the Stops? So I do not need this? Or that I need both?
                    if (order.Name == "LongStops1" || order.Name == "LongStops2" || order.Name == "LongStops3" || order.Name == "LongStops4" || order.Name == "LongStops5" || order.Name == "LongStops6" || order.Name == "LongStops7")
                    {
                    if (orderState != OrderState.Filled)
                    {
                    StopLongOrder = order;
                    }
                    }



                    This a sell stop that must be below the current bid price. The stop price is 11709.25. What is the bid price?

                    It looks like you are using BigT_Level2[0] as the stop price. Are you verifying this is 1 tick less than the bid price?


                    The code was to wait for the Close of the Bar "Calculate = Calculate.OnBarClose;"..........examine the Bar High and if it is above a level.....move the stop up to that level at the close of the Bar. That seems to work with SetStopLoss without issue and in fact stops out right on the open of the bar (close of the trigger bar). So I did not have a current check against Bid for that reason. (see attachment of the same trade as the Text file)

                    Once I moved to Exit format....I am having this trouble. So how would I add a check to just use Bid to exit at the close of the bar if Bid is lower than the level - to replicate what SetStopLoss is doing? Can you point to a resource suggested sample for that?
                    Attached Files

                    Comment


                      #11
                      Hello BigT4X,

                      Yes, call the order method without assigning this to a variable.
                      ExitLongStopMarket(0, true, QuantitySize, Position.AveragePrice * 0.994, "LongStops1", "Long1");

                      In OnOrderUpdate() assign the order to a variable
                      if (order.Name == "LongStops1" && order != StopLongOrder1)
                      StopLongOrder1 = order;

                      if (order.Name == "LonsgStops2 && order != StopLongOrder2)
                      StopLongOrder2 = order;

                      Do this for all order you plan to assign to different variables.

                      "The code was to wait for the Close of the Bar "Calculate = Calculate.OnBarClose;"..........examine the Bar High and if it is above a level.....move the stop up to that level at the close of the Bar. "

                      This code does not appear to be in OnBarUpdate. Even if it is though, did you make sure its less than the bid?

                      double stopPrice = BigT_Level2[0];

                      if (stopPrice >= GetCurrentBid())
                      stopPrice = GetCurrentBid() - TickSize;

                      You have use a valid price. Whatever you assigned to BigT_Level2[0] might not be on the right side of the market at the exact moment the order is submitted.

                      The example I provided you demonstrates logic to move a stop order up.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        So since my entries are unique (and unique names) and do not have different set of variables, then I would not need a OnOrderUpdate entry for Long1, Long2, Long3, Short1, Short2, Short 3, etc. However, since I do update the Stops multiple times I do need an entry. I believe that is what you are saying in green

                        - 10 stops x 2 sides = 20 entries YES
                        and NOT
                        - (7 entries + 10 stops) x 2 sides = 34 entries NO

                        Sorry to be so simple.

                        Also.....
                        I do not have any sort of Bid check on Stop levels. BUT my levels (BigT_Level2[0], etc) are set because I need them for entry validation too, targets and stops. So instead I think I will have to apply a check on the Stop validation code itself rather than apply it to the level specifically. I will think that one through.

                        I will make all the changes you suggested and apply everything tonight. Thanks for ALL your help as I move through all of this!!!!!!!

                        Comment


                          #13
                          Hello BigT4X,

                          If you have 1 variable to hold 1 order, you don't have 7 orders with 7 variables. You have 1 order assigned to the variable.

                          "So since my entries are unique (and unique names) and do not have different set of variables, then I would not need a OnOrderUpdate entry for Long1"

                          I'm not certain what this means. Your entries need to have unique signal names. Your exits need to have unique signal names. If you want to use those order objects later, these need to be saved to different variables.

                          You don't have to save an order to a variable if you want to resubmit the order using the same signal name. You do need the order object saved to a variable if you want any information from the order like the OrderState.

                          "However, since I do update the Stops multiple times I do need an entry."

                          I'm not sure what this means. If you want to place an exit you would need an entry. If you want to update an order multiple times you can.

                          "- 10 stops x 2 sides = 20 entries YES"

                          I don't know what this means.

                          If you have 7 entry orders, you should have 7 exit orders with unique names.

                          "and NOT
                          - (7 entries + 10 stops) x 2 sides = 34
                          entries NO"

                          I also don't understand what this means.

                          "I do not have any sort of Bid check on Stop levels."

                          Then add a check to make sure your order price is valid or it will be ignored or rejected, just like your order has been.

                          "BUT my levels (BigT_Level2[0], etc) are set because I need them for entry validation too"

                          Your price still has to be a valid price for the order no matter how you decided on the price.

                          "So instead I think I will have to apply a check on the Stop validation code itself rather than apply it to the level specifically."

                          I don't understand what this means.

                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            NinjaTrader_ChelseaB

                            Just ignore my last post....(thanks for answering though)

                            I wanted to say thank you for all your help!!You went above and beyond!! I was able to shift my code from SetStop/Set Target to Exits mode. Results are now identical. If there is a way I can send this to your Manager or please let your Manager know on my behalf.....awesome job, well done!!

                            I am now moving on to "Reverse on Stop" which was the main reason I switched this code. I got it to work on "OnOrderUpdate" but the Historical Test Result on the chart fills the Entry always at the Low/High on the same bar as the Exit instead of same price as the Entry. That of course would be "time traveling"....not possible to enter a long at the low and exit the short later in the bar. (see Picture). I would not expect this to happen running live, but I like to know how well my code is working before I run live.

                            So I will try to figure it out how to do it as part of the Stop order instead or the OnPosition Update as mentioned in Post #7.

                            Current code:

                            protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
                            {
                            if (StopLongOrder5 != null && StopLongOrder5 == order)
                            {
                            Print(order.ToString());
                            if (order.OrderState == OrderState.Filled)
                            {
                            EnterShort(QuantitySize, "Short7ReverseOnLongStop");
                            StopLongOrder5 = null;
                            }
                            if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                            {
                            StopLongOrder5 = null;
                            }
                            }
                            Attached Files
                            Last edited by BigT4X; 08-04-2022, 08:30 AM.

                            Comment


                              #15
                              Hello BigT4X,

                              Because this is the managed approach, the order filling may not have updated the position yet. Because of this NinjaTrader may still try and manage the position. If you are using the managed approach, I would recommend waiting until the position updates. If you use the unmanaged approach, you can send the new order when the stop order updates or the execution updates.

                              In historical, implement 1 tick intra-bar granularity for intra bar fills.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Yesterday, 05:17 AM
                              0 responses
                              63 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              139 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              75 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              45 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              50 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X