I am running logic on OnBarUpdate
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 2)
return;
// Set 1
if ((High[1] <= High[2])
&& (Low[1] >= Low[2])
&& (IsFirstTickOfBar == true))
{
Print(@"Order Placed");
placeOrder = true;
and have a bool "placeorder" set to false at definition
private bool placeOrder = false;
private SessionIterator sessionIterator;
which becomes true after an inside bar. When I run the logic portion of this on Sttrategy Builder it runs as expected.
The problem is when I run this pasted into the OCO order management example, It places an order immediately and
prints placeorder as true even though that portion of code has not yet run. This the portion of code that is giving me the
if (longStopEntry == null
&& shortStopEntry == null
&& (placeOrder == true))
{
// generate a unique oco string based on the time
// oco means that when one entry fills, the other entry is automatically cancelled
// in OnExecution we will protect these orders with our version of a stop loss and profit target when one of the entry orders fills
ocoString = string.Format("unmanagedentryoco{0}", DateTime.Now.ToString("hhmmssffff"));
longStopEntry = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.StopMarket, 1, 0, (High[0] + TickOffset * TickSize), ocoString, "longStopEntry");
shortStopEntry = SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.StopMarket, 1, 0, (Low[0] - TickOffset * TickSize), ocoString, "shortStopEntry");
Print(Convert.ToString(placeOrder));
placeOrder = false;
Later in the process, an actual bar will show up and I get the "order placed" output as expected from the OnBarUpdate() .
How is that bool getting set to true from the start when I set it to false and the code to change it has not run?
Comment