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 rbeckmann05, Yesterday, 06:48 PM
      1 response
      12 views
      0 likes
      Last Post bltdavid  
      Started by llanqui, Today, 03:53 AM
      0 responses
      6 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      10 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      15 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Working...
      X