Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to capture a list in a bool flag trap

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

    how to capture a list in a bool flag trap

    Chelsea seems to be out of the office today so I post in general thread this question

    I succeeded to trap an int in bool flags (x1 and x2 below) but I've a hard time doing the same with orders from sublists.

    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:47 AM.

    #2
    Hello PaulMohn,

    If you have a previous post for the same question please refer back to that and wait for a reply. We can't dedicate resources to double reply to duplicate questions so please contain your posts into a single thread when possible.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    647 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    368 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    571 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X