Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

getting value of double from previous candle

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

    getting value of double from previous candle

    Hey I'm just starting to develope in ninjascript, I used to code in pinescript and I try to make some changes to my indicator from pinescript to a ninjascript.

    In pinescript I can access the previous candle double value by doing (variable name)[1].
    I tried to do the same in pinescript but it is not working.

    Error CS0021 Cannot apply indexing with [] to an expression of type 'double' NinjaTrader.Custom C:\Users\woshr\Documents\NinjaTrader 8\bin\Custom\Indicators\CryptoStars.cs 152 Active

    is there any way to work around it?

    double rsivalue = RSI(14, 3)[0];
    double hb = MAX(RSI(14, 3), 90)[0];
    double lb = MIN(RSI(14, 3), 90)[0];

    double max;
    double max_rsi;
    double min;
    double min_rsi;

    max = hb == 0 ? Close[0] : max[1] == 0 ? Close[0] : max[1];​

    #2
    Solved by creating a variable series<double>

    double rsivalue = RSI(14, 3)[0];
    double hb = MAX(RSI(14, 3), 90)[0];
    double lb = MIN(RSI(14, 3), 90)[0];

    Series<double> max;
    Series<double> max_rsi;
    Series<double> min;
    Series<double> min_rsi;

    max[0] = hb == 0 ? Close[0] : max[1] == 0 ? Close[0] : max[1];​

    Comment


      #3
      Hello oshriur,

      Thanks for your notes.

      I am happy to hear you resolved this matter by using a Series<double> variable. This would be the correct way to do this to get a previous value from a variable. Regular double variables cannot have indexing applied to it but custom Series<T> objects can.

      See this help guide page for more information about custom Series<T> objects: https://ninjatrader.com/support/help...t8/seriest.htm
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      637 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      366 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      107 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      569 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      571 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X