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 agclub, 04-21-2024, 08:57 PM
      5 responses
      34 views
      0 likes
      Last Post agclub
      by agclub
       
      Started by ESHunter, Today, 08:06 PM
      2 responses
      18 views
      0 likes
      Last Post ESHunter  
      Started by ETFVoyageur, 05-07-2024, 07:05 PM
      19 responses
      150 views
      0 likes
      Last Post ETFVoyageur  
      Started by ETFVoyageur, Yesterday, 10:13 PM
      3 responses
      26 views
      0 likes
      Last Post ETFVoyageur  
      Started by ETFVoyageur, Yesterday, 12:52 AM
      3 responses
      33 views
      0 likes
      Last Post ETFVoyageur  
      Working...
      X