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

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, [COLOR="Red"]2[/COLOR], "");
    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 [COLOR="green"]([/COLOR](CrossBelow(Stochastics(2, 14, 4).K, Stochastics(2, 14, 4).D, 1)) && ((Stochastics(2, 14, 4).D[COLOR="Green"][0][/COLOR]) > 80)[COLOR="green"])[/COLOR]
        {
        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.

            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, "");
                  		}
                  	}
                  }


                  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 junkone, Today, 11:37 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post junkone
                          by junkone
                           
                          Started by quantismo, 04-17-2024, 05:13 PM
                          5 responses
                          34 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Started by proptrade13, Today, 11:06 AM
                          1 response
                          6 views
                          0 likes
                          Last Post NinjaTrader_Clayton  
                          Started by love2code2trade, 04-17-2024, 01:45 PM
                          4 responses
                          34 views
                          0 likes
                          Last Post love2code2trade  
                          Started by cls71, Today, 04:45 AM
                          2 responses
                          10 views
                          0 likes
                          Last Post eDanny
                          by eDanny
                           
                          Working...
                          X