i set in "OnBarUpdate" a variable and want this use as my Stoploss in OnExecutionUpdate. Playback & SimTrades works fine, but Realtime i became following situation (Stoploss is always 0)
OnBarUpdate i set my Currentstop like this
if (isNQMomentumTradingAllowed && Position.MarketPosition == MarketPosition.Flat)
{
if( (SignaleNQ.Setup0123MomentumLongBlue[0] || SignaleNQ.Setup0123MomentumLongGreen[0] || SignaleNQ.Setup0123MomentumLongBlack[0] || SignaleNQ.Setup0123MomentumLongYellow[0]) && Button_Long )
{
ProfitDistance1 = 28; ProfitDistance2 = 32; ProfitDistance3 = 32; EntryDistance = 0; TrailStopDistance = 18; TrailStopBegin = 18;
ProfitTargetPrice1 = High[1] + (ProfitDistance1 * TickSize); ProfitTargetPrice2 = High[1] + (ProfitDistance2 * TickSize); ProfitTargetPrice3 = High[1] + (ProfitDistance3 * TickSize);
CurrentTriggerPrice = High[1] + (TrailStopBegin * TickSize); CurrentStopPrice = Low[1] - (1 * TickSize); AbsicherungsSL = Close[1];
Print("SetupLong " + CurrentTriggerPrice + " " + CurrentStopPrice+ " H " + High[1] + " L " + Low[1]);
if (isNQMomentumTradingeinfachALL) { BuyLong(); }
else if (isNQMomentumTradingeinfachab1 && SignaleNQ.momzaehlung[0] == -1) { BuyLong(); }
else if (isNQMomentumTradingeinfachab2 && SignaleNQ.isTradingSerie[0]) { BuyLong(); }
else if (isNQMomentumTradingeinfachab3 && SignaleNQ.momzaehlung[0] == -3) { BuyLong(); }
}
else if ( (SignaleNQ.Setup0123MomentumShortBlue[0] || SignaleNQ.Setup0123MomentumShortRed[0] || SignaleNQ.Setup0123MomentumShortBlack[0] || SignaleNQ.Setup0123MomentumShortYellow[0]) && Button_Short )
{
ProfitDistance1 = 28; ProfitDistance2 = 32; ProfitDistance3 = 32; EntryDistance = 0; TrailStopDistance = 18; TrailStopBegin = 18;
ProfitTargetPrice1 = Low[1] - (ProfitDistance1 * TickSize); ProfitTargetPrice2 = Low[1] - (ProfitDistance2 * TickSize); ProfitTargetPrice3 = Low[1] - (ProfitDistance3 * TickSize);
CurrentTriggerPrice = Low[1] - (TrailStopBegin * TickSize); CurrentStopPrice = High[1] + (1 * TickSize); AbsicherungsSL = Close[1];
Print("SetupShort " + CurrentTriggerPrice + " " + CurrentStopPrice+ " H " + High[1] + " L " + Low[1]);
if (isNQMomentumTradingeinfachALL) { BuyShort(); }
else if (isNQMomentumTradingeinfachab1 && SignaleNQ.momzaehlung[0] == -1) { BuyShort(); }
else if (isNQMomentumTradingeinfachab2 && SignaleNQ.isTradingSerie[0]) { BuyShort(); }
else if (isNQMomentumTradingeinfachab3 && SignaleNQ.momzaehlung[0] == -3) { BuyShort(); }
}
}
if (longEntry != null && longEntry == execution.Order)
{
Print("OnExecutionUpdate1 " + CurrentTriggerPrice + " " + CurrentStopPrice+ " H " + High[1] + " L " + Low[1]);
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
// We sum the quantities of each execution making up the entry order
sumFilledLong += execution.Quantity;
if (State == State.Historical)
oco = DateTime.Now.ToString() + CurrentBar + "LongExits";
else
oco = GetAtmStrategyUniqueId() + "LongExits";
Print("OnExecutionUpdate2 " + CurrentTriggerPrice + " " + CurrentStopPrice+ " H " + High[1] + " L " + Low[1]);
if (stopLossLong == null && targetLong == null )
{
// CurrentTriggerPrice = (Close[0] + (TrailStopBegin * TickSize)) ;
SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.StopMarket, KaufMengeoco, 0, CurrentStopPrice, oco, "StopLossLong");
SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.Limit, KaufMengeoco, ProfitTargetPrice1, 0, oco, "TargetLong");
}
else
{
// Submit exit orders for partial fills
if (execution.Order.OrderState == OrderState.PartFilled)
{
ChangeOrder(stopLossLong, KaufMengeoco, 0, CurrentStopPrice);
ChangeOrder(targetLong, KaufMengeoco, ProfitTargetPrice1, 0);
}
// Update our exit order quantities once orderstate turns to filled and we have seen execution quantities match order quantities
else if (execution.Order.OrderState == OrderState.Filled && sumFilledLong == execution.Order.Filled)
{
//Stop-Loss order for OrderState.Filled
ChangeOrder(stopLossLong, KaufMengeoco, 0, CurrentStopPrice);
ChangeOrder(targetLong, KaufMengeoco, ProfitTargetPrice1, 0);
}
}
// Resets the entryOrder object and the sumFilled counter to null / 0 after the order has been filled
if (execution.Order.OrderState != OrderState.PartFilled && sumFilledLong == execution.Order.Filled)
{
longEntry = null;
sumFilledLong = 0;
}
}
}

Comment