Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Why multiple orders are generated

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

    Why multiple orders are generated

    Hi,

    In my strategy I enter a long position if my signal is valid. Sample code is as below.

    Code:
    if(position.MarketPosition == MarketPosition.Flat)
    {
     	if(High[0] > _longSignal){
    	  EnterLong(BarsInProgress, data.Quantity, _signalName);
       	  SetStopLoss(CalculationMode.Price, buyStop);
              Print(string.Format("{0} Long Entry: T:{0},H:{1}", this.Instrument.FullName, Time[0], High[0]);
           }
    }
    In output window I see the above message generated multiple times in consecutive 5 min bars. My understanding is that, once I EnterLong (this is a market order?), the position should not be Flat in my next bar update. (5 min bar update). Why do I see multiple print messages of Long Entry and consecutive bar updates.
    It looks like Market position remains Flat.

    #2
    Hello toughgetsgoing,

    Print the market position outside of that condition.
    What is the market position on the bars after the order is placed?

    Is the order being filled?
    (Turn on TraceOrders)

    Do you have multiple series added to your script?
    Which series is being checked?
    Which series is the order placed to?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      yes, I have multiple series added. It's a multiple instrument strategy so I add 5 minute bars series for each instruments.
      I have changed my code from EnterLong(BarsInProgress, data.Quantity, _signalName); to EnterLong(data.Quantity, _signalName); and I am going to test this again. This change shouldn't have any impact, but my understanding is that the BarsInProgress should point to the correct instrument in question (this.Instrument) and hence I shouldn't have to specify BarsInProgress.

      I ran 6 months backtest and I couldn't reproduce the same issue. (yesterday's run was 5 years). I will run 5 years backtest later tonight and post the results of trace orders tomorrow.

      But today's 6 months result had another issue which I am not sure about. Can you please confirm whether EnteriesPerDirection (Value is 1) is set for each instrument separately or it is set across all instruments? Please note that I am specifying instrument name in the signal so entry signal is unique for each instrument. If you check the logs below, 3rd order entry on 3/11/2017 on CL 09-17 has Error message as below.

      Ignored SubmitOrderManaged() method at 3/11/2017 2:00:00 AM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=45 LimitPrice=0 StopPrice=0 SignalName='CL 09-17 S-1 Short Entry' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'

      Why has this occurred since this was the first ever order on CL 09-17 and no other order was entered before this. (Previous orders being GC 05-17 and TF 06-17)

      EDIT:
      When I was looking at the log after submitting I realized that the value of FromEntrySignal is not set. (value is ''). Is this the value used to identify signal and since this value is same for TF short and CL short and hence CL short is ignored since TF short already has an entry for this signal? If yes, this how can I specify Entries per signal to match 1 for each instrument (each series)?

      EDIT 2: Problem was resolved when I set Entries Per Direction to number of instruments trading in my strategy. How Can I set FromEntrySignal ?

      Please see 6 months strategy log here:


      Code:
      Strategy Loaded
      From Date 1/3/2017 7:05:00 AM, To Date: 6/20/2017 5:00:00 AM
      
      1/10/2017 10:55:00 PM Strategy 'GeninMission01/-1': Entered internal SubmitOrderManaged() method at 1/10/2017 10:55:00 PM: BarsInProgress=2 Action=Buy OrderType=Market Quantity=2 LimitPrice=0 StopPrice=0 SignalName='GC 05-17 S-1 Long Entry' FromEntrySignal=''
      1/10/2017 10:55:00 PM Strategy 'GeninMission01/-1': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='GC 05-17 S-1 Long Entry stop loss' Mode=Price Value=1161.74 IsSimulatedStop=True IsMarketIfTouched=False
      [B]GC 05-17 S-1 Long Entry[/B]: T:1/10/2017 10:55:00 PM,H:1193.4,S1LEntry:1193.4,C:1192.4,buyStop:1161.74
       
      1/20/2017 3:20:00 AM Strategy 'GeninMission01/-1': Entered internal SubmitOrderManaged() method at 1/20/2017 3:20:00 AM: BarsInProgress=4 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='TF 06-17 S-1 Short Entry' FromEntrySignal=''
      1/20/2017 3:20:00 AM Strategy 'GeninMission01/-1': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='TF 06-17 S-1 Short Entry stop loss' Mode=Price Value=1375.47 IsSimulatedStop=True IsMarketIfTouched=False
      [B]TF 06-17 S-1 Short Entry[/B]: T:1/20/2017 3:20:00 AM,L:1338.8,S1SEntry:1338.8,C:1339.7,sellStop:1375.47
      
      3/11/2017 2:00:00 AM Strategy 'GeninMission01/-1': Entered internal SubmitOrderManaged() method at 3/11/2017 2:00:00 AM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=45 LimitPrice=0 StopPrice=0 SignalName='CL 09-17 S-1 Short Entry' FromEntrySignal=''
      3/11/2017 2:00:00 AM Strategy 'GeninMission01/-1': Ignored SubmitOrderManaged() method at 3/11/2017 2:00:00 AM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=45 LimitPrice=0 StopPrice=0 SignalName='CL 09-17 S-1 Short Entry' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
      3/11/2017 2:00:00 AM Strategy 'GeninMission01/-1': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='CL 09-17 S-1 Short Entry stop loss' Mode=Price Value=52.275 IsSimulatedStop=True IsMarketIfTouched=False
      [B]CL 09-17 S-1 Short Entry[/B]: T:3/11/2017 2:00:00 AM,L:49.87,S1SEntry:49.87,C:49.97,sellStop:52.275
      
      3/14/2017 11:15:00 PM Strategy 'GeninMission01/-1': Entered internal SubmitOrderManaged() method at 3/14/2017 11:15:00 PM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=45 LimitPrice=0 StopPrice=0 SignalName='CL 09-17 S-1 Short Entry' FromEntrySignal=''
      3/14/2017 11:15:00 PM Strategy 'GeninMission01/-1': Ignored SubmitOrderManaged() method at 3/14/2017 11:15:00 PM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=45 LimitPrice=0 StopPrice=0 SignalName='CL 09-17 S-1 Short Entry' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
      3/14/2017 11:15:00 PM Strategy 'GeninMission01/-1': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='CL 09-17 S-1 Short Entry stop loss' Mode=Price Value=51.049 IsSimulatedStop=True IsMarketIfTouched=False
      [B]CL 09-17 S-1 Short Entry[/B]: T:3/14/2017 11:15:00 PM,L:48.65,S1SEntry:48.65,C:48.7,sellStop:51.049
      
      6/8/2017 9:00:00 PM Strategy 'GeninMission01/-1': Entered internal SubmitOrderManaged() method at 6/8/2017 9:00:00 PM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=45 LimitPrice=0 StopPrice=0 SignalName='CL 09-17 S-1 Short Entry' FromEntrySignal=''
      6/8/2017 9:00:00 PM Strategy 'GeninMission01/-1': Ignored SubmitOrderManaged() method at 6/8/2017 9:00:00 PM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=45 LimitPrice=0 StopPrice=0 SignalName='CL 09-17 S-1 Short Entry' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
      6/8/2017 9:00:00 PM Strategy 'GeninMission01/-1': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='CL 09-17 S-1 Short Entry stop loss' Mode=Price Value=48.468 IsSimulatedStop=True IsMarketIfTouched=False
      [B]CL 09-17 S-1 Short Entry[/B]: T:6/8/2017 9:00:00 PM,L:45.41,S1SEntry:45.41,C:45.5,sellStop:48.468
      Strategy Finished
      Last edited by toughgetsgoing; 07-03-2017, 09:02 AM. Reason: additional questions

      Comment


        #4
        Hi Chelsea,

        Just to make sure my understanding is correct, Can you confirm if below logic to enter, add stop loss and exit correct for multiple instrument strategy? I am putting only partial code for long signal only. My question is from the point of view that there are multiple orders in the market, multiple live positions and fromEntrySignal is not set (is empty for all signals/instruments). Is my understanding correct that below exits/stop losses will not interfere in other instruments orders. (this question came in mind because Entries Per direction was impacting orders on other instruments)

        Code:
        if(position.MarketPosition == MarketPosition.Flat)
        {
        	_signalName = string.Format("{0} Long Entry", this.Instrument.FullName);
        	EnterLong(data.Quantity, _signalName);
        	SetStopLoss(_signalName + " stop loss"  , CalculationMode.Price, buyStop, true);
        } 
        else if(position.MarketPosition == MarketPosition.Long) 
        {
        	ExitLong();
        }

        Comment


          #5
          Hello toughgetsgoing,

          If you don't have a condition to specify which bars in progress to do this check on, then the position will be checked for all series as each series triggers OnBarUpdate.

          EnteriesPerDirection is for the entire strategy and is not specific to positions for individual instruments.

          If you wanted these per instrument, i would suggest using signal names that are unique to the instrument for the entry and set EntryHandling to .UniqueEntries.

          EnterLong("longEntry"+Instrument.FullName);

          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hi Chelsea,

            If you see the log attached in my previous post, you will see that I am specifying instrument name in the signal name but still the short CL order was ignored with error Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties' Can you please advise why is this the case?
            I am Entering the short positions using code EnterShort(BarsInProgress, Quantity, "CL 09-17 S-1 Short Entry" )

            Additionally I know how to set SignalName in EnterShort function But I do not know how to set fromEntrySignal when i initiate a position.

            What do you mean this statement here?
            If you don't have a condition to specify which bars in progress to do this check on, then the position will be checked for all series as each series triggers OnBarUpdate.

            I expect to get OnBarUpdate for each instrument series that I have added and act on them individually. If I do EnterLong in OnBarUpdate then the long position will be entered for the instrument corresponding to that series only (BarsInProgress) and not for others.
            Last edited by toughgetsgoing; 07-04-2017, 09:12 AM.

            Comment


              #7
              Hello toughgetsgoing,

              What is EntryHandling set to in the script?
              What is EntriesPerDirection set to in the script?

              The fromEntrySignal is for exit orders like SetStopLoss or ExitLongLimit. This needs to match the signalName used for the entry.
              Understand the fundamentals of basic strategy creation by developing an actual strategy using the NinjaTrader Strategy Builder.2:45 Opening a Strategy Builde...


              When placing an order without specifying a BarsInProgress index, yes it will be placed to the currently processing series.

              However, I am stating that if you are checking the position and you are doing this as every series is processed without any check for BarsInProgress then the position will be checked for each series (some will have positions some will not).
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                I have below settings in my strategy

                Code:
                EntriesPerDirection							= _instruments.Length;  // total number of instruments
                EntryHandling								= EntryHandling.AllEntries;
                Yes, the behavior you explained is what i am expecting. each instrument will trade on bar update depending on its signal.

                I have a confusion between SignalName vs fromEntrySignal.

                I am setting SignalName in my EnterLong function and in the order trace log I see the Signal Name is correctly set what I am expecting but FromEntrySignal is Empty. It looks like SignalName and FromEntrySignal are 2 separate fields.

                Here is the order log:

                6/8/2017 9:00:00 PM Strategy 'GeninMission01/-1': Entered internal SubmitOrderManaged() method at 6/8/2017 9:00:00 PM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=45 LimitPrice=0 StopPrice=0 SignalName='CL 09-17 S-1 Short Entry' FromEntrySignal=''

                I know how to set SignalName in EnterLong function but I don't know how to set FromEntrySignal When i enter into a position. please advise.

                Comment


                  #9
                  Hello toughgetsgoing,

                  Because you are using EntryHandling.AllEntries the signal names will not be used for entry handling. The signal names are only used with EntryHandling.UniqueEntries.

                  What is the value of _instruments.Length?

                  Print this to ensure it is the expected value.


                  With the signalName this is used for the EnterLong() call.
                  EnterLong(int barsInProgressIndex, int quantity, string signalName)


                  There is no parameter for the fromEntrySignal as these are only used for the exit order to tie this to an entry order.

                  ExitLong(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal)


                  For example

                  EntryHandling = EntryHandling.UniqueEntries;

                  if (Position.MarketPosition == MarketPosition.Flat)
                  {
                  EnterLong(0, 1, "longEntry1");
                  EnterLong(0, 2, "longEntry2");
                  }
                  else
                  {
                  ExitLong(0, 1, "longExit1", "longEntry1");
                  }

                  With this example, two entries will be placed with unique signalNames longEntry1 and longEntry2.
                  Then only one of those trades will be exited. The trade that entered with longEntry1 will be exited by an exit order named longExit1. The trade entered with longEntry2 will not be exited.
                  Chelsea B.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by frankthearm, Today, 09:08 AM
                  5 responses
                  14 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  3 responses
                  43 views
                  0 likes
                  Last Post jeronymite  
                  Started by yertle, Today, 08:38 AM
                  5 responses
                  15 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by adeelshahzad, Today, 03:54 AM
                  3 responses
                  19 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by bill2023, Yesterday, 08:51 AM
                  6 responses
                  27 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Working...
                  X