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

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>   submitTargetsOrdersListsubmitStopLossesOrdersListmultiOrdersy1y2;

       private 
    bool   doOncelistCount1stOrdersGroupdoOncelistCount2ndOrdersGroup;

       private 
    int   Orders1stGroupQtyOrders2ndGroupQty;

       private 
    int   LongEntriesCounterShortEntriesCounter
    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 senderSystem.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 senderKeyEventArgs 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 0index Orders1stGroupQtyindex++)
            {
             
    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 0index Orders2ndGroupQtyindex++)
            {
              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.Instrument == Instrument).Count() > 0)
              
    accountPosition myAccount.Positions.Where(=> 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.

    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by gravdigaz6, Today, 11:40 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by MarianApalaghiei, Today, 10:49 PM
    3 responses
    10 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by XXtrader, Today, 11:30 PM
    0 responses
    4 views
    0 likes
    Last Post XXtrader  
    Started by love2code2trade, Yesterday, 01:45 PM
    4 responses
    28 views
    0 likes
    Last Post love2code2trade  
    Started by funk10101, Today, 09:43 PM
    0 responses
    9 views
    0 likes
    Last Post funk10101  
    Working...
    X