• 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

Managed approach EnterLongLimit

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

    Managed approach EnterLongLimit

    I created a strategy with 2 seperate EnterLongLimit at the same price. The order is created but for some reason the next bar the order gets cancelled.

    The questions I have are the following


    Can one SetStopLoss AND SetProfitTarget before the the order is executed?

    If not do I setStopLoss and ProfitTarget on OnPostionUpdate OR OnExecttionUpdate?



    if(Position.MarketPosition == MarketPosition.Short)
    {
    ExitShort("Short1");

    if(nTarget2Contracts != 0)
    ExitShort("Short2");

    }

    if(Position.MarketPosition == MarketPosition.Flat)
    {

    SetProfitTarget("Long1",CalculationMode.Price,dPri ceA,true);
    SetProfitTarget("Long2",CalculationMode.Price,dPri ceB,true);
    SetStopLoss("Long1",CalculationMode.Price,dStopLos sA,false);
    if(nTarget2Contracts != 0)
    SetStopLoss("Long2",CalculationMode.Price,dStopLos sA,false);


    EnterLongLimit(nTarget1Contracts,dLimitPriceA,"Lon g1");
    if(nTarget2Contracts != 0)
    EnterLongLimit(nTarget2Contracts,dLimitPriceA,"Lon g2");
    }



    #2
    Hello ballboy11,

    If isLiveUntilCancelled is not used, it defaults to false and the order will be cancelled when the submission bar closes if the order is not resubmitted.

    Below is a link to the help guide. Please see the definition for isLiveUntilCancelled.
    https://ninjatrader.com/support/help...rlonglimit.htm


    Set methods should be set before the entry order is placed. This is because they cannot be unset and will continue to use old values for new orders.
    Below is a link to an example that uses set methods and sets these before the entry is placed.
    https://ninjatrader.com/support/foru...269#post802269
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3

      I added the OnOrderUpdate Logic and I am starting to have Issues
      If I keep the OnOrderLogic update out and my order is not filled, my limit order will stay activated until filled.

      I need to cancel all my orders and re submit my new limit order.


      private Order oEntryOrder1 = null;




      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")
      oEntryOrder1 = order;

      if (order.Name == "Short1")
      oEntryOrder1 = order;

      // Evaluates for all updates to myEntryOrder.
      if (oEntryOrder1 != null && oEntryOrder1 == order)
      {
      // Check if myEntryOrder is cancelled.
      if (oEntryOrder1.OrderState == OrderState.Cancelled)
      {
      // Reset myEntryOrder back to null
      oEntryOrder1 = null;
      }
      }
      }

      //bar update logic

      if(CurrentBar>3)
      {

      if(bShort)
      {

      bLong = true;
      bShort = false;

      //************************************************** ************************
      if (oEntryOrder1 != null) //THIS IS THE AREA I AM HAVING PROBLEMS WITH
      CancelOrder(oEntryOrder1);
      //************************************************** ****************************
      if(Position.MarketPosition == MarketPosition.Short)
      {
      ExitShort("Short1");
      }


      if(Position.MarketPosition == MarketPosition.Flat)
      {
      {

      SetProfitTarget("Long1",CalculationMode.Price,dTar get,true);
      SetStopLoss("Long1",CalculationMode.Price,dStopLos s,false);
      EnterLongLimit(0,true,nTarget1Contracts,dLimitPric e,"Long1");
      }
      }
      }
      else
      if(bLong)
      {
      bLong = false;
      bShort = true;

      //************************************************** *********************************************
      if (oEntryOrder1 != null)
      CancelOrder(oEntryOrder1);
      //************************************************** ***************************************
      if(Position.MarketPosition == MarketPosition.Long)

      {
      ExitLong("Long1");
      }




      if(Position.MarketPosition == MarketPosition.Flat)
      {

      SetProfitTarget("Short1",CalculationMode.Price,dTa rget,true);
      SetStopLoss("Short1",CalculationMode.Price,dStopLo ss,false);
      EnterShortLimit(0, true,nTarget1Contracts,dLimitPrice,"Short1");

      }


      }

      }








      Comment


        #4
        Hello ballboy11,

        What is the issue you are having?

        Is an error appearing?

        What is the error message?

        Is the order in a working or accepted state when supplying to CancelOrder()?

        Why are you cancelling an order and resubmitting it instead of keeping it alive and changing the price if desired?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I just got this error when it was transitioning from a buy to a sell

          Comment


            #6
            Hello ballboy11,

            The error indicates a historical order was attempted to be transitioned to a live order without using GetRealtimeOrder() on that order.

            You will need to use GetRealtimeOrder() in State.Realtime to transition an order from historical to live.

            Below is a link to the help guide.
            https://ninjatrader.com/support/help...ltimeorder.htm
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I read the GetRealTimeOrder but I am confused. I thought my logic closed the order.
              Where would I use the GetRealTimeOrder????



              if(Momentum[0] <Middle[0] && bCrossedDown == false)
              {
              bCrossedUp = false; //should only enter once until next crossover
              bCrossedDown = true;

              bManualStopMovement =false; //set until double clicked



              if(Position.MarketPosition == MarketPosition.Long)

              {
              if(nTarget1Contracts != 0)
              ExitLong("Long1"); // if contract still live close position

              }
              else
              {
              if (oEntryOrder1 != null)
              CancelOrder(oEntryOrder1); // if postion active and not filled cancel order

              }



              if(Position.MarketPosition == MarketPosition.Flat)
              {


              if(nTarget1Contracts != 0 && bManualStopMovement ==false ) // not sure how to override manual stop
              {

              //ENTER ORDER

              SetProfitTarget("Short1",CalculationMode.Price,dAT R1,true);
              SetStopLoss("Short1",CalculationMode.Price,dATR8,f alse);


              if(bUseMarketOrder == true)
              EnterShort(nTarget1Contracts,"Short1");
              else
              EnterShortLimit(0, true,nTarget1Contracts,dATR7,"Short1");
              }





              }


              }







              Comment


                #8
                Hello ballboy11,

                The error indicates that your strategy did not close the order in historical but it was modified after the script entered real-time. For these type of orders, you will need to transition them using GetRealtimeOrder exactly as the help guide shows. This can occur with the Order object you have used as you are manually controlling the orders lifecycle when using Order objects.

                You use the order object oEntryOrder1 in your code, so this is what you would use in place of "myOrder" which is what the help guide sample uses. You would need to make it look just like the sample in your script as well to avoid this message.

                I look forward to being of further assistance.

                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ntbone, Yesterday, 08:10 PM
                0 responses
                7 views
                0 likes
                Last Post ntbone
                by ntbone
                 
                Started by chrislou, 08-28-2015, 03:27 AM
                14 responses
                2,881 views
                0 likes
                Last Post nkhoi
                by nkhoi
                 
                Started by outofstock, Yesterday, 06:40 PM
                2 responses
                8 views
                0 likes
                Last Post outofstock  
                Started by saeed, Yesterday, 12:32 PM
                3 responses
                40 views
                0 likes
                Last Post NinjaTrader_PatrickG  
                Started by motog4, Yesterday, 11:42 AM
                3 responses
                21 views
                0 likes
                Last Post NinjaTrader_PatrickG  
                Working...
                X