• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

No suitable method found to override...

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

    #16
    OK, thank you I'll try that.

    I have a question though: when you say the cancel order is not reached, what would it have to look like if it was reached, coz I thought the print below meant the cancel order was reached, but not executed?


    R = 0
    Trying to cancel entryShort1
    04/10/2019 18:41:00 - Flat


    Thank you

    Comment


      #17
      Hello itrader46, thanks for your reply.

      You can print out the Orders state within OnOrderUpdate to see what its last state is. If you want to cancel the order based on the state that it is resting at, check for that state. The last state the order reaches is Accepted. I believe the TriggerPending state will happen with simulated stop orders, those who are hidden from the exchange until a volume trigger is reached.
      Chris L.NinjaTrader Customer Service

      Comment


        #18
        I managed to get the orders to cancel now, but I have to add another cancellation condition, so that they don't get cancelled unless the price moves X ticks back from the Stop price that triggered the Limit order, but keep it live if the price retraces less than X, then turns towards the Limit price.

        At the moment they cancel and get resubmitted so fast, that I think NT8 can't keep up with all that, especially during volatile periods, which is exactly the reason I'm trying to build this strategy.

        I would appreciate any help you can give me

        Thank you

        Comment


          #19
          Hi itrader46, thanks for your reply.

          It sounds like additional limitations need to be made so the conditions will not be hit when you don't want them to. What about your script currently makes the order cancel and be re-created so quickly? Whatever that is will need to be controlled.
          Chris L.NinjaTrader Customer Service

          Comment


            #20
            I think the orders were filled so quickly because of the Tick Calculation Mode.

            Anyway, I think I am close now, but the syntax below doesn't work, as the orders are not cancelled at all now, probably because PositionAccount.AveragePrice is not the right price to compare the currentAsk/Bid, as there is no position open yet?

            Am I right in thinking that and If I am, how can I get the price at which my condition becomes true and places the Limit orders, so I can compare it with the currentAsk/Bid?


            if (entryLong1 == null && entryLong2 == null && entryLong3 == null && (condition))
            {

            EnterLongStopLimit(0, true, Convert.ToInt32(Target1Cont), (GetCurrentAsk(0) + (StopOffsetLong * TickSize)), (GetCurrentAsk(0) + (StopOffsetLong * TickSize)), @"Long1");
            .
            .
            .


            else if (entryLong1 != null && entryLong2 != null && entryLong3 != null && (condition) && (currentAsk <= PositionAccount.AveragePrice - CancelOffsetTicks * TickSize))
            {

            CancelOrder(entryLong1);
            CancelOrder(entryLong2);
            CancelOrder(entryLong3);
            }

            Comment


              #21
              Hi itrader46, Thanks for your reply.

              You can save the value of the bid/ask price when your order fills. Set up a double variable at the class level and set it equal to the current bid or ask after the order entry method is called.

              e.g.

              Code:
              public class TestAddIndicators : Strategy
              {
                  private double fillPrice;
              
                  ...
              
                  OnBarUpdate()
                  {
                      if(entrycondition)
                      {
                          EnterLongStopLimit(...);
                          fillPrice = GetCurrentAsk(0); // Now fill price can be referenced anywhere within the class.
                      }
              }
              Chris L.NinjaTrader Customer Service

              Comment


                #22
                OK, I've got it going now, but I still have issues during high volatility: "Error: Stop price can't be changed above the market" which sometimes freezes my platform, as it comes dozens of times.

                Comment


                  #23
                  I thought maybe if I placed the targets and stops in OnExecutionUpdate, it will be OK, but I can't compile the syntax below: "Cannot inplicitly convert type 'void' to NinjaTrader.Cbi.Order' "

                  if (entryShort2 != null && entryShort2 == execution.Order)
                  {
                  if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                  {
                  myTrailStop = SetTrailStop(CalculationMode.Ticks, Stop);
                  myTarget2 = SetProfitTarget(@"Short2", CalculationMode.Ticks, Target2Ticks);
                  if (execution.Order.OrderState != OrderState.PartFilled)
                  entryShort2 = null;
                  }
                  }

                  It compiles with ExitLongStopMarket, instead of SetTrailStop though.

                  I can't use SetTrailStop in OnExecutionUpdate?

                  Comment


                    #24
                    Hello itrader46, thanks for your reply.

                    SetProfitTarget and SetTrailStop do not return anything. If you need to set up stops and targets and get a reference to the Order object, see this example:

                    https://ninjatrader.com/support/help...and_onexec.htm

                    If you have code that only needs to be run once on each bar, you can use IsFirstTickOfBar to separate OnBarClose code from OnEachTick code. There is a reference sample of that here:

                    https://ninjatrader.com/support/help...either_cal.htm
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #25
                      So I have no way of using trailing stop, then?

                      Comment


                        #26
                        Hi itrader46,

                        A trailing stop would need to be implemented by your script. You can cancel the order with CancelOrder() then re-submit the order with the new price, or better yet use ChangeOrder(). When the price is no longer valid, move the order to the next price.
                        Chris L.NinjaTrader Customer Service

                        Comment


                          #27
                          I'm trying to do an ATM triggering strategy, to get around the logic of trailing stops and targets and it works pretty good, but I'm having a bit of trouble with the prints, as you can see in the attachments, which makes it difficult for me to asses exactly how the strategy works. Sometimes, it prints an error about the order ID, as you can see in the second attachment.

                          Also, there are no trace order prints

                          So, my question is: what am I doing wrong in the way I set my prints up and how do I make it stop printing countless cancel and condition lines when I don't need it to?

                          The strategy is set to calculate mode Tick

                          Thank you


                          protected override void OnBarUpdate()
                          {
                          if (BarsInProgress != 0)
                          return;

                          if (CurrentBars[0] < 1)
                          return;

                          // Make sure this strategy does not execute against historical data
                          if(State == State.Historical)
                          return;

                          if (longOrderId.Length > 0)
                          {
                          // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements.
                          string[] status = GetAtmStrategyEntryOrderStatus(longOrderId);
                          if (status.GetLength(0) > 0)
                          {
                          // If the order state is terminal, reset the order id value.
                          if (status[0] == "Filled" || status[0] == "Cancelled" || status[0] == "Rejected")
                          longOrderId = string.Empty;
                          }
                          }
                          // If the strategy has terminated reset the strategy id.
                          else if (longAtmId.Length > 0 && GetAtmStrategyMarketPosition(longAtmId) == Cbi.MarketPosition.Flat)
                          {
                          longAtmId = string.Empty;
                          isLongAtmStrategyCreated = false;
                          }

                          // Check for a pending short order.
                          if (shortOrderId.Length > 0)
                          {
                          // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements.
                          string[] status = GetAtmStrategyEntryOrderStatus(shortOrderId);
                          if (status.GetLength(0) > 0)
                          {
                          // If the order state is terminal, reset the order id value.
                          if (status[0] == "Filled" || status[0] == "Cancelled" || status[0] == "Rejected")
                          shortOrderId = string.Empty;
                          }
                          }
                          // If the strategy has terminated reset the strategy id.
                          else if (shortAtmId.Length > 0 && GetAtmStrategyMarketPosition(shortAtmId) == Cbi.MarketPosition.Flat)
                          {
                          shortAtmId = string.Empty;
                          isShortAtmStrategyCreated = false;
                          }


                          if(condition = true)
                          {
                          Print("Long condition at : "+Time[0]);
                          // If there is a short ATM Strategy running close it.
                          if(shortAtmId.Length != 0 && isShortAtmStrategyCreated)
                          {
                          AtmStrategyClose(shortAtmId);
                          isShortAtmStrategyCreated = false;
                          }
                          // Ensure no other long ATM Strategy is running.
                          if(longOrderId.Length == 0 && longAtmId.Length == 0 && !isLongAtmStrategyCreated)
                          {
                          longOrderId = GetAtmStrategyUniqueId();
                          longAtmId = GetAtmStrategyUniqueId();
                          AtmStrategyCreate(OrderAction.Buy, OrderType.StopLimit, (GetCurrentAsk(0) + (StopOffsetLong * TickSize)), (GetCurrentAsk(0) + (StopOffsetLong * TickSize)), TimeInForce.Day, longOrderId, "3C", longAtmId, (atmCallbackErrorCode, atmCallBackId) =>
                          {
                          //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
                          if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == longAtmId)
                          isLongAtmStrategyCreated = true;
                          });
                          stopPrice = GetCurrentAsk(0);
                          Print(Convert.ToString(Times[0][0]) + " - " + "Stop Price Long: " + Convert.ToString(stopPrice));
                          }

                          }

                          else if (longAtmId.Length != 0 && isLongAtmStrategyCreated && (condition = false) && (currentAsk <= stopPrice - CancelOffsetTicks * TickSize))
                          {
                          AtmStrategyCancelEntryOrder(longOrderId);
                          cancelPrice = GetCurrentAsk(0);
                          Print(Convert.ToString(Times[0][0]) + " - " + "Cancel Price Long: " + Convert.ToString(cancelPrice));
                          }


                          if(condition = true)
                          {
                          Print("Short condition at " + Time[0]);
                          // If there is a long ATM Strategy running close it.
                          if(longAtmId.Length != 0 && isLongAtmStrategyCreated)
                          {
                          AtmStrategyClose(longAtmId);
                          isLongAtmStrategyCreated = false;
                          }
                          // Ensure no other short ATM Strategy is running.
                          if(shortOrderId.Length == 0 && shortAtmId.Length == 0 && !isShortAtmStrategyCreated)
                          {
                          shortOrderId = GetAtmStrategyUniqueId();
                          shortAtmId = GetAtmStrategyUniqueId();
                          AtmStrategyCreate(OrderAction.Sell, OrderType.StopLimit, (GetCurrentBid(0) - (StopOffsetShort * TickSize)), (GetCurrentBid(0) - (StopOffsetShort * TickSize)), TimeInForce.Day, shortOrderId, "3C", shortAtmId, (atmCallbackErrorCode, atmCallBackId) =>
                          {
                          //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
                          if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == shortAtmId)
                          isShortAtmStrategyCreated = true;
                          });
                          stopPrice = GetCurrentBid(0);
                          Print(Convert.ToString(Times[0][0]) + " - " + "Stop Price Short: " + Convert.ToString(stopPrice));
                          }

                          }

                          else if (shortAtmId.Length != 0 && isShortAtmStrategyCreated && (condition = false) && (currentBid >= stopPrice + CancelOffsetTicks * TickSize))
                          {
                          AtmStrategyCancelEntryOrder(shortOrderId);
                          cancelPrice = GetCurrentBid(0);
                          Print(Convert.ToString(Times[0][0]) + " - " + "Cancel Price Short: " + Convert.ToString(cancelPrice));
                          }
                          Attached Files

                          Comment


                            #28
                            Also, the strategies don't reset, so after a short and a long order, there is no other order in any direction

                            Comment


                              #29
                              Hello itrader46, thanks for your reply.

                              The Print statements need to be placed deliberately to focus on a specific part of your script. They will be called whenever the logic processes them. If you would like to limit how often you see the prints, you can use logic to control when they are called or remove the prints all together. It is often useful to add prints specifically for a section you are working on so your output is only relevant to the issue you are looking into. I'm unable to debug individual code, but I think focusing on one issue and addressing it would be the best way forward. I wanted to attach this "ATMStrategyMonitor" script that identifies and reports data on an ATM strategy using OnOrderUpdate, it could prove useful.
                              Attached Files
                              Chris L.NinjaTrader Customer Service

                              Comment


                                #30
                                I managed in the meantime to make it reset again. It was down to me changing the "status[2]" below to "status[0]", but I can't find in the help guide what that does. Can you help me with that, please? I thought [2] is two bars ago, but it obviously isn't

                                string[] status = GetAtmStrategyEntryOrderStatus(shortOrderId);
                                if (status.GetLength(0) > 0)
                                {
                                // If the order state is terminal, reset the order id value.
                                if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
                                shortOrderId = string.Empty;
                                }

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Goolden, Today, 09:51 AM
                                1 response
                                9 views
                                0 likes
                                Last Post NinjaTrader_Jesse  
                                Started by ArmKnuckle, Today, 01:25 AM
                                1 response
                                25 views
                                0 likes
                                Last Post NinjaTrader_Jesse  
                                Started by 7robert, Today, 08:26 AM
                                1 response
                                5 views
                                0 likes
                                Last Post NinjaTrader_Jesse  
                                Started by 7robert, Today, 08:08 AM
                                1 response
                                6 views
                                0 likes
                                Last Post NinjaTrader_Jim  
                                Started by ttodua, Today, 08:09 AM
                                1 response
                                10 views
                                0 likes
                                Last Post NinjaTrader_Jim  
                                Working...
                                X