Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entry Groups new issue only going forward

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

    Entry Groups new issue only going forward

    Thanks Chelsea. Let's close the discussion on Target orders move since it is solved.

    Now let's go for the Entry Groups new issue only going forward.

    I'm intending to incorporate some LIFO logic into the Entry Groups issue solution.

    The idea would be to have a 1st Hotkey move the 1st latest filled orders Targets,
    then a 2nd hotkey move previous latest filled orders Target an so on.


    For example using a list containing 2 LONG Entries Positions,

    1st LONG Entry Position = 2 contracts/ 2 Orders of 1 contract each

    2nd LONG Entry Position = 3 contracts/ 3 Orders of 1 contract each

    Something like

    hotkey X

    for (int index = ((submitTargetsOrdersList.Count > 0) ?
    submitTargetsOrdersList.Last() : quantitySelector.Value); index > (submitTargetsOrdersList.Last() - 3) ; index--)

    hotkey Y

    for (int index = ((submitTargetsOrdersList.Count > 0) ?
    (submitTargetsOrdersList.Last() - 2) : quantitySelector.Value); index > (submitTargetsOrdersList.Last() - 5) ; index--)


    In post #117 you suggested
    Saving the first set of orders in an Order[] array (if fixed size) or a List<Order> and a second set in another object of the same type would likely work.
    How would you save the 1st, 2nd etc sets of orders counts in variables?

    My idea would be to use those variables as

    Xa = 2 = 1st orders count (1st LONG Entry Position)
    Xb = 3 = 2nd orders count (2nd LONG Entry Position)
    Xn = ? = nth orders count (nth LONG Entry Position)

    in

    After 1st LONG Entry Position = submitTargetsOrdersList.Count = 2

    hotkey X
    for (int index = ((submitTargetsOrdersList.Count > 0) ?
    submitTargetsOrdersList.Last() : quantitySelector.Value); index > (submitTargetsOrdersList.Last() - submitTargetsOrdersList.Count) ; index--)


    After 2nd LONG Entry Position = submitTargetsOrdersList.Count = 5

    hotkey Y
    for (int index = ((submitTargetsOrdersList.Count > 0) ?
    (submitTargetsOrdersList.Last() - Xa) : quantitySelector.Value); index > (submitTargetsOrdersList.Last() - submitTargetsOrdersList.Count) ; index--)

    etc.

    ​​​​​​​Thanks!
    Last edited by PaulMohn; 06-29-2022, 02:05 PM.

    #2
    Hello PaulMohn,

    If this is a new inquiry then start a new thread.

    I have moved your post to a new thread as this is a new inquiry.

    I would not be able to design your custom logic. This thread will remain open for any community members that would like to design your logic as a convenience to you.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.

    In general, you could add the orders you want modified from the first keypress to one collection, and the orders you want modified from the second keypress to another collection. When pressing the first keypress, use a for loop from 0 to less than the collection.Count of the first collection. When pressing the second keypress, loop to the collection.Count of the second collection.

    "How would you save the 1st, 2nd etc sets of orders counts in variables?"

    What does this mean?
    The count comes from the collection you have added the orders to.
    myList.Count is the count of the list.

    Below is a link to the Microsoft Documentation on List.Count.
    https://docs.microsoft.com/en-us/dot...t?view=net-6.0

    If you are not using lists, then you could use an integer as a counter. Each time an order is placed increment the counter. Since the orders are not added to a list, the count would tell you how many orders were placed. If you are using lists, don't use a counter. Use the collection.Count.
    Last edited by NinjaTrader_ChelseaB; 06-29-2022, 02:20 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea for the new thread. I was not asking for custom logic design so please do not infer that.

      What I was asking, not clearly enough, hope it is clear enough with what follows,
      was what way can I access the orders ID or other identifiable element of the order groups in order to then add them in a collection.

      I know how to add elements in a list. But I don't know what to call to get the elements according to the order group.

      What way would you suggest to identify the elements according to the Entry group? Any sample? Any documentation? Thanks!

      If it's still not clear enough please let me know. Thanks!

      Comment


        #4
        Hello PaulMohn,

        Any advanced C# would be up to you.
        I've suggested storing the orders in different List<Order> variables.
        Perhaps you are looking for a dictionary or keyvaluepair?

        The order object has an OrderId property.
        Print(string.Format("OrderId: {0}", order.OrderId));
        https://ninjatrader.com/support/help.../nt8/order.htm

        "What way would you suggest to identify the elements according to the Entry group? Any sample? Any documentation?"
        I would suggest you add the orders that are grouped to a List. Add different groups, to a different list. Refer to the group by the variable name holding the list.
        I would not have any samples.
        Below is a link to the Microsoft documentation on List<T>.
        https://docs.microsoft.com/en-us/dot...1?view=net-6.0
        Last edited by NinjaTrader_ChelseaB; 06-29-2022, 02:50 PM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Ah ok thanks for the counter tip, it seems it would work with capturing the list count upon each order submission at the top of the Hotkeys action blocks.
          I thought you would need to access orders groups IDs or timestamps etc. available with Entry order data but the counter seems the simplest way.
          I'll test tomorrow. Thanks again for the great help!

          just read your latest post, I'll consider that as well if the counter does not work. Thanks!
          Last edited by PaulMohn; 06-29-2022, 03:07 PM.

          Comment


            #6
            Got it working for 2 targets moving Hotkeys (NumPad7 and NumPad8) so far


            Using this looping command

            Click image for larger version  Name:	Multi-Targets Moving From List.png Views:	0 Size:	137.8 KB ID:	1207346

            I'll extend it to 5 more targets asa. Thanks!
            Last edited by PaulMohn; 07-02-2022, 04:15 AM.

            Comment


              #7
              Hello Chelsea,

              I'm trying your method with several lists, as it seems simpler,
              since I've just found out about the
              .Except()
              or .Intersect() uses:
              I have two lists: List A {A, B, C, D} List B {A, E, F, G} I need to produce three lists: One with the items only in list A (B, C, D) One with the items only in list B (E, F, G) One with the ...

              I have 2 lists: list1 and list2 (both of type int) Now I want to remove content of list2 from list1. How I can do this in C#? PS: Don't use loop.


              I'm testing using 2 Sublists, y1 and y2.
              I set it so y1 captures the orders of the 1st Entry group (with a incrementer and a bool doOnce...).
              but the problem is y1 doesn't just capture the 1st Entry Group, instead it keeps adding the new Entry orders.

              I don't know how to get the capture working and can't find an answer online.
              I suspect the problem comes from my State.DataLoaded instances of y1 and y2. But I don't know why.
              Is it the syntax that is wrong? Is y1 = new List<Order>(); telling to keep adding the 2nd Entry orders to y1 inspite the condition
              if (doOncelistCount1stOrdersGroup && (LongEntriesCounter == 1)). Why?


              Why does the list keep incrementing despite the incrementer and a bool doOnce?
              y1
              PHP Code:
              y1 = submitTargetsOrdersList; 
              
              should only capture the orders present in the list at the time the Numpad.Multiply is pressed for the 1st time.
              Then,
              PHP Code:
              y2 = submitTargetsOrdersList.Except(y1).ToList(); 
              
              y2 should just Except the previous orders of the "superlist" (submitTargetsOrdersList), leaving only the 2nd Entries orders in y2.

              I tested printing the count (y1.Count) on 2 entries (1st 2 orders/contracts, 2nd 3 orders/ contracts).
              and it does prints 2 on the 1st entry, but then it prints 5 on the 2nd entry.

              x1 : 2
              x2 : 0
              Buy
              NP7. y1.Count : 2
              x1 : 2
              x2 : 3
              Buy
              NP7. y1.Count : 5
              NP8. y1.Count : 5
              NP8. y2.Count : 0
              Error on triggering custom event for NinjaScript 'ProfitSnipers' on bar 5022: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
              I need it to print 3 on the 2nd entry not 5.
              What am I missing to get the y1 list to capture only the 1st entry orders count? Thanks!

              Below the reduced relevant snippets (if it's clearer also the script is attached):
              PHP Code:
              public class ProfitSnipers : Indicator
              {
                 private List<Order>   submitTargetsOrdersList, submitStopLossesOrdersList, multiOrders, y1, y2;
              
                 private bool   doOncelistCount1stOrdersGroup, doOncelistCount2ndOrdersGroup;
              
                 private int   Orders1stGroupQty, Orders2ndGroupQty;
              
                 private int   LongEntriesCounter, ShortEntriesCounter; 
              
              PHP Code:
              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
                   doOncelistCount1stOrdersGroup = true;
                   doOncelistCount2ndOrdersGroup = true;
              
              else if (State == State.DataLoaded)
              {
              
                 y1 = new List<Order>();
                 y2 = new List<Order>(); 
              
              PHP Code:
                 private async void OnPreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs p)
                 {
                  await ChartControl.Dispatcher.InvokeAsync((Action) (() =>
                  {
                   if (p.Key == Key.Multiply)
                   {
                    ++LongEntriesCounter;
              
                    if (doOncelistCount1stOrdersGroup && (LongEntriesCounter == 1))
                    {
                     Orders1stGroupQty = quantitySelector.Value;
              
                     y1 = submitTargetsOrdersList;
              
              
                     doOncelistCount1stOrdersGroup = false;
                    }
                    else
                    if (doOncelistCount2ndOrdersGroup && (LongEntriesCounter == 2))
                    {
                     Orders2ndGroupQty = quantitySelector.Value;
              
                     y2 = submitTargetsOrdersList.Except(y1).ToList();
              
              
                     doOncelistCount2ndOrdersGroup = false;
                    } 
              

              PHP Code:
              protected void ChartControl_PreviewKeyDown(object sender, KeyEventArgs e)
              {
                   TriggerCustomEvent(TestNumPad7 =>
                   {
                    if (entryBuyMar****rder != null)
                    {
              
                     if (Keyboard.IsKeyDown(Key.NumPad7) && !(Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
                     {
                       Print("NP7. y1.Count : " + y1.Count);
              
              
                      for (int index = 0; index < Orders1stGroupQty; index++)
                      {
                       currentPTPrice = y1[index].LimitPrice + (ProfitTargetMove * TickSize);
                       y1[index].LimitPriceChanged = currentPTPrice;
                      }
              
              
                      myAccount.Change(y1);
                     }
              
                    }
              
              ---------------
              
                   TriggerCustomEvent(TestNumPad8 =>
                   {
                    if (entryBuyMar****rder != null)
                    {
                     if (Keyboard.IsKeyDown(Key.NumPad8) && !(Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
                     {
                      for (int index = 0; index < Orders2ndGroupQty; index++)
                      {
                        Print("NP8. y1.Count : " + y1.Count);
                        Print("NP8. y2.Count : " + y2.Count);
                       currentPTPrice = y2[index].LimitPrice + (ProfitTargetMove * TickSize);
                       y2[index].LimitPriceChanged = currentPTPrice;
                      }
                      myAccount.Change(y2);
              
                     }
                    } 
              

              PHP Code:
                    protected override void OnBarUpdate()
                    {
                      if (myAccount != null && myAccount.Positions.Where(o => o.Instrument == Instrument).Count() > 0)
                        accountPosition = myAccount.Positions.Where(o => o.Instrument == Instrument).Last();
                      else
                        accountPosition = null;
              
                      if (accountPosition == null)
                      {
                                  entryBuyMar****rder     = null;
                        entrySellMar****rder   = null;
              
                                  profitTargetOrder       = null;
                                  stopLossOrder           = null;
              
              
                        multiOrders.Clear();
              
                        submitTargetsOrdersList.Clear();
              
                            submitStopLossesOrdersList.Clear();
              
                        y1.Clear();
                        y2.Clear();
              
                        LongEntriesCounter   = 0;
                        ShortEntriesCounter = 0;
              
                      }
                      else
                      {
              
                      }
                    } 
              
              Attached Files
              Last edited by PaulMohn; 07-05-2022, 05:46 AM.

              Comment


                #8
                Hello PaulMohn,

                This would be advanced C# that is out of the scope of what is documented in the NinjaTrader help guide.
                There can be limitations using advanced C# concepts, in NinjaScript, so your mileage may vary. As of now, we do not have any examples that can be used to navigate that path.

                This thread will remain open for any community members that would like to assist with this advanced C# code.
                I would recommend asking these kind of advanced c# questions on stack overflow.

                I also would recommend you simplify and break it down to a specific step.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                53 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                130 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                70 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                44 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                49 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X