Below is my current code and a screenshot. As can be seen in the screenshot, only the first EnterLong (P1) is triggered. When looking in the logs, I can't find any mention on the second order "P2".
Please let me know if I am missing something.
Thank you
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class MultipleOrderStrategy : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = “Multiple”OrderStrategy;
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.UniqueEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 30;
IsInstantiatedOnEachOptimizationIteration = true;
}
}
private bool inLongTrade;
private bool isTargetMoved;
private float entryPrice;
protected override void OnBarUpdate() {
if (CurrentBar < BarsRequiredToTrade) {
return;
}
Print(string.Format("Market Position: {0}",Position.MarketPosition));
//if (Position.MarketPosition == MarketPosition.Flat && Close[2] > Close[1]) {
if(Close[2] > Close[1]) {
Print("Entering a Long Position");
SetStopLoss(CalculationMode.Ticks, 40);
entryPrice = (float) Close[0];
SetProfitTarget("P1", CalculationMode.Ticks, 40);
SetProfitTarget("P2", CalculationMode.Ticks, 80);
SetStopLoss(CalculationMode.Ticks, 40);
EnterLong("P1");
EnterLong("P2");
isTargetMoved = false;
}
}
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
{
if (execution.Order.OrderState == OrderState.Filled) {
if (execution.Order.Name == "P1" && !isTargetMoved) {
SetStopLoss(CalculationMode.Price, entryPrice);
SetProfitTarget("P2", CalculationMode.Price, entryPrice + 100);
isTargetMoved = true;
}
}
}
}
}

Comment