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

Strategy using displaced moving averages

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

    Strategy using displaced moving averages

    Hello,

    I have been having a hard time since I am not a programmer to find out how to make a strategy on the builder using a displaced moving average.
    My strategy is a crossover between a 30 period EMA and a 15 (displaced by -3 periods) EMA.

    I have the knowledge that the "cross above" and "cross below" feature on the builder can't be used for this strategy, then I don't how to program it, I have been struggling with this for 2 days.

    Can somebody please help me?

    #2
    Hello manuelvega,

    Thank you for your post.

    To check for the value of the 15-period EMA 3 bars ago, you would set a 'Bars ago' value of 3 for the 15-period EMA indicator when creating your condition.

    Something you could do is create a condition that checks if the 30-period EMA with a bars ago value of 0 is less than the 15-period EMA with a bars ago value of 3. This would check if the current value of the 30-period EMA is less than the value of the 15-period EMA 3 bars ago.

    See the attached image demonstrating this in the Strategy Builder.

    Let us know if we may assist further.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Unfortunately, it did not work

      Comment


        #4
        Hello manuelvega,

        Thank you for your note.

        Please elaborate on what exactly did not work so we may accurately assist.

        For example, can you enable the strategy on a chart? Do you see orders placed by the strategy when it is enabled?

        I have created a test strategy using the condition shown in the screenshot attached in my previous post. I have also checked the 'Plot on chart' box for each EMA indicator so that we are able to see the EMA plots. When running the test strategy on a chart I am seeing the strategy enable and place orders without issue. See this in the attached screenshot.

        Please also see the attached strategy that was used for testing this.

        Let us know if we may assist further.
        Attached Files
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          My idea for the strategy creation

          In the following picture you can tell that it is not working because the picture from the top is the strategy I created by my sight (just visually, by adding two EMAs to the chart from scratch). The strategy idea works like this: when the blue 15 EMA (-3 periods displacement) crosses above the green 30 EMA I would open a long position, and for the opposite situation I would look for a short. That is why I drew the vertical lines, just to show how the stretegy should work.

          How the strategy made from the builder is actually working

          The picture below shows how the stretegy made from the builder is currently working (following the instructions you gave me on the prior post). It does not open/close the operations at the time they are supposed to open/close in contrast to the picture above.

          The asset I am trading is the MES 09-21 at 60 minutes temporality,

          Please help me

          Comment


            #6
            Hello manuelvega,

            Thank you for your note.

            If the strategy is not placing orders when expected, you should use prints and drawings to determine how the strategy is behaving.

            To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

            In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

            Also, something you could do is use a BackBrush to color the background of the chart when your order entry condition becomes true to visually see when the condition becomes true. In the Strategy Builder this could be done by clicking 'add' in the Actions section, then open the Drawing folder, and select 'Set background color'.

            Below is a link to a forum post that demonstrates using prints to understand behavior and including a link to a video recorded using the Strategy Builder.
            https://ninjatrader.com/support/foru...121#post791121

            Let us know if we may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              I just watched the video and saw that the conditions do not match to the strategy. I also did a market replay to finally check if the conditions were meeting the strategy; I put on a chart the same indicators, a 15-PERDIOD EMA (-3 displacement) & a 30-PERIOD EMA, and what I want the strategy to do is to place the orders as son as the EMAs cross each other on each tick (I also put calculate on each tick on the builder). For example, the picture I attached shows how the 15 EMA (-3) just crossed below the 30 EMA, and when that happens I would like to open a short. That in contrast to the conditions inserted on the builder does completely different.

              May you please optimize this strategy for me? Please contrast each chart, I mean the one visually from scratch with the 2 EMAs (on market replay and on each tick cross) and the one with the strategy builder you told me to do.

              I'm using the MES on 60-minute chart, and I back tested this strategy from February 2021

              Comment


                #8
                Hello manuelvega,

                Thank you for your note.

                In the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services in our support. This is so that we can maintain a high level of service for all of our clients as well as our partners.

                That said, I would be able to assist with any specific NinjaScript related questions you may have. Also, I can assist by demonstrating how to use prints, comments, and the output window to understand the behavior of a script.

                Please briefly explain exactly what part you are having trouble with so that we may point you in the right direction.

                You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. If you would like our NinjaTrader Ecosystem team to follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request, please email vendorsupport[AT]ninjatrader.com.

                I look forward to assisting further.
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  I didn’t know those policies!! Thank you for your assistance!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by arvidvanstaey, Today, 02:19 PM
                  4 responses
                  11 views
                  0 likes
                  Last Post arvidvanstaey  
                  Started by samish18, 04-17-2024, 08:57 AM
                  16 responses
                  61 views
                  0 likes
                  Last Post samish18  
                  Started by jordanq2, Today, 03:10 PM
                  2 responses
                  9 views
                  0 likes
                  Last Post jordanq2  
                  Started by traderqz, Today, 12:06 AM
                  10 responses
                  18 views
                  0 likes
                  Last Post traderqz  
                  Started by algospoke, 04-17-2024, 06:40 PM
                  5 responses
                  48 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X