Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trying to convert StochRSI from Pinescript to Ninjascript..

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

    Trying to convert StochRSI from Pinescript to Ninjascript..

    This is essentially the Pinescript code
    src
    =input(close, title="RSI Source")
    rsi1=ta.rsi(src, 14)
    k=ta.sma(ta.stoch(rsi1, rsi1, rsi1, 14), 3)
    d=ta.sma(k, 3)

    I've tried converting this into Ninjascript with this, but keep getting errors

    OnBarUpdate
    -----

    //RSI
    double rsi = RSI(14, 3)[0];

    //Stoch
    stoch[0] = Stochastics(rsi, 14, 14, 3)[0];

    //Stochastics
    k[0] = SMA(stoch, 3)[0];
    d[0] = SMA(k, 3)[0];​

    ​Before I keep trying to fix any error that appears. Is this even the correct way of doing it?

    #2
    i can help you convert this to nt8

    Comment


      #3
      k[0] = SMA(Stochastics(RSI(14, 3), 14, 14, 3), 3)[0];
      d[0] = SMA(k, 3)[0];​

      thats the solution ​

      Comment


        #4
        Originally posted by ajgauss13 View Post
        k[0] = SMA(Stochastics(RSI(14, 3), 14, 14, 3), 3)[0];
        d[0] = SMA(k, 3)[0];​

        thats the solution ​
        Thanks! That did work. It's super simple too. No errors in the code but I am getting a "Object reference not set to an instance of an object"

        Comment


          #5
          Please send me the code here to check please

          Comment


            #6
            hello send me the full code please

            Comment


              #7
              Originally posted by ajgauss13 View Post
              Please send me the code here to check please
              public class StochasticRSI : Strategy
              {
              private Series<double> k;
              private Series<double> d;

              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
              Description = @"Enter the description for your new custom Strategy here.";
              Name = "StochasticRSI";
              Calculate = Calculate.OnBarClose;
              EntriesPerDirection = 1;
              EntryHandling = EntryHandling.AllEntries;
              IsExitOnSessionCloseStrategy = true;
              ExitOnSessionCloseSeconds = 30;
              IsFillLimitOnTouch = true;
              MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
              OrderFillResolution = OrderFillResolution.Standard;
              Slippage = 0;
              StartBehavior = StartBehavior.WaitUntilFlat;
              TimeInForce = TimeInForce.Gtc;
              TraceOrders = false;
              RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
              StopTargetHandling = StopTargetHandling.PerEntryExecution;
              BarsRequiredToTrade = 20;
              // Disable this property for performance gains in Strategy Analyzer optimizations
              // See the Help Guide for additional information
              IsInstantiatedOnEachOptimizationIteration = true;
              }
              else if (State == State.Configure)
              {
              }
              }

              protected override void OnBarUpdate()
              {
              if (CurrentBar < BarsRequiredToTrade)
              return;

              //Stochastics
              k[0] = SMA(Stochastics(RSI(14, 3), 14, 14, 3), 3)[0];
              d[0] = SMA(k, 3)[0];

              //Trades
              trade stuff here
              }
              }
              }​

              Comment


                #8
                Add in state == state.Configure

                else if (State == State.Configure)
                {
                k= new Series<double>(this);
                d= new Series<double>(this);



                }​

                Comment


                  #9
                  Originally posted by ajgauss13 View Post
                  Add in state == state.Configure

                  else if (State == State.Configure)
                  {
                  k= new Series<double>(this);
                  d= new Series<double>(this);



                  }​
                  Wow that seemed to work! No error this time, backtest ran fine. Thank you man. I was searching google to no avail.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Yesterday, 05:17 AM
                  0 responses
                  62 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  134 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  75 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  45 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  50 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X