Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

onExecution - stop not working/accepted

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

    onExecution - stop not working/accepted

    Hello,

    I try to solve a strange problem for days now but I can´t find the reason for this:

    when the entry is filled then I bring in the stops in onExecution. This works sometimes and sometimes there is only the entry but no stop!?

    if (entryOrder1 != null && entryOrder1 == execution.Order && execution.Order.OrderState == OrderState.Filled)
    {stopOrder1a = ExitShortStop(0, true, 1000, execution.Order.AvgFillPrice +80 * TickSize, "StopD1a", "D5");

    I need not to debug with coloring or variables, because we see that the entry is filled. The trade itself shows that it works (correctly referring conditons). So, the stop should be accepted also.

    What might be the reason that sometimes the stop is not "there" (not accepted/not recjected/not working" - nothing appears in orderstab!)

    Thank you.
    Tony

    #2
    Hello Tony,

    If you place TraceOrders = true; inside of Intialize() and a Print() inside of your condition so that you can see when it is being called what do you see inside of the Output window?



    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hello,

      thank you for your reply. Yes, I do traceorders and I see the correct informations when the entry and the stop is filled/accepted.

      In case of missing stop there is in the output window:

      29.05.2013 12:29:38 Entered internal PlaceOrder() method at 29.05.2013 12:29:38: BarsInProgress=3 Action=SellShort OrderType=Market Quantity=3.000 LimitPrice=0 StopPrice=0 SignalName='STO5' FromEntrySignal=''
      29.05.2013 12:29:38 Entered internal PlaceOrder() method at 29.05.2013 12:29:38: BarsInProgress=3 Action=SellShort OrderType=Market Quantity=3.000 LimitPrice=0 StopPrice=0 SignalName='STO5' FromEntrySignal=''
      29.05.2013 12:29:38 Ignored PlaceOrder() method at 29.05.2013 12:29:38: Action=SellShort OrderType=Market Quantity=3.000 LimitPrice=0 StopPrice=0 SignalName='STO5' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'

      So, the enty is filled and it appears in the executions tab and in chart trader but the stop is not there. (Not in output window, not in the order tab) . I´m wondering why there appears the informaton a 2nd time. However the entry is done, so why no stop?

      In case of correct entry and stop it shows:

      29.05.2013 14:04:06 Entered internal PlaceOrder() method at 29.05.2013 14:04:06: BarsInProgress=3 Action=SellShort OrderType=Market Quantity=3.000 LimitPrice=0 StopPrice=0 SignalName='STO5' FromEntrySignal=''
      entryOrder1 Order='bba6841ebb8341eaa02129de29233cd8/Sim101' Name='STO5' State=Filled Instrument='$USDCAD' Action=SellShort Limit price=0 Stop price=0 Quantity=3.000 Type=Market Tif=Gtc OverFill=False Oco='' Filled=3000 Fill price=1,03717 Token='bba6841ebb8341eaa02129de29233cd8' Gtd='01.01.0001 00:00:00'
      29.05.2013 14:03:57
      29.05.2013 14:04:06 Entered internal PlaceOrder() method at 29.05.2013 14:04:06: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=1.000 LimitPrice=0 StopPrice=1,0379'7 SignalName='StopSTO1a' FromEntrySignal='STO5'
      29.05.2013 14:04:06 Entered internal PlaceOrder() method at 29.05.2013 14:04:06: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=1.000 LimitPrice=0 StopPrice=1,0379'7 SignalName='StopSTO1b' FromEntrySignal='STO5'
      29.05.2013 14:04:06 Entered internal PlaceOrder() method at 29.05.2013 14:04:06: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=1.000 LimitPrice=0 StopPrice=1,0379'7 SignalName='StopSTO1c' FromEntrySignal='STO5'




      Thank you for your support.
      Tony

      Originally posted by NinjaTrader_JC View Post
      Hello Tony,

      If you place TraceOrders = true; inside of Intialize() and a Print() inside of your condition so that you can see when it is being called what do you see inside of the Output window?



      Happy to be of further assistance.
      Last edited by tonynt; 05-29-2013, 08:27 AM.

      Comment


        #4
        Hello Tony,

        It would appear a second time if another order gets called again, or their is another order being placed with the same parameters.

        Are you running this in real-time or Historical?

        Also, how are you calling this entry order? Inside of OnBarUpdate?

        As for why your other order is not being called, it may be due to your conditions not being hit since I do not see the order trying to be placed. You may want to use Print() statements to make sure that your conditions are all true and also inside of your Condition so that you can easily tell when it is all true as well.
        JCNinjaTrader Customer Service

        Comment


          #5
          Thank you for your reply.

          * It appears a second time because of conditions true - therefore I have set the Entry handling to avoid a 2nd entry - so this is correct and expected(?)

          * I run this in realtime

          * the entry order conditions are in onbarupdate and the action is eg "entryOrder1=EnterShort(3000,"D5")"

          * and then I do the corresponding stops in onExecution (that works fine about 50% of the trades)
          if (entryOrder1 != null && entryOrder1 == execution.Order && execution.Order.OrderState == OrderState.Filled)
          {stopOrder1a = ExitShortStop(0, true, 1000, execution.Order.AvgFillPrice +80 * TickSize, "StopD1a", "D5");
          stopOrder1b = ExitShortStop(0, true, 1000, execution.Order.AvgFillPrice +80 * TickSize, "StopD1b", "D5");
          stopOrder1c = ExitShortStop(0, true, 1000, execution.Order.AvgFillPrice +80 * TickSize, "StopD1c", "D5");}

          * The conditions for calling the stop-orders is true, no? Or is this the misunderstanding on my end - and the solution. I thought the condition for the stoporders is OK with "if entryOrder1......filled". Isn´t this a correct condition for calling the stop?

          * What you suggest to print() in this case to find out?

          Thank you for your support.

          Tony


          Originally posted by NinjaTrader_JC View Post
          Hello Tony,

          It would appear a second time if another order gets called again, or their is another order being placed with the same parameters.

          Are you running this in real-time or Historical?

          Also, how are you calling this entry order? Inside of OnBarUpdate?

          As for why your other order is not being called, it may be due to your conditions not being hit since I do not see the order trying to be placed. You may want to use Print() statements to make sure that your conditions are all true and also inside of your Condition so that you can easily tell when it is all true as well.

          Comment


            #6
            Hello Tony,

            That is correct and expected, yes.

            From the snippets everything looks good, but if the conditions where true every-time you would see that Inside of the Output window if the order was ignored or rejected. If they are not being called as you expected then we need to see what is changed.

            You would want to Print the "entryOrder1" and "execution.Order" before the if() statement.

            Print("EntryOrder String: "+entryOrder1.ToString());

            Print("Execution Order String: "+execution.Order.ToString());

            Also inside of the Condition you may want to Print something to easily see when the condition is true and when it is not true for comparison.
            JCNinjaTrader Customer Service

            Comment


              #7
              Originally posted by tonynt View Post
              Hello,

              thank you for your reply. Yes, I do traceorders and I see the correct informations when the entry and the stop is filled/accepted.

              In case of missing stop there is in the output window:

              29.05.2013 12:29:38 Entered internal PlaceOrder() method at 29.05.2013 12:29:38: BarsInProgress=3 Action=SellShort OrderType=Market Quantity=3.000 LimitPrice=0 StopPrice=0 SignalName='STO5' FromEntrySignal=''
              29.05.2013 12:29:38 Entered internal PlaceOrder() method at 29.05.2013 12:29:38: BarsInProgress=3 Action=SellShort OrderType=Market Quantity=3.000 LimitPrice=0 StopPrice=0 SignalName='STO5' FromEntrySignal=''
              29.05.2013 12:29:38 Ignored PlaceOrder() method at 29.05.2013 12:29:38: Action=SellShort OrderType=Market Quantity=3.000 LimitPrice=0 StopPrice=0 SignalName='STO5' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'

              So, the enty is filled and it appears in the executions tab and in chart trader but the stop is not there. (Not in output window, not in the order tab) . I´m wondering why there appears the informaton a 2nd time. However the entry is done, so why no stop?

              In case of correct entry and stop it shows:

              29.05.2013 14:04:06 Entered internal PlaceOrder() method at 29.05.2013 14:04:06: BarsInProgress=3 Action=SellShort OrderType=Market Quantity=3.000 LimitPrice=0 StopPrice=0 SignalName='STO5' FromEntrySignal=''
              entryOrder1 Order='bba6841ebb8341eaa02129de29233cd8/Sim101' Name='STO5' State=Filled Instrument='$USDCAD' Action=SellShort Limit price=0 Stop price=0 Quantity=3.000 Type=Market Tif=Gtc OverFill=False Oco='' Filled=3000 Fill price=1,03717 Token='bba6841ebb8341eaa02129de29233cd8' Gtd='01.01.0001 00:00:00'
              29.05.2013 14:03:57
              29.05.2013 14:04:06 Entered internal PlaceOrder() method at 29.05.2013 14:04:06: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=1.000 LimitPrice=0 StopPrice=1,0379'7 SignalName='StopSTO1a' FromEntrySignal='STO5'
              29.05.2013 14:04:06 Entered internal PlaceOrder() method at 29.05.2013 14:04:06: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=1.000 LimitPrice=0 StopPrice=1,0379'7 SignalName='StopSTO1b' FromEntrySignal='STO5'
              29.05.2013 14:04:06 Entered internal PlaceOrder() method at 29.05.2013 14:04:06: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=1.000 LimitPrice=0 StopPrice=1,0379'7 SignalName='StopSTO1c' FromEntrySignal='STO5'




              Thank you for your support.
              Tony
              You need to check your code to see why it is trying to enter the same order twice. The text in Blue, and Cyan show that your code is trying to enter twice. The text in Green is in response to the second entry, which it appears would, therefore, not trigger an OnExecution() event.

              (Emphasis mine).
              Last edited by koganam; 07-21-2013, 11:45 AM. Reason: Corrected spelling and punctuation.

              Comment


                #8
                koganam, JC

                Thank you for your responses.

                I could find the error with your help.

                Best regards
                Tony
                Last edited by tonynt; 05-31-2013, 09:06 AM. Reason: clearify

                Comment


                  #9
                  koganam,

                  thank you for all your replies. We found out what the reason for the problem was and I want to inform you about.

                  Usually there are no interdependencies between different script strategies. This is what I thought for months. But "onposition" can have impact to other strategies, and this was the reason for my problems. I did reset my variables in onposition (when flat) but this needs to be done in onorderupdate to avoid this certain problems.

                  As you are very competent and you know a lot about NinjaTrader (you also answered me how to plot lines to the right side margin) I want to ask you a question, that maybe for you is a small step, but for me not to solve. How would you plot a line starting at the close of a bar starting each day the same time eg 10:00 PM and end the line next day 9:00 PM (for trading on mondays or after holidays the line would start 2 days before)

                  Thanks again for all your posts.

                  Best regards
                  Tony

                  Originally posted by koganam View Post
                  You need to check your code to see why it is trying to enter the same order twice. The text in Blue, and Cyan show that your code is trying to enter twice. The text in Green is in response to the second entry, which it appears would theretore, not trigger an OnExecution() event.

                  (Emphasis mine).

                  Comment


                    #10
                    Originally posted by tonynt View Post
                    koganam,

                    thank you for all your replies. We found out what the reason for the problem was and I want to inform you about.

                    Usually there are no interdependencies between different script strategies. This is what I thought for months. But "onposition" can have impact to other strategies, and this was the reason for my problems. I did reset my variables in onposition (when flat) but this needs to be done in onorderupdate to avoid this certain problems.

                    As you are very competent and you know a lot about NinjaTrader (you also answered me how to plot lines to the right side margin) I want to ask you a question, that maybe for you is a small step, but for me not to solve. How would you plot a line starting at the close of a bar starting each day the same time eg 10:00 PM and end the line next day 9:00 PM (for trading on mondays or after holidays the line would start 2 days before)

                    Thanks again for all your posts.

                    Best regards
                    Tony
                    You seem to have given all the information that you need, so what is the difficulty? You just need to specify the start and end times of the line.

                    Code:
                     
                    //Declare class variables to hold the values:
                     
                    private DateTime StartTime;
                    private DateTime EndTime;
                    private double LineValue;
                    private bool Initialized = false;
                    Code:
                     
                    //Then reset the start time every day when it arrives
                     
                    if (CurrentBar < 1) return;
                     
                    if (Time[1] <= Time[0].Date.Add(new TimeSpan(22, 00, 00))
                        && Time[0] > Time[0].Date.Add(new TimeSpan(22, 00, 00) ))
                    {
                    int StartBarIndex = 1; //or "0" depending on which bar you want to use.
                    StartTime = Time[StartBarIndex]; 
                    EndTime = StartTime.AddHours(23);
                    LineValue = Close[StartBarIndex];
                    Initialized = true; //needed at the very beginning so that we do not fall through with invalid Times
                    }
                     
                    if (!Initialized) return;
                     
                    //Now draw the line with the StartTime And EndTime.
                    DrawLine("TonyLine" + CurrentBar.ToString(), true, StartTime, LineValue, EndTime, LineValue, Color.Blue, DashStyle.Solid, 2);

                    Comment


                      #11
                      koganam,

                      thank you for your reply!

                      The difficulty was that with one solution the line was not plotted the actual month when there are 2 month (or more) in the dataseries and with the other solution there was no line plotted on Monday.

                      With your solution now everything works it seems.

                      THANK YOU!

                      I wish you a great weekend!

                      Best regards
                      Tony

                      Originally posted by koganam View Post
                      You seem to have given all the information that you need, so what is the difficulty? You just need to specify the start and end times of the line.

                      Code:
                       
                      //Declare class variables to hold the values:
                       
                      private DateTime StartTime;
                      private DateTime EndTime;
                      private double LineValue;
                      private bool Initialized = false;
                      Code:
                       
                      //Then reset the start time every day when it arrives
                       
                      if (CurrentBar < 1) return;
                       
                      if (Time[1] <= Time[0].Date.Add(new TimeSpan(22, 00, 00))
                          && Time[0] > Time[0].Date.Add(new TimeSpan(22, 00, 00) ))
                      {
                      int StartBarIndex = 1; //or "0" depending on which bar you want to use.
                      StartTime = Time[StartBarIndex]; 
                      EndTime = StartTime.AddHours(23);
                      LineValue = Close[StartBarIndex];
                      Initialized = true; //needed at the very beginning so that we do not fall through with invalid Times
                      }
                       
                      if (!Initialized) return;
                       
                      //Now draw the line with the StartTime And EndTime.
                      DrawLine("TonyLine" + CurrentBar.ToString(), true, StartTime, LineValue, EndTime, LineValue, Color.Blue, DashStyle.Solid, 2);
                      Last edited by tonynt; 06-07-2013, 02:06 PM. Reason: Thanks to the post

                      Comment


                        #12
                        koganam,

                        I want to post again for being sure you receive my thanks.

                        With your coding it works and I want to thank you again and wish you all the best.

                        Tony

                        Comment


                          #13
                          Originally posted by tonynt View Post
                          koganam,

                          I want to post again for being sure you receive my thanks.

                          With your coding it works and I want to thank you again and wish you all the best.

                          Tony
                          I am glad that you have it working.

                          All the best, and good trading to you!

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by wzgy0920, 04-20-2024, 06:09 PM
                          2 responses
                          27 views
                          0 likes
                          Last Post wzgy0920  
                          Started by wzgy0920, 02-22-2024, 01:11 AM
                          5 responses
                          32 views
                          0 likes
                          Last Post wzgy0920  
                          Started by wzgy0920, 04-23-2024, 09:53 PM
                          2 responses
                          49 views
                          0 likes
                          Last Post wzgy0920  
                          Started by Kensonprib, 04-28-2021, 10:11 AM
                          5 responses
                          193 views
                          0 likes
                          Last Post Hasadafa  
                          Started by GussJ, 03-04-2020, 03:11 PM
                          11 responses
                          3,235 views
                          0 likes
                          Last Post xiinteractive  
                          Working...
                          X