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

Coding Help - Double RSI Cross within 60 candles

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

    Coding Help - Double RSI Cross within 60 candles

    Hi There,

    I'm new to this platform and very new to coding in general but I'm giving it my best effort. Lot's of great resources on this website so thank you all for what you do.

    I'm trying to code in a strategy/indicator to enter a short position after the RSI has crossed below 70 (from > 70 to < 70) twice within the last 60 candles. Here's what I came up with but it doesn't seem to work:

    if (CountIf(delegate {return (CrossBelow(RSI1.Avg, RSIInput, 0));}, 60) > 2)
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), "");
    }

    Any feedback/support would be greatly appreciated.

    Thanks for your time.

    -Kyle

    #2
    BTW RSIInput = 70. I just have it as an input because I wanted to play around with the optimization to see which RSI crossover number might give the best results.

    Comment


      #3
      Hi kylef,
      IF I had to accomplish this using the StrategyBuilder, I would in doubt run two cross over checks on each bar.
      For the most recent cross over, bars ago is 0 and lookback period is 1.
      For the "elder" cross over, bars ago is -1 and lookback period is 59 in your example (60-1), because you start further looking back from one bar ago already.
      If both conditions are true, you should have two "defined" cross overs w/in your lookback period.
      The suggestion assumes you want to enter immediately after the new cross occurred ...
      NT-Roland

      Comment


        #4
        Thanks for the suggestion but when I try it, it is entering the trade each time it crosses below the 70 RSI and not just on the second crossover within 60 bars.

        Any ideas?
        Last edited by kylef; 06-06-2020, 03:38 PM.

        Comment


          #5
          Hi kylef, thanks for your question.

          You can use the MRO method to find the most recent occurrence of a condition:

          https://ninjatrader.com/support/helpGuides/nt8/?most_recent_occurence_mro.htm - MRO

          The support team can not write custom code, but I always encourage heavy use of Print() methods to print data to the output window to find what is going unexpectedly in a script. Place the print statements in strategic locations in your script (like within or right before conditional statements) to find bugs.

          https://ninjatrader.com/support/help...nt8/?print.htm - Print()

          Kind regards.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by kylef View Post

            if (CountIf(delegate {return (CrossBelow(RSI1.Avg, RSIInput, 0));}, 60) > 2)
            {
            EnterShort(Convert.ToInt32(DefaultQuantity), "");
            }
            I'd suggest you look into more robust ways of testing that condition. Even if it worked, and you had 3 consecutive data points: first below zero, second briefly returns above zero, and the third one goes below zero again, you'd trigger an order entry. It can be even worse if you have a similar statement for long positions and the fourth data point goes above zero again. You'd end up with an entry short and an entry long, effectively opening and immediately closing your position.

            What you are trying to solve is more complex than simply figuring out the last two occurrences of an event, but rather "(1) the last two occurrences of an event (2) up to X data points back in time but (3) no less than Y data points back in time."

            X and Y will be your parameters, and you will have to constantly tweak them based on the current market. Hope this helps.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by kevinenergy, 02-17-2023, 12:42 PM
            115 responses
            2,699 views
            1 like
            Last Post kevinenergy  
            Started by prdecast, Today, 06:07 AM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by Christopher_R, Today, 12:29 AM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by chartchart, 05-19-2021, 04:14 PM
            3 responses
            577 views
            1 like
            Last Post NinjaTrader_Gaby  
            Started by bsbisme, Yesterday, 02:08 PM
            1 response
            15 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X