Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling EnterLong() in Loop

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

    Calling EnterLong() in Loop

    Hi,
    I am trying to build my strategy code with managed approach by accepting quantity per each lot and number of lots, I need set different profit targets within each lot based on the quantity per lot.
    When I try to enter the order using for loop, I am getting below error on the second iteration of the loop.
    "**NT** Error on calling 'OnBarUpdate' method for strategy 'GZonesSt1/0d31c7eca40f4f6eb47543d8f76ac776': Object reference not set to an instance of an object."

    Can we use the EnterLong() in the loop with different entry signal name?
    Can you please check below code which is throwing error on second iteration?
    Can you please suggest me any workaround for this issue? am i missing any thing in the EnterLong?

    Sample Test Code:
    Variables section:
    private int lots=1;
    private int qty=4;
    private IOrder longOrder1 = null;
    private IOrder shortOrder1 = null;
    private List<IOrder> longOrder = new List<IOrder>(6);
    private List<IOrder> shortOrder = new List<IOrder>(6);

    OnBarUpdate() Section:
    Print(CurrentBar+" "+Time[0]+" LONG Order Entry , QTY "+qty+" , Lots, "+lots);
    for (int i=0; i < qty;i++)
    {
    longOrder1=null;
    Print("AA "+i);
    longOrder1=EnterLong(lots,"L"+i);
    Print("BB "+i+" ");
    Print("BB "+i+" "+longOrder1.Name); // getting error on second iteration
    longOrder.Add(longOrder1);
    Print("CC "+i);
    Print(CurrentBar+" "+Time[0]+" LONG Order Name longOrder1 = "+longOrder1.Name+" ,longOrder["+i+"] : "+longOrder[i].Name);
    }

    OutPut:
    939 9/24/2012 6:51:00 AM LONG Order Entry , QTY 4 , Lots, 1
    AA 0
    BB 0
    BB 0 L0
    CC 0
    939 9/24/2012 6:51:00 AM LONG Order Name longOrder1 = L0 ,longOrder[0] : L0
    AA 1
    BB 1
    **NT** Error on calling 'OnBarUpdate' method for strategy 'GZonesSt1/0d31c7eca40f4f6eb47543d8f76ac776': Object reference not set to an instance of an object.

    thanks,
    GSREDDY

    #2
    Hi,

    i am able to clear my code related issue by placing the below statements in initialize method.

    //TraceOrders=true;
    EntriesPerDirection = qty;
    EntryHandling = EntryHandling.UniqueEntries;

    thanks
    GSREDDY

    Comment


      #3
      Hello gsreddy,
      Glad to know you could resolve the scenario.

      Please let me know if I can assist you any further.
      JoydeepNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      649 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      370 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      109 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      574 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      576 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X