• 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

entryconditions - trigger

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

    entryconditions - trigger

    Hello,

    I have a strange problem with entries and onorderupdate and onexecution. I do debugging with coloring and drawing objects and it occurs that with

    ConditionSet1 (COBC== false)

    if (BarsInProgress == 2
    && FirstTickOfBar
    && Closes[2][1] > Lows[2][1]
    && Position.MarketPosition == MarketPosition.Flat )

    there is an entry and onExecution works fine and onOrderupdate works fine (and my coloring and drawing objects work fine - in onExecution and onOrder)

    but with

    ConditionSet2 (COBC==false)

    if (BarsInProgress == 0
    && Position.MarketPosition == MarketPosition.Flat )

    there is an entry but onExecution and onOrder do not work - there is no coloring and no drawing objects (which I do for control). Only onbarupdate is correct (entry) but onorder and onexecution are not done.

    I do not understand, as condtionset 2 is more "easy". How can conditionset1 work correct all the time, but conditionset2 appears as I described 90% (only sometimes the coloring for debugging is correct)

    What is the issue here for onorder and onexecution please?
    (also when I add for NT another logic and true condition in conditionset2 like "if GetCurrentAsk() > GetCurrentBid()" there is only the entry from onbarupdate but nothing from onorderupdaten and onexecution)



    Thank you
    Tony
    Last edited by tonynt; 10-17-2013, 11:06 AM. Reason: clearify

    #2
    Hello tonynt,

    Have you added any prints to OnExecution (without any conditions) to ensure that the OnExecution is not being triggered?

    Are there conditions in OnExecution? If so, may I see the code for these?

    Are you submitting the order with the correct bars in progress?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      thank you for your response. I´m happy to send you my onExecution:

      if (entryOrderML1a != null && entryOrderML1a == execution.Order && execution.Order.OrderState == OrderState.Filled)
      {contracts=Position.Quantity;}

      if (entryOrderML1b != null && entryOrderML1b == execution.Order && execution.Order.OrderState == OrderState.Filled)
      {contracts++; }

      if (entryOrderML1c != null && entryOrderML1c == execution.Order && execution.Order.OrderState == OrderState.Filled)
      {contracts++;
      _button.Text = contracts.ToString();
      stopstepa=1; Print("stopstepa: " + stopstepa); Print(Time[0]);
      BackColor=Color.LightGray;
      DrawLine("Entry", false,0,GetCurrentAsk(),-30,GetCurrentAsk(), Color.Black, DashStyle.Dash,3);
      DrawLine("InitialStop", false,0,GetCurrentAsk()-10*TickSize,-30,GetCurrentAsk()-10*TickSize, Color.Magenta,DashStyle.Dash,3);

      This is exactly the same in both strategies - I had posted the entry condtions with set1 and set2 (set1 is to enter at reversal bar and set2 is to do an entry immediately). The more strange for me is why in 100% of the trades all is correct for conditionset1 but with conditionset2 only some times it works (all is the same - and when each entry-condtion is true we have the entryOrder filled - so it should work in onExecution in both sets)

      Thanks
      Tony

      Originally posted by NinjaTrader_ChelseaB View Post
      Hello tonynt,

      Have you added any prints to OnExecution (without any conditions) to ensure that the OnExecution is not being triggered?

      Are there conditions in OnExecution? If so, may I see the code for these?

      Are you submitting the order with the correct bars in progress?
      Last edited by tonynt; 10-17-2013, 12:55 PM. Reason: clearify

      Comment


        #4
        Hi tonynt,

        I think I will need to the complete script to understand what is happening.

        In the executions it looks like its using the handle so the handle must be set in the trigger of the entry.

        Can you send me the complete script to look at? (a simplified version that only contains code necessary to reproduce this if possible)

        Send to support[at]ninjatrader[dot]com Attn: Chelsea #937239.

        Also, please add a link to this forum thread.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea,

          I think I have an idea about the reason. I seperated the drawings and orders and I can see now that the TIME is the reason for strange behavor. I put some codes to onExecution and others to onBarUpdate. But what I see now is alarmingly:

          There is the entry (I see in my seperate "chart-trader-control-window" and there are the drawings in the "strategy-chart-window". And only about 2-3 seconds later there appear the stops! Why do the stops not appear the same time as the entry?

          Should the Setstoploss not be in onBarUpdate?

          Thank you for your support.
          Tony.


          Originally posted by NinjaTrader_ChelseaB View Post
          Hi tonynt,

          I think I will need to the complete script to understand what is happening.

          In the executions it looks like its using the handle so the handle must be set in the trigger of the entry.

          Can you send me the complete script to look at? (a simplified version that only contains code necessary to reproduce this if possible)

          Send to support[at]ninjatrader[dot]com Attn: Chelsea #937239.

          Also, please add a link to this forum thread.

          Comment


            #6
            Hi tonynt,

            The stops are being set a bar later because you are setting them in OnBarUpdate(). This means that after the order is placed, a new bar must form before OnBarUpdate will be run again.

            Try setting the stop loss in Initialize or in OnExecution() instead.

            Then they will be set when the entry fills.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea,

              I put them into onbarupdate because in some samples from NinjaTrader the setstoploss is in onbarupdate eg "SamplePriceModification". I´m wondering why in the sample it is there, so I have done same.

              Did you found out maybe why the entries, stops and drawings are correct with conditionsetup1 but eg the horizontal line for entry and stop are not there with conditionsetup2 - both conditions cause the entry that is done and in onExecution TOGETHER with the entry are the drawings? (Together I mean: there shouldn´t be an entry OR entry and drawings should be done, no?)

              Thank you for your support.

              Best regards
              Tony

              Originally posted by NinjaTrader_ChelseaB View Post
              Hi tonynt,

              The stops are being set a bar later because you are setting them in OnBarUpdate(). This means that after the order is placed, a new bar must form before OnBarUpdate will be run again.

              Try setting the stop loss in Initialize or in OnExecution() instead.

              Then they will be set when the entry fills.

              Comment


                #8
                Hello tonynt,

                Take a look at the SamplePriceModification script again.

                http://www.ninjatrader.com/support/f...ead.php?t=3222

                This is in Initialize():
                Code:
                SetStopLoss(CalculationMode.Ticks, stoplossticks);
                SetProfitTarget(CalculationMode.Ticks, profittargetticks);
                This is in OnBarUpdate():
                Code:
                if (Position.MarketPosition == MarketPosition.Flat)
                {
                SetStopLoss(CalculationMode.Ticks, stoplossticks);
                }
                			
                // If a long position is open, allow for stop loss modification to breakeven
                else if (Position.MarketPosition == MarketPosition.Long)
                {
                // Once the price is greater than entry price+50 ticks, set stop loss to breakeven
                if (Close[0] > Position.AvgPrice + 50 * TickSize)
                {
                SetStopLoss(CalculationMode.Price, Position.AvgPrice);
                }
                }
                In the script the initial stop loss and profit target are being set. This is why orders are protected the moment they are entered. In your script you do not have this.

                Also in the sample they are actually modifying the price at which the stop loss is sitting. Your script does not have this either. It is simply setting the stop loss to the same level of 8 ticks over and over.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello,

                  thank you for your support. I have changed referring your informations and it works.

                  Please let me do another question:

                  For exitorders filled I have set in OnExecution section counting and additional actions then: if(exitOrder1a != null && exitOrder1a == execution.Order && execution.Order.OrderState == OrderState.Filled)
                  contracts--;Print("contracts/exit: " + contracts); Print(Time[0]);

                  But this doesn´t work. I have no idea why. The exit is filled (I see reduced quantity beside in my chart with chart-trader): Output window shows:

                  18.10.2013 10:02:04 Entered internal PlaceOrder() method at 18.10.2013 10:02:04: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='xML1a' FromEntrySignal='ML1a'

                  18.10.2013 10:02:04 Ignored PlaceOrder() method: Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=xML1a' FromEntrySignal='ML1a' Reason='There already is a matching, filled exit order in place'

                  18.10.2013 10:02:04 Cancelled pending exit order, since associated position is closed: Order='39d4114789534828a4d38f97b50da66f/Sim101' Name='Stop loss' State=Accepted Instrument='YM 12-13' Action=Sell Limit price=0 Stop price=15307 Quantity=1 Strategy='a1111kLstops' Type=Stop Tif=Gtc Oco='cf4b9571288643fcacdb5d16273b56f8-3825' Filled=0 Fill price=0 Token='39d4114789534828a4d38f97b50da66f' Gtd='01.12.2099 00:00:00'

                  18.10.2013 10:02:05 Entered internal PlaceOrder() method at 18.10.2013 10:02:05: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='xML1a' FromEntrySignal='ML1a'
                  18.10.2013 10:02:05 Ignored PlaceOrder() method at 18.10.2013 10:02:05: Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='xML1a' FromEntrySignal='ML1a' Reason='SignalName does not have a matching FromEntrySignal to exit'

                  Thank you so much for your support. Please let us find out this last brick.

                  Best regards
                  Tony



                  Originally posted by NinjaTrader_ChelseaB View Post
                  Hello tonynt,

                  Take a look at the SamplePriceModification script again.

                  http://www.ninjatrader.com/support/f...ead.php?t=3222

                  This is in Initialize():
                  Code:
                  SetStopLoss(CalculationMode.Ticks, stoplossticks);
                  SetProfitTarget(CalculationMode.Ticks, profittargetticks);
                  This is in OnBarUpdate():
                  Code:
                  if (Position.MarketPosition == MarketPosition.Flat)
                  {
                  SetStopLoss(CalculationMode.Ticks, stoplossticks);
                  }
                              
                  // If a long position is open, allow for stop loss modification to breakeven
                  else if (Position.MarketPosition == MarketPosition.Long)
                  {
                  // Once the price is greater than entry price+50 ticks, set stop loss to breakeven
                  if (Close[0] > Position.AvgPrice + 50 * TickSize)
                  {
                  SetStopLoss(CalculationMode.Price, Position.AvgPrice);
                  }
                  }
                  In the script the initial stop loss and profit target are being set. This is why orders are protected the moment they are entered. In your script you do not have this.

                  Also in the sample they are actually modifying the price at which the stop loss is sitting. Your script does not have this either. It is simply setting the stop loss to the same level of 8 ticks over and over.
                  Last edited by tonynt; 10-18-2013, 08:13 AM. Reason: clearify

                  Comment


                    #10
                    Hello tonynt,

                    This code is different than the code you have supplied to me.

                    What is the value of the contracts variable before the execution?

                    Where are the prints that you have added in your output?
                    Print("contracts/exit: " + contracts); Print(Time[0]);

                    You are using exitOrder1a. Where is this order triggered? (SetStopLoss will not give you an IOrder handle btw)
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello Chelsea,

                      thank you for you reply.

                      * The contracts value is set to "0" when flat and then counts up untill 3 - as I described in my 2nd post here. This works correct.

                      * The prints do not appear in output - this I do not understand.

                      * Order triggering is in onbarupdate:
                      if(contracts==3 && GetCurrentBid() > Position.AvgPrice + 5 * TickSize)
                      exitOrder1a = ExitLong(1, "xML1a","ML1a");

                      exitOrder1a is done correctly as I described in a post before and I can see in the chart with chart-trader reduced quantity and stops. But it is strange that contracts--;Print("contracts/exit: " + contracts); Print(Time[0]); does not work.

                      Thats it.

                      Thank you for your support.
                      Tony




                      Originally posted by NinjaTrader_ChelseaB View Post
                      Hello tonynt,

                      This code is different than the code you have supplied to me.

                      What is the value of the contracts variable before the execution?

                      Where are the prints that you have added in your output?
                      Print("contracts/exit: " + contracts); Print(Time[0]);

                      You are using exitOrder1a. Where is this order triggered? (SetStopLoss will not give you an IOrder handle btw)
                      Last edited by tonynt; 10-18-2013, 01:41 PM. Reason: clearify

                      Comment


                        #12
                        Hi tonynt,

                        Add the following print to the beginning of your OnExecution() code and then post the output.

                        Print(execution.ToString());
                        if (exitOrder1a == null)
                        Print("null");
                        if (exitOrder1a != execution.Order)
                        Print("not this execution");
                        if (execution.Order.OrderState == OrderState.Filled)
                        Print("not filled "+execution.Order.OrderState.ToString());
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello Chelsea,

                          thanks again for your support. I have done so and this appears in output window:

                          18.10.2013 16:08:46 Entered internal PlaceOrder() method at 18.10.2013 16:08:46: BarsInProgress=9 Action=BuyToCover OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='xMS1a' FromEntrySignal='MS1a'
                          18.10.2013 16:08:46 Ignored PlaceOrder() method: Action=BuyToCover OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=xMS1a' FromEntrySignal='MS1a' Reason='There already is a matching, filled exit order in place'
                          18.10.2013 16:08:46 Cancelled pending exit order, since associated position is closed: Order='eca2c0f3206d46ac99cfd76e491bc32e/Sim101' Name='Stop loss' State=Accepted Instrument='NQ 12-13' Action=BuyToCover Limit price=0 Stop price=3348,75 Quantity=1 Strategy='a1111kSstops' Type=Stop Tif=Gtc Oco='d4f647db62784e01b5e7d7b12a55de8a-3476' Filled=0 Fill price=0 Token='eca2c0f3206d46ac99cfd76e491bc32e' Gtd='01.12.2099 00:00:00'
                          Execution='9ed297898f0349a99fc6d67897193030' Instrument='NQ 12-13' Account='Sim101' Name='xMS1a' Exchange=Default Price=3345,5 Quantity=1 Market position=Long Commission=0 Order='a961e91944904d22bc5fa45999e3625c' Time='18.10.2013 16:08:46'
                          null
                          not this execution
                          not filled Filled
                          18.10.2013 16:08:46 Entered internal PlaceOrder() method at 18.10.2013 16:08:46: BarsInProgress=0 Action=BuyToCover OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='xMS1a' FromEntrySignal='MS1a'
                          18.10.2013 16:08:46 Ignored PlaceOrder() method at 18.10.2013 16:08:46: Action=BuyToCover OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='xMS1a' FromEntrySignal='MS1a' Reason='SignalName does not have a matching FromEntrySignal to exit'


                          Originally posted by NinjaTrader_ChelseaB View Post
                          Hi tonynt,

                          Add the following print to the beginning of your OnExecution() code and then post the output.

                          Print(execution.ToString());
                          if (exitOrder1a == null)
                          Print("null");
                          if (exitOrder1a != execution.Order)
                          Print("not this execution");
                          if (execution.Order.OrderState == OrderState.Filled)
                          Print("not filled "+execution.Order.OrderState.ToString());

                          Comment


                            #14
                            Hi tonynt,

                            This is interesting...

                            So the execution has the signal name right "xMS1a" but the exitOrder1a variable is null...

                            Execution='9ed297898f0349a99fc6d67897193030' Instrument='NQ 12-13' Account='Sim101' Name='xMS1a' Exchange=Default Price=3345,5 Quantity=1 Market position=Long Commission=0 Order='a961e91944904d22bc5fa45999e3625c' Time='18.10.2013 16:08:46'
                            null
                            not this execution
                            not filled Filled
                            Are you at any point setting exitOrder1a to null?

                            May I have your updated code to test?

                            support[at]ninjatrader[dot] Attn: Chelsea #937239
                            Chelsea B.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Jschmelz, Yesterday, 04:45 PM
                            1 response
                            17 views
                            0 likes
                            Last Post NinjaTrader_Marco  
                            Started by sisenberg, Today, 07:29 AM
                            1 response
                            9 views
                            0 likes
                            Last Post sisenberg  
                            Started by Oceans, Today, 02:22 AM
                            2 responses
                            25 views
                            0 likes
                            Last Post Oceans
                            by Oceans
                             
                            Started by sisenberg, Yesterday, 08:06 PM
                            1 response
                            25 views
                            0 likes
                            Last Post sisenberg  
                            Started by PLeary, Today, 06:25 AM
                            1 response
                            18 views
                            0 likes
                            Last Post NinjaTrader_SergeyS  
                            Working...
                            X