Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Support with an method error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Support with an method error

    Hello everyone! Sorry for my english but I will do my best.
    I am trying to code an strategy for a long time and it has been working well. however, I have a new challenge. I would like to include trailing stop and breakeven properties ir oder to optimize my results.

    When I compile my code, the result is an error in OnOrderUpdate method. The specific error is: no suitable method found to override. I share fragments of my code below. Please if someone has an idea to fix it, I will really aprreciate to help me.



    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    if (Position.MarketPosition == MarketPosition.Flat)
    {
    if ((Close[1] < Bollinger1[1])
    ...
    {
    double targetPrice = Close[1] + Target * TickSize - Desplazamiento * TickSize;
    double stopPrice = Close[1] - Desplazamiento * TickSize - Stop * TickSize;
    entryPrice = Close[1];

    entryOrder = EnterLongLimit(10, GetCurrentAsk() - Desplazamiento * TickSize, "Long");

    stopOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, 10, 0, stopPrice, "Stop", "LongStop");
    targetOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, 10, targetPrice, 0, "Target", "LongTarget");
    }
    }
    else if (Position.MarketPosition == MarketPosition.Long)
    {
    double currentProfit = (Close[0] - entryPrice) / TickSize;

    // Implementar lógica de breakeven
    if (currentProfit >= BreakevenTrigger)
    {
    CancelOrder(stopOrder);
    stopOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, 10, 0, entryPrice, "BreakevenStop", "LongStop");
    }

    // Implementar lógica de trailing stop
    if (currentProfit >= TrailingStopTrigger)
    {
    double newStopPrice = Close[0] - TrailingStopDistance * TickSize;
    if (newStopPrice > entryPrice)
    {
    CancelOrder(stopOrder);
    stopOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, 10, 0, newStopPrice, "TrailStop", "LongStop");
    }
    }
    }
    }

    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, double filled, double averageFillPrice, OrderState orderState, DateTime time)
    {
    if (order.OrderState == OrderState.Filled)
    {
    if (order.Name == "Long")
    {
    entryPrice = order.AverageFillPrice;
    }
    else if (order.Name == "LongStop" || order.Name == "LongTarget")
    {
    entryOrder = null;
    stopOrder = null;
    targetOrder = null;
    }
    }
    }

    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 == "LongStop" || execution.Order.Name == "LongTarget")
    {
    entryOrder = null;
    stopOrder = null;
    targetOrder = null;
    }
    }
    }

    }

    #2
    Hello nelson0715,

    The overrides you posted have incorrect parameters, you need to copy exactly how it is shown in the help guide with all parameters. The two overrides look like this:

    Code:
    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)
    {
    
    }​
    
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    
    }


    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    47 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    141 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    160 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    96 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    275 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X