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

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 elirion, Yesterday, 09:32 PM
      1 response
      13 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by ldanenberg, Yesterday, 03:19 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by tkaboris, Today, 06:27 AM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_RyanS  
      Started by Option Whisperer, Yesterday, 07:58 PM
      5 responses
      22 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by BackToTheFutures, 08-17-2021, 03:15 PM
      9 responses
      733 views
      0 likes
      Last Post NinjaTrader_RyanS  
      Working...
      X