Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Series losing value on next bar

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

    Series losing value on next bar

    Hello,

    I am using series in my strategy (code below) but facing issue when accessing current value of the series. I set the current member value in ExecutionUpate and check the value immediately after setting. However, on next bar update, myDoubleSeries[0] always prints 0. This is driving me nuts. I would really appreciate any help on this.


    private Series<double> myDoubleSeries;

    protected override void OnStateChange()
    {

    // defaul state removed for brevity

    else if (State == State.DataLoaded)
    {
    myDoubleSeries = new Series<double>(this);
    }
    }

    protected override void OnExecutionUpdate( Cbi.Execution e, string executionId, double price, int quantity,
    Cbi.MarketPosition marketPosition, string orderId, DateTime time )
    {

    if(some condition)
    myDoubleSeries[0] = 1
    else
    myDoubleSeries[0] = -1

    Print​ ("Series[0] ={0}​​", myDoubleSeries[0]); //Prints the value correctly
    }

    protected override void OnBarUpdate()
    {
    Print(String.Format("myDoubleSeries.Count = {0}",myDoubleSeries.Count)); //Always 0 even though OnExecutionUpdate member was added to the series
    Print​ ("Series[0] ={0}​​", myDoubleSeries[0]); //This is always 0 even though myDoubleSeries[0] was set to 1 or -1 in OnExecutionUpdate
    }
    Last edited by dejafutures; 05-22-2024, 01:08 PM.

    #2
    Hello dejafutures,

    From a non-data-driven thread like OnExecutionUpdate() you must use TriggerCustomEvent() to synchronize the series first.


    After correcting this, ensure its the same bar by adding CurrentBar to each print.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your help. I am bit lost on the use of TriggerCustomEvent() . Do I need to call this like shown below:

      protected override void OnExecutionUpdate( Cbi.Execution e, string executionId, double price, int quantity,
      Cbi.MarketPosition marketPosition, string orderId, DateTime time )
      {
      TriggerCustomEvent(o =>
      {
      if(some condition)
      myDoubleSeries[0] = 1
      else
      myDoubleSeries[0] = -1​
      }, null);​



      }​

      Comment


        #4
        Hello dejafutures,

        Yes, this is correct.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        22 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        120 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        63 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        45 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X