Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problems with CalculateOnBarClose

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

    Problems with CalculateOnBarClose

    Dear Sirs,

    I am programming a strategy that must work in realtime, that is, with CalculateOnBarClose = false; In my strategy I use for example the value of the volume, like this:

    double volumentrading = EMA(VOL(),10)[0];

    and then I print it in the screen with:

    DrawTextFixed("Text", "\nVolumen: "+volumentrading, TextPosition.TopRight);

    If I use the same in an indicator this value is continuously changing (updating), but in a strategy with COBC=false; it remains fixed all time.

    Any idea about this behaviour?

    Thanks in advance


    #2
    Hello Sangui,

    You should experence the same behavior inside of a strategy that you would see inside of an Indicator for COBC = false. Does it only update when a new bar is created or does it not update at all?

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      I think the problem is because I am using "protected override void OnMarketData(MarketDataEventArgs e)" within the strategy code, like this:

      protected override void OnBarUpdate()
      { .... }

      protected override void OnMarketData(MarketDataEventArgs e)
      {.....}

      Maybe the reason is because I am not using if (Historical) return; in the code of OnBarUpdate?

      Comment


        #4
        it does not update at all. But when I remove "protected override void OnMarketData(MarketDataEventArgs e) code" it updates, so I think I must add if (Historical) return; in the code of OnBarUpdate, right?

        Comment


          #5
          Hello Sangui,

          If you have COBC set to false, you may set everything inside of OnBarUpdate() as it will be called with each incoming price data. If it was not updating at all, there may have been an error, you may check your Log tab inside of the Control Center to see if there was an error. I believe what was happening was that were trying to access an array that was out of bounds which was causing your strategy not to disable itself. You may either want to check to make sure you have enough bars before starting your calculations and/or yes you may add the "if (Historical) return;" so that it will run in real-time.

          Happy to be of further assistance.
          JCNinjaTrader Customer Service

          Comment


            #6
            It was the array... Because of the COPY-PASTE :-). Thanks

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            633 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            364 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
            567 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            568 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X