Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reverse Position

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

    #16
    Hello,

    I wanted to let you know I am still investigating the cause of the ignored order.

    This is the code generating the error:
    Code:
    else if (macd.Diff[barOffset + 1] >= 0 && macd.Diff[barOffset] < 0)
    {
    //Print(Close[0] + " - " + (Close[barOffset] + TickSize));
    var entryLevel = Close[barOffset] + TickSize;
    Print(Close[0] + " - " + entryLevel);
    SetStopLoss("ShortEntry", CalculationMode.Price, entryLevel + stopLossTicks * TickSize, false);
    SetProfitTarget("ShortEntry", CalculationMode.Price, entryLevel - takeProfitTicks * TickSize);
    EnterShortLimit(1, entryLevel, "ShortEntry");
    }
    The output for the Print i added is 1445.5 - 1445.75.

    This means that you are trying to submit a sell limit order at 1445.75 while the market is at 1445.50. This appears to be a valid order and I am uncertain as to why the error message is appearing.

    I appreciate your patience as I look into this.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Hi aytacasan,

      Thanks for your patience.

      Regarding the setting of the Stop Loss and Profit Target, it is good practice to set these before an order because they can often be changed and not at the right level when being modified for previous orders. Resetting these will ensure the stop is at the right level. In your script, the stop loss and profit target use signal names. They also are not changed at any point after being set. Because of this they could be set once, for each entry signal name. However, I would still recommend you reset them because in more complicated code these can get very confusing. Its my personal opinion that it is good practice to do.

      Regarding the the order that is being ignored, is ignored because a limit order was placed in the opposite direction of an open strategy position.

      From the help guide: "Methods that generate orders to exit a position will be ignored if:.. ...A position is open 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".

      Please see the section "Internal Order Handling Rules that Reduce Unwanted Positions".
      http://www.ninjatrader.com/support/h...d_approach.htm


      To correct this, try using market orders when flipping the position but use limit orders when entering the market when flat.

      Attached is your script modified to reflect the changes.
      Attached Files
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Hello ChelseaB,

        Yes in my strategy i'm doing same thing about SetStopLoss and SetTakeProfit commands, like your said. Thanks for your personal opinion. And i know about ninjatrader's limit order rule. Actually limit order rejects reason is not try to open opposite side order exactly. Reject reason is in my strategy i'm long and i have take profit order 1650.00 for this long position, then i'm sending new ShortLimitOrder at the same level 1650.00 and at the same time. I'm trying take profit for long at the same time enter new short level at the same level. Ninjatrader worried about something, i don't know what is. But in sample project TakeProfit Level so far ShortLimitOrder level if you pay attention. So this mean close long and cancel it's Tp and SL working orders and open new short position. Beside your example not working for me, in your sample new position opening early.

        Whatever, at that rate I think i have to use only market entry orders; EnterLong/EnterShort only. I try to catch entry level when strategy run in tick but tick mode. If level is reach i send market order.

        Thanks.
        Last edited by aytacasan; 08-13-2013, 12:01 PM.

        Comment


          #19
          Hello aytacasan,

          I think I am understanding the issue.

          You would like the profit target to exit your position and then an EnterShortLimit to enter you into the opposite direction.

          If you would to do this, place the EnterShortLimit, 1 tick above the exit. For example: if you exit at 1650.00 place the EnterShortLimit (after the position is closed) at 1650.25.

          Also, I want to mention that if you long and you place an EnterShort() (market order) this will automatically close your long position keeping any profit or loss, and then enter you into the new position.

          Please let me know if the above does not work for you.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            Hi Chelsea,

            Of couse i can't do this, If i do this i'll be broke my strategy rules. But i decide to write my strategy base on market orders and use some high level approach. For example i send new short order inside of overloaded orderexecuted event/method (for example if TP order executed and now if we are flat and have signal too then open new position via market order) or something like that. Maybe i'll use unmanaged approach for do this.

            Thanks for your helps.

            Comment


              #21
              Hi aytacasan,

              The unmanaged approach will likely work much better for what you are trying to accomplish.

              Please let me know if I can be of any assistance.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Reverse position with Stop Order

                Hallo,
                I am trying to get the following strategy to work, but without success. The position correctly enters on breakout of the Maximum of the last 5 bars Highs, but when then the position is Long it does not reverse the position on Short when the breakout of the Low the the last 5 bars is occurring.
                I am really struggling why this does not work. The code is the following. Could you give me some advice please?
                Thank you
                Martin

                protectedoverridevoid Initialize()
                {
                ExitOnClose =
                true;
                }

                protectedoverridevoid OnBarUpdate()
                {
                if (Position.MarketPosition == MarketPosition.Long)
                {
                ExitLongStop(MIN(Low,
                5)[0]);
                }

                if (Position.MarketPosition == MarketPosition.Flat)
                {
                EnterLongStop(
                1, MAX(High, 5)[0], "");
                }
                }

                Comment


                  #23
                  Hello marticora,

                  Thank you for your post.

                  Your code would just close the long position. Is this the intent or do you wish to go short at the MIN(Low, 5)?

                  Comment


                    #24
                    Hallo Patrick,
                    thanks for your quick reply.
                    You're right, I posted the wrong version, but it does not change: also the Exit does not happen.

                    If you backtest the posted code (e.g. with ES 30 min) it does not exit the position as I've written the code below and it does not reverse the position as well, if instead of ExitLongStop you use EnterShortStop (given the position is Long).

                    The Entry is perfect, ExitLongStop (or EnterShortStop) does nor happen at all

                    Comment


                      #25
                      Hello marticora,

                      Thank you for your response.

                      The code below is working, please take a look at my screenshot attached.
                      Code:
                              protected override void OnBarUpdate()
                              {
                      			if (Position.MarketPosition == MarketPosition.Long)
                      			{
                      				EnterShortStop(MIN(Low, 5)[0]);
                      			}
                      
                      			if (Position.MarketPosition == MarketPosition.Flat)
                      			{
                      				EnterLongStop(1, MAX(High, 5)[0], "");
                      			}
                              }
                      Attached Files

                      Comment


                        #26
                        I understood my mistake!
                        I sincerely thank you very much

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        656 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        370 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        109 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        574 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        577 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X