Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Does the OnExecutionUpdate method no exist in the AddOnBase?

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

    Does the OnExecutionUpdate method no exist in the AddOnBase?

    I'm creating a custom add-on, but in the sample I have, this method was available and now it's not. How do I use it?


    Code:
    using NinjaTrader.Cbi;
    using NinjaTrader.NinjaScript;
    using System;
    using System.Linq;
    
    namespace NinjaTrader.NinjaScript.AddOns
    {
        public class OrderReplicatorAddOn : AddOnBase
        {
            private Account masterAccount; // Conta mestre
            private Account followerAccount; // Conta seguidora
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Name = "OrderReplicatorAddOn";
                    Description = "Add-on para replicar ordens entre contas.";
                }
                else if (State == State.Configure)
                {
                    // Configura as contas mestre e seguidora
                    masterAccount = Account.All.FirstOrDefault(a => a.Name == "MasterAccountName");
                    followerAccount = Account.All.FirstOrDefault(a => a.Name == "FollowerAccountName");
    
                    if (masterAccount == null || followerAccount == null)
                    {
                        Log("Conta mestre ou seguidora não encontrada!", LogLevel.Error);
                        return;
                    }
                }
            }
    
            protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
            {
                // Verifica se a execução é da conta mestre
                if (execution.Account == masterAccount)
                {
                    // Replica a execução na conta seguidora
                    switch (execution.Order.OrderState)
                    {
                        case OrderState.Filled:
                            ReplicateOrder(execution);
                            break;
    
                        case OrderState.Cancelled:
                        case OrderState.Rejected:
                            // Fecha a posição na conta seguidora se a ordem for cancelada ou rejeitada na conta mestre
                            followerAccount.Flatten(execution.Order.Instrument);
                            break;
                    }
                }
            }
    
            private void ReplicateOrder(Execution execution)
            {
                // Obtém os detalhes da ordem
                Instrument instrument = execution.Order.Instrument;
                MarketPosition position = execution.Order.MarketPosition;
                int quantity = execution.Order.Quantity;
    
                // Replica a ordem na conta seguidora
                if (position == MarketPosition.Long)
                {
                    followerAccount.CreateMar****rder(instrument, position, quantity);
                }
                else if (position == MarketPosition.Short)
                {
                    followerAccount.CreateMar****rder(instrument, position, quantity);
                }
    
                // Replica stop-loss e take-profit (se existirem)
                if (execution.Order.StopLoss != null)
                {
                    followerAccount.CreateStopMar****rder(instrument, position == MarketPosition.Long ? MarketPosition.Short : MarketPosition.Long, quantity, execution.Order.StopLoss.Price);
                }
    
                if (execution.Order.TakeProfit != null)
                {
                    followerAccount.CreateLimitOrder(instrument, position == MarketPosition.Long ? MarketPosition.Short : MarketPosition.Long, quantity, execution.Order.TakeProfit.Price);
                }
            }
        }
    }​
    None of this stretch of code is working. What changed?

    #2
    Hello gabrielrodrigues,

    OnExecutionUpdate is only for Strategies but you can use ExecutionUpdate which is essentially the same event in addons.

    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    607 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    353 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    560 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    561 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X