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

Assigning barsAgo in a Reference set to a custom counter Series

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

    Assigning barsAgo in a Reference set to a custom counter Series

    Is there an example anywhere of a dynamic (so to speak) barsAgo applied to a referenced indicator Series?
    I'm attempting to have MAX look back within the barsAgo but only when in a position (e.g. long/short). So the relative barsAgo would update so long as the position wasn't flat.

    I've written something along these lines but can't seem to get the language to pass when applying myCounter to barsAgo:

    private Series<double> myCustomSeries;
    private MAX ref_MAX;
    private Series<int> myCounter


    protected override void OnStateChange()
    {
    }
    else if (State == State.DataLoaded)
    {
    myCounter = new Series<int>(this);
    ref_MAX = MAX(myCustomSeries, myCounter[0]);
    }
    }

    Thanks,

    #2
    Hello larkmail,

    I'm not quite clear on what you are wanting.

    Indicators have a plot series which also uses barsAgo indexes.
    The print below would print the value of the SMA from 5 bars ago.
    Print(SMA(14)[5]);

    In your suggested code you have a custom series, but the custom myCustomSeries is not initialized and it appears you are attempting to use the most recent bar value of the myCounter series as the period (number of bars) for the MAX indicator call. Are you trying to save custom calculated values for every bar?

    Are you trying to save a bar number and then reference this bar later?

    int savedBar;

    // In OnBarUpdate():
    if (/* condition that occured where you want to save the bar number */)
    savedBar = CurrentBar;

    // where you want information about that bar at a later time:
    Print(SMA(14)[CurrentBar - savedBar]);

    Are you wanting to add a different instrument or time frame with AddDataSeries() and use this for the input series of an indicator?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Let me apply and follow up. Thank you

      Comment


        #4
        Chelsea,

        So i was successful in getting this summary to work:

        Value[0] = (Convert.ToInt32(MAX(MyReferencedSeries,myCounter[0])[0]));

        in this example myCounter is the number of bars that have passed since an event occurred. I then applied that as the int barsAgo which dynamically expands the area that i wish MAX to review.

        The issue i'm having (and guessing you know this) is this renders noticeable amount of additional processing.

        Any suggestions on less consuming methods of
        1. denoting the ongoing highest value in a
        2. dynamically growing set of bars based on
        3. a start (to stop) condition?
        Thanks,

        L

        Comment


          #5
          Hello L,

          The Max method would be correct for finding the highest value in a range of bars in a series.

          This is what Ninjatrader has, but you could write your own method that loops through bars.


          ​​​​​​Use bools to prevent conditions from evaluating as true. Set the bool to true when the action occurs, set the bool to false to reset when you want, require the bool to be true for the action.

          ​​​​​
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by stafe, 04-15-2024, 08:34 PM
          6 responses
          31 views
          0 likes
          Last Post stafe
          by stafe
           
          Started by adeelshahzad, Today, 03:54 AM
          4 responses
          26 views
          0 likes
          Last Post adeelshahzad  
          Started by merzo, 06-25-2023, 02:19 AM
          10 responses
          823 views
          1 like
          Last Post NinjaTrader_ChristopherJ  
          Started by frankthearm, Today, 09:08 AM
          5 responses
          17 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          43 views
          0 likes
          Last Post jeronymite  
          Working...
          X