Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Changing Bars.CurrentBar - is it safe?

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

    Changing Bars.CurrentBar - is it safe?

    Due to logic of my indicator sometimes I need to move back to the history and recalculate my indicator values again

    The simplest way how to do it is to change value of Bars.CurrentBar to bar i need to recalculate and then run my calculation again. Something like this:

    Code:
                    
    var aBarsCurrentBar = Bars.CurrentBar;
    try
    {
       Bars.CurrentBar = bar_I_need_to_recalculate;
       Call my calculation engine here
    }
    finally
    {
      //restoring  current bar
      Bars.CurrentBar = aBarsCurrentBar;
    }
    Everything works great, but considering Ninja's multithreading, i'm not sure, that changing of the current bar is safe for other indicators / strategies. Maybe, I need to lock Bars object for the time I'm changing its current bar? Or maybe I need to use some other syncronization methods?

    #2
    Hello rfsettling,

    Thank you for your note.

    Setting the value of CurrentBar would not be supported and could introduce issues.

    Have you considered saving your indicator values to a data series for which you could reference at a future point in time? For example I included an indicator which divides two SMA’s and saves their values to a series, for which at any point in the future you could call the value of that that series, x values ago.

    Please let us know if you need further assistance.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      I need to recalculate previous values, not current (which is [0]). That's a point.
      Let's consider example

      I have some formula to calculate current value of indicator:
      Value[0]=some_function()

      At some time i decide that some previos bar (for example, [10]) must be re-calculated, so, I set CurrentBar=CurrentBar-10 and call my calculation routime once again and then return CurrentBar value to normal. Everything works well, but I'm not sure, whether other indicators at this moment would use normal CurrentBar or my changed current bar. This bothers me

      Comment


        #4
        Hello rfsettling,

        Thank you for your response.

        As my colleague stated setting the CurrentBar is not supported.

        Instead you just need to reference bars you wish to use to recalculate values and then set the values of your Series to those at the needed bar.

        For example, let's say you wish to recalculate the values from 10 bars ago. In my example below I am recalculating the High minus the Low from 10 bars ago.
        Code:
        Value[10] = (High[10] - Low[10]);
        Please let me know if you have any questions.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Rapine Heihei, Today, 07:51 PM
        0 responses
        2 views
        0 likes
        Last Post Rapine Heihei  
        Started by frslvr, 04-11-2024, 07:26 AM
        5 responses
        96 views
        1 like
        Last Post caryc123  
        Started by algospoke, 04-17-2024, 06:40 PM
        6 responses
        49 views
        0 likes
        Last Post algospoke  
        Started by arvidvanstaey, Today, 02:19 PM
        4 responses
        11 views
        0 likes
        Last Post arvidvanstaey  
        Started by samish18, 04-17-2024, 08:57 AM
        16 responses
        61 views
        0 likes
        Last Post samish18  
        Working...
        X