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

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 usazencort, Today, 01:16 AM
      0 responses
      1 view
      0 likes
      Last Post usazencort  
      Started by kaywai, 09-01-2023, 08:44 PM
      5 responses
      603 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by xiinteractive, 04-09-2024, 08:08 AM
      6 responses
      22 views
      0 likes
      Last Post xiinteractive  
      Started by Pattontje, Yesterday, 02:10 PM
      2 responses
      21 views
      0 likes
      Last Post Pattontje  
      Started by flybuzz, 04-21-2024, 04:07 PM
      17 responses
      230 views
      0 likes
      Last Post TradingLoss  
      Working...
      X