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

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
      Brandon H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by StockTrader88, 03-06-2021, 08:58 AM
      45 responses
      3,992 views
      3 likes
      Last Post johntraderuser2  
      Started by TAJTrades, Today, 09:46 AM
      0 responses
      7 views
      0 likes
      Last Post TAJTrades  
      Started by rhyminkevin, Yesterday, 04:58 PM
      5 responses
      62 views
      0 likes
      Last Post dp8282
      by dp8282
       
      Started by realblubb, Today, 09:28 AM
      0 responses
      8 views
      0 likes
      Last Post realblubb  
      Started by AaronKoRn, Yesterday, 09:49 PM
      1 response
      19 views
      0 likes
      Last Post Rikazkhan007  
      Working...
      X