Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Mimic Entry Handling in Unmanaged Strategy

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

    Mimic Entry Handling in Unmanaged Strategy

    How would I mimic Entry Handling in an Unmanged Strategy? Both all entries and unique entries?

    #2
    Hello cutzpr,

    This tracking would need to be accomplished with the logic of your script.

    If you were tracking a single entry, you could look for the position to be flat to allow any new entries.
    Or you could use a counter that increments on each (complete) entry order fill and decrements when an exit order fills.

    If you are wanting multiple entries based on the signal name and logic to allow up to a set number of entries for each signal name, you would need custom logic to store this information. You might use a dictionary of ints used as counters where the key is the signal name. This would make one entry per signal name that tracks the number of entries for that signal name.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I know there are several ways to go about it, this is what I figured. I am posting here to help anyone else that may find it useful

      PHP Code:
      
      Order lastOrder;
      
       protected override void OnOrderUpdate(...)
      {
      lastOrder = order;
      }
          
      
              public bool MaxPositionSizeMet()
              {
                  if(IsFlat()) return false;
                  else if (Position.Quantity >= this.maxPositions)
                  {
                  return true;
                  }
                  else return false;    
              }
              
              
              public bool MaxEntriesPerDirectionMet()
              {
                  
                  OpenOrders.Add(lastOrder);
                  int count = 0;
      
                  if(IsFlat())
                  {
                  OpenOrders.Clear();
                  count = 0;
                  return false;
                  }
      
      
                  //For Max Entries for All Entries----------
                  foreach(Order o in OpenOrders)
                  {
                      if(o.FromEntrySignal == lastOrder.FromEntrySignal) count++;
                  }
                  
                  if (count >= maxEntriesPerDirection) return true;
                  else return false;
                  //----------------------------------------
                  
      
              }
              
      public bool zMaxUniqueEntriesMet()
              {
                  OpenOrders.Add(lastOrder);
                  bool u = false;
                  
                  if(zIsFlat())
                  {
                  OpenOrders.Clear();
                  return false;
                  }
      
                  if (OpenOrders.Any())
                  {
                      var OrderGroups = OpenOrders.GroupBy(x => x.FromEntrySignal);
      
                      foreach (var g in OrderGroups)
                      {
                          if (lastOrder.FromEntrySignal == g.Key)
                          {
                              if (g.Count() >= maxUniqueEntriesPerDirection)
                                  u = true;
                              else
                                  u = false;
                          }
                      }
                  }
      
                  return u;
                          
              } 
      
      Last edited by cutzpr; 09-30-2018, 10:51 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      21 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Working...
      X