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

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.FromEntrySignalcount++;
                  }
                  
                  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.FromEntrySignal);

                      foreach (var 
      g in OrderGroups)
                      {
                          if (
      lastOrder.FromEntrySignal == g.Key)
                          {
                              if (
      g.Count() >= maxUniqueEntriesPerDirection)
                                  
      true;
                              else
                                  
      false;
                          }
                      }
                  }

                  return 
      u;
                          
              } 
      Last edited by cutzpr; 09-30-2018, 10:51 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Gerik, Today, 09:40 AM
      2 responses
      6 views
      0 likes
      Last Post Gerik
      by Gerik
       
      Started by RookieTrader, Today, 09:37 AM
      2 responses
      10 views
      0 likes
      Last Post RookieTrader  
      Started by alifarahani, Today, 09:40 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by KennyK, 05-29-2017, 02:02 AM
      3 responses
      1,285 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by AttiM, 02-14-2024, 05:20 PM
      11 responses
      186 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X