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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      37 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, Yesterday, 02:41 AM
      0 responses
      18 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      25 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      34 views
      0 likes
      Last Post CarlTrading  
      Working...
      X