GOAL:
My goal is to build pyramid trade entry logic such that the more a trade goes in my favor, as certain prices cross, a new entry order is executed.
APPROACH:
I have an original order I used a simple EnterLongLimit and use the SetStoppLoss and SetProfitTarget as you'll see in the attached code snippet.
Using a long as an example:
From reading this forum, I've understood that using a EnterLongStopLimit and setting my stop price and limit price is a way to achieve my entry logic, when prices crosses the stop price, submit a limit order for my entry. This appears to be working well in the code provided for the "Buy SLM" part. If price crosses, it will indeed execute the Buy SLM order.
For each of those EnterStopLongLimit orders I have associated setStopLoss and setProfitTarget orders with the appropriate signal name.
ISSUE:
The issue I have is those associated setStopLoss and SetProfitTarget orders are being cancelled for some reason, so that when a pyramid entry executes we get the new position but no new target/stop orders.
I've tried looking into isLiveUntilCancelled, but not sure how to use it, or if even possible for these order types.
Can you please advise how I might achieve my requirements? Thanks!
Attached is a sample log of a single trade setup that executes, places the orders, but then shows the cancellations.
Code Snippet for pyramid logic:
// Pyramid Logic Function
private void ExecutePyramidLong(double entryPrice, double stopPrice, int contractsToTrade, double targetPrice, double rr)
Print("Target RR: " + rr); //Debug statement
for (int i = 1; i <= rr; i++) // Loop from 1x to target RR
{
double pyramidStopPrice = pyramidEntryPrice - stopSize ; // Stop price for the pyramid trade (new entry - stop size)
// Set stop loss and profit target for the pyramid trade
SetProfitTarget(pyramidSignalName, CalculationMode.Price, targetPrice);
// Enter the pyramid long trade using EnterLongStopLimit
// Debug print statements
}

Comment