Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy running against IB not firing OnBarUpdate?

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

    Strategy running against IB not firing OnBarUpdate?

    I am trying to run a simple strategy to test a strategy running against an IB connection. The real time bars are painting on the chart, but OnBarUpdate is not firing.

    Code:

    Code:
        public class PrintingStrategy : Strategy
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Just used to print stuff";
                    Name                                        = "PrintingStrategy";
                    Calculate                                    = Calculate.OnBarClose;
                    EntriesPerDirection                            = 1;
                    EntryHandling                                = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy                = true;
                    ExitOnSessionCloseSeconds                    = 30;
                    IsFillLimitOnTouch                            = false;
                    MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                    OrderFillResolution                            = OrderFillResolution.Standard;
                    Slippage                                    = 0;
                    StartBehavior                                = StartBehavior.WaitUntilFlat;
                    TimeInForce                                    = TimeInForce.Gtc;
                    TraceOrders                                    = false;
                    RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                    StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                    BarsRequiredToTrade                            = 20;
                    // Disable this property for performance gains in Strategy Analyzer optimizations
                    // See the Help Guide for additional information
                    IsInstantiatedOnEachOptimizationIteration    = true;
                }
                else if (State == State.Configure) {
                    try {
                        Print("Account Info:");
                        foreach (Account Acct in Account.All) {
                            Print("Account: " + Acct.DisplayName.ToString());
                            if (Acct.Name != "xxxxxxxx") continue;
                            var enumValues = Enum.GetValues((typeof(AccountItem)));
                            foreach (AccountItem enumValue in (AccountItem[])enumValues) {
                                var Name = Enum.GetName(typeof(AccountItem), enumValue);
                                var Value = Acct.GetAccountItem(enumValue, Currency.UsDollar).Value;
                                Print(Name + ": " + Value);
                            }
    
    
                        }
    
                    }
                    catch {
    
                    }
                }
            }
    
    
            protected override void OnBarUpdate()
            {
                Print(Time[0].ToShortDateString() + "," + Instrument.FullName);
            }
        }​
    Output:

    Account Info:
    Account: Backtest
    Account: Playback101
    Account: Sim101
    Account: xxxxxxxx
    BuyingPower: 100000
    CashValue: 100000
    Commission: 0
    ExcessIntradayMargin: 100000
    ExcessInitialMargin: 0
    ExcessMaintenanceMargin: 0
    ExcessPositionMargin: 0
    Fee: 0
    GrossRealizedProfitLoss: 0
    InitialMargin: 0
    IntradayMargin: 0
    LongOptionValue: 0
    LookAheadMaintenanceMargin: 0
    LongStockValue: 0
    MaintenanceMargin: 0
    NetLiquidation: 1000
    NetLiquidationByCurrency: 100000
    PositionMargin: 0
    RealizedProfitLoss: 0
    ShortOptionValue: 0
    ShortStockValue: 0
    SodCashValue: 0
    SodLiquidatingValue: 0
    UnrealizedProfitLoss: 0
    TotalCashBalance: 100000

    Click image for larger version

Name:	NT SPY 1 min chart.png
Views:	147
Size:	14.9 KB
ID:	1224508

    #2
    Hi Erik, thanks for posting. It looks like the strategy is not enabled. Go into its settings and check the Enabled check box then it should start printing out.

    Kind regards,
    -ChrisL

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X