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
Comment