• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

RSI Entry Code

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

    RSI Entry Code

    Can someone tell me what is wrong with this code please. On 5 min chart

    if (CrossBelow(Stochastics(2, 14, 4).K, Stochastics(2, 14, 4).D, 1)) && ((Stochastics(2, 14, 4).D) > 80);
    {
    EnterShortLimit(DefaultQuantity, 2, "");
    }

    I would also like to add a condition so the trade enters only when the Rsi K <= D and falling in 30 min chart.

    Can someone help me with this or direct me to text that can make this clear..

    Thank you

    #2
    Hello mccallum28,
    You have 2 as the limit price. Are you sure you want to place an order with a limit price of 2.

    Code:
    EnterShortLimit(DefaultQuantity, 2, "");
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      I have adjusted to enter at default:

      EnterShort(DefaultQuantity, "");

      But the following still shows compile errors.

      if (CrossBelow(Stochastics(2, 14, 4).K, Stochastics(2, 14, 4).D, 1)) && ((Stochastics(2, 14, 4).D) > 80);

      {
      EnterShort(DefaultQuantity, "");
      }

      Comment


        #4
        Hello mccallum28,
        If you use the below code then can you compile it.

        Code:
        if ((CrossBelow(Stochastics(2, 14, 4).K, Stochastics(2, 14, 4).D, 1)) && ((Stochastics(2, 14, 4).D[0]) > 80))
        {
        EnterShort(DefaultQuantity, "");
        }
        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Ahh that sorted it, can you also assist me with adding another condition. I only want the trades to enter when

          if ((CrossBelow(Stochastics(4, 14, 4).K, Stochastics(4, 14, 4).D, 1)) && ((Stochastics(4, 14, 4).D[0]) >= 80))

          On a secondary higher time frame such as 30 min.

          Can you help me with this or point me to text that points out how to do this.

          Thanks

          Comment


            #6
            Hello mccallum28,
            You can do it by creating a multi-series NinjaScript code. Please refer to our help guide which further discusses on it.

            http://www.ninjatrader.com/support/h...nstruments.htm
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              if ((CrossBelow(Stochastics(4, 14, 4).K, Stochastics(4, 14, 4).D, 1)) && ((Stochastics(4, 14, 4).D[0]) >= 85))

              if (Stochastics(BarsArray[2],4,14,4).K[0] > 80);
              {
              EnterShort(DefaultQuantity, "");
              }


              I have added "Add(PeriodType.Minute, 30);" to protected override void Initialize() and added the code above but I get an error on calling "OnBarUpdate" it says the index was outside the bounds of the array.

              How do I correct this, I appreciate your help..

              Comment


                #8
                Originally posted by mccallum28 View Post
                if ((CrossBelow(Stochastics(4, 14, 4).K, Stochastics(4, 14, 4).D, 1)) && ((Stochastics(4, 14, 4).D[0]) >= 85))

                if (Stochastics(BarsArray[2],4,14,4).K[0] > 80);
                {
                EnterShort(DefaultQuantity, "");
                }


                I have added "Add(PeriodType.Minute, 30);" to protected override void Initialize() and added the code above but I get an error on calling "OnBarUpdate" it says the index was outside the bounds of the array.

                How do I correct this, I appreciate your help..
                The strategy also fails to enable....

                Comment


                  #9
                  Hello mccallum28,
                  You have appended BarsArray[2] to calculate teh Stochastic based on the secondary series. It should be BarsArray[1]. Also instead of BarsArray we recommend using Closes[1].

                  Please try this code and see if you able to get it work.

                  Code:
                  protected override void OnBarUpdate()
                  {
                  	if (CurrentBars[0] < 1 || CurrentBars[1] < 1) return;
                  	if (this.BarsInProgress == 0)
                  	{
                  		if ((CrossBelow(Stochastics(4, 14, 4).K, Stochastics(4, 14, 4).D, 1)) && ((Stochastics(4, 14, 4).D[0]) >= 85))
                  
                  		if (Stochastics(Closes[1],4,14,4).K[0] > 80);
                  		{
                  			EnterShort(DefaultQuantity, "");
                  		}
                  	}
                  }
                  http://www.ninjatrader.com/support/h...inprogress.htm
                  http://www.ninjatrader.com/support/h...tml?closes.htm
                  http://www.ninjatrader.com/support/h...urrentbars.htm
                  JoydeepNinjaTrader Customer Service

                  Comment


                    #10
                    Hi Joydeep,

                    I have used the code you suggested, on back testing the strategy it seems trades are being entered short between 0 and 100 rather than when crossover occurs over the OB mark ie 80 in the primary time frame and RSI over 85 in the secondary timeframe i.e 30min.

                    Because of the above the strategy is entering trades on every bar, rathet than only when in the OB or OS position.

                    protected override void OnBarUpdate()

                    {
                    if (CurrentBars[0] < 1 || CurrentBars[1] < 1) return;
                    if (this.BarsInProgress == 0)
                    {
                    if ((CrossBelow(Stochastics(4, 14, 4).K, Stochastics(4, 14, 4).D, 0)) && ((Stochastics(4, 14, 4).D[0]) >= 80))

                    if (Stochastics(Closes[1],2,14,4).K[0] > 85);
                    {
                    EnterShort(DefaultQuantity, "");
                    }
                    }


                    // Condition set 2
                    if ((CrossAbove(Stochastics(4, 14, 4).K, Stochastics(4, 14, 4).D, 0)) && ((Stochastics(4, 14, 4).D[0]) <= 20))

                    if (Stochastics(Closes[1],2,14,4).K[0] < 20);
                    {
                    EnterLong(DefaultQuantity, "");
                    }

                    }

                    Comment


                      #11
                      Hello mccallum28,
                      To assist you further can you please send a toy NinjaScript code* replicating the behavior to support[AT]ninjatrader[DOT]com

                      Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

                      I look forward to assisting you further.

                      *The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.
                      JoydeepNinjaTrader Customer Service

                      Comment


                        #12
                        Any update Joydeep>?

                        Thanks

                        Comment


                          #13
                          Hello mccallum28,
                          I have received your mail and has replied back to it. I need the actual cs file and not the code snippet so that I can test it further.

                          Please do check your inbox (including the spam folder) and reply to my email.
                          JoydeepNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by sledge, Today, 06:11 PM
                          1 response
                          8 views
                          0 likes
                          Last Post sledge
                          by sledge
                           
                          Started by Bionian, Today, 02:46 PM
                          2 responses
                          9 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by rwilliam, Today, 01:54 PM
                          1 response
                          19 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by franco12364, Today, 11:27 AM
                          1 response
                          13 views
                          0 likes
                          Last Post NinjaTrader_PaulH  
                          Started by YevhenShynkarenko, Today, 11:48 AM
                          4 responses
                          27 views
                          0 likes
                          Last Post NinjaTrader_ChrisL  
                          Working...
                          X