Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Handling series

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

    Handling series

    Is there a way to divide a price series by itself shifted n bars back? For example, create a new series such that:
    new series = Price/Price[n]

    Eventually I'd like to alter the newly series to create the final series

    final series = constant * Math.Log(Price/Price[n], Math.E);

    Is this doable? Any suggestions would be greatly appreciated. Thank you.

    #2
    Thank you for your question Zeos6. This is easily possible. Some considerations :

    • Whenever we do division with a computer program, a good habit is to always check (even in situations where this is unlikely) that the denominator is not zero. A good "recipe" to avoid this is

      double example = b == 0.0 ? 0.0 : a/b;

    • We will need to guarantee that we have at least n bars. We can do this with

      if (CurrentBar < n) return;

      near the beginning of OnBarUpdate
    • A convention many programmers adopt is to put constants in immutable memory, and to name them with capital letters. While adopting this is your preference, the way to do this in C# is

      public const int EXAMPLE = 0xD06F00d;

    • However since you are modifying an object to create it, rather than const, you will be interested in the readonly keyword, which is publicly documented here and which allows calling constructors

      https://msdn.microsoft.com/en-us/library/acdd6hb7.aspx

      If you create a variable with a getter, and no setter (as I will do in the example I give you), this variable will be readonly, and you will have more flexibility as far as setting up this variable.

    With all this in mind I have prepared a code example. Code samples we provide are for educational purposes, and are not intended for live trading, and are not guaranteed to accomplish any user goal or to be maintained. Please let us know if there are any other ways we can help.
    Attached Files
    Last edited by NinjaTrader_JessicaP; 04-28-2017, 02:46 PM.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the example Jessica. Appreciate it.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      563 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      329 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      547 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      548 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X