I would like to know if this is the right way to manage trades and track losing ones.
protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price,
int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time)
{
if (execution.Order != null && execution.Order.OrderState == Cbi.OrderState.Filled)
{
// Check if the trade was a loser
if (GetAtmStrategyRealizedProfitLoss(atmStrategyId)< 0)
{
losingTrades++;
if (losingTrades >= 1)
{
canTrade = false; // Prevent further trading in this event
}
}
}
}
This is one of the events
if (orderId.Length == 0 && atmStrategyId.Length == 0 && isPreviousBarBullish ) { canTrade = true; hadALosingTrade = false; }
if (canTrade && ...) { isAtmStrategyCreated = false; // reset atm strategy created check to false atmStrategyId = GetAtmStrategyUniqueId(); orderId = GetAtmStrategyUniqueId(); AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "3 Posistion BreakEvenCheckNQ", atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => { //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId) isAtmStrategyCreated = true; }); canTrade =!hadALosingTrade; }
Comment