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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X