I am trying to have a button that takes an open position that was done manually (charttrader).
but the following error does not appear
| McGEnergyValidation.cs | 'NinjaTrader.Cbi.Position' does not contain a definition for 'AvgPrice' and no extension method 'AvgPrice' accepting a first argument of type 'NinjaTrader.Cbi.Position' could be found (are you missing a using directive or an assembly reference?) | CS1061 | 341 | 56 |
private void MoveToBreakEven()
{
// Obtener el instrumento y la posición actual
string currentInstrument = ChartControl.Instrument.FullName;
Position position = Position; // Obtiene la posición actual del instrumento en la estrategia
Print("Instrumento actual: " + currentInstrument);
Print("Posición: " + position);
if (position != null && position.Quantity > 0)
{
foreach (var order in Orders)
{
if (order.Instrument.FullName == currentInstrument)
{
if (order.OrderType == OrderType.StopMarket || order.OrderType == OrderType.StopLimit)
{
if (order.OrderState != OrderState.Cancelled && order.OrderState != OrderState.Filled)
{
// Cancelar la orden existente
CancelOrder(order);
// Obtener el precio promedio de la posición
double averagePrice = position.AvgPrice; // Usa AvgPrice
// Crear una nueva orden de Stop con el precio promedio
if (position.MarketPosition == MarketPosition.Short)
{
SubmitOrder(0, OrderAction.BuyToCover, OrderType.StopMarket, position.Quantity, averagePrice, 0, "BreakEven", "BreakEvenSignal");
}
else if (position.MarketPosition == MarketPosition.Long)
{
SubmitOrder(0, OrderAction.Sell, OrderType.StopMarket, position.Quantity, averagePrice, 0, "BreakEven", "BreakEvenSignal");
}
}
}
}
}
}
else
{
Print("No se encontró posición para el instrumento actual o la posición está vacía.");
}
}
private void SubmitOrder(int barsAgo, OrderAction action, OrderType orderType, double quantity, double limitPrice, double stopPrice, string signalName, string orderTag)
{
// Enviar la orden
SubmitOrder(barsAgo, action, orderType, quantity, limitPrice, stopPrice, signalName, orderTag);
}

Tk, but It doesn't read the open position I have from the charttrader
Comment