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

Moving Average Price Crossover

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

    Moving Average Price Crossover

    There are many indicators out there where a signal is generated when two moving averages cross. Does anyone have an indicator that would generate a signal (arrow, dot etc.) when price crosses a user defined, single, moving average? How difficult would it be to create it on the platform's "new indicator" function?

    #2
    Hello edleal,

    I'm not aware of one but should be easy enough to create. You can create through New Indicator if you are comfortable working with code. If you want to create this without code, you can use the strategy wizard to define the crossing condition as well as the draw action. Help for working with the strategy wizard is available here:
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Moving Average Price Crossover

      Thanks for your help Ryan. I used the Strategy Wizard and have not been successful in gettng the strategy to work. When activated nothing appears on my charts. I smply tried to program an up arrow to appear for price closing above the moving average and a down arrow for price closing below the moving average. A copy of the generated code is in the attached file. Not sure where I messed up.


      Comment


        #4
        Rya here's the code

        ///</summary>
        [Description("A buy or sell signal is generated when price crosses the moving average.")]
        publicclass MAPriceCrossover : Strategy
        {
        #region Variables
        // Wizard generated variables
        privateint mAPeriod = 1; // Default setting for MAPeriod
        // User defined variables (add any user defined variables below)
        #endregion
        ///<summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        ///</summary>
        protectedoverridevoid Initialize()
        {
        CalculateOnBarClose = true;
        }
        ///<summary>
        /// Called on each bar update event (incoming tick)
        ///</summary>
        protectedoverridevoid OnBarUpdate()
        {
        // Condition set 1
        if (CrossAbove(Close, EMA(14), 1))
        {
        DrawArrowUp("My up arrow" + CurrentBar, false, 0, 0, Color.Lime);
        }
        // Condition set 2
        if (CrossBelow(Close, EMA(14), 1))
        {
        DrawArrowDown("My down arrow" + CurrentBar, false, 0, 0, Color.Red);
        }
        }
        #region Properties
        [Description("Moving Average Period")]
        [GridCategory("Parameters")]
        publicint MAPeriod
        {
        get { return mAPeriod; }
        set { mAPeriod = Math.Max(1, value); }
        }
        #endregion
        }
        }

        Comment


          #5
          One issue is the Y value that the objects are drawn at. You selected 0 so will not have a place to draw the arrows. You can draw near bar values, like lows or highs. There is an example showing a Y value here, in the drawing objects section:
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Moving Average Price Crossover

            Ryan thanks again for your help but may I offer a suggestion. I think your company's time would be well spent putting effort into making your help guides more comprehensive and user friendly. Maybe also consider adding a weekly webinar for indicator/strategy creation like you do for ATMs. Ninja's wizard help guide is simply not helpful enough, things could be made a lot easier if there were more examples provided for each step. It's very frustrating to have the option to use all these powerful trading tools but yet not be able to make them work with a reasonable investment of time and effort.

            I got the arrow/Y access issue squared away but there are many other variables that I have not programmed properly. Even though I've selected a different moving average the program invariably uses the default setting of 14 periods. It is also generating an excessive number of arrows. Not only does it generate an arrow for the appropriate "crossing bar"but then does the same for every successive bar on the same side of the moving average as the trigger bar.

            Comment


              #7
              Thank you for the feedback. You may be interested in attending this webinar on automated strategy development.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                my ema/price cross doesnt compile

                I copied your code into a new indicator and tried to compile but it says 'the type or namespace name "publicint" could not be found.
                I'm using it as an indicator not strategy since I want signals but dont want Ninja making entries for me. I want a signal when 1 bar ago price was less than the 5 EMA and now >= 5 EMA. I wanted to get yours to work then adjust it for my needs but I can't get yours working.
                Attached Files

                Comment


                  #9
                  Hello simpletrades,

                  Thank you for your post.

                  On line 61 of the code; change "publicint" to "public int".

                  Please let me know if you have any questions.

                  Comment


                    #10
                    thanks it compiles but it doesn't show on a chart. oh well. not that big of a deal.

                    Comment


                      #11
                      Hello simpletrades,

                      Thank you for your response.

                      Do you see any errors in the Log tab of the Control Center?

                      I look forward to your response.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by PhillT, Today, 02:16 PM
                      1 response
                      1 view
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by Kaledus, Today, 01:29 PM
                      3 responses
                      9 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by frankthearm, Yesterday, 09:08 AM
                      14 responses
                      47 views
                      0 likes
                      Last Post NinjaTrader_Clayton  
                      Started by gentlebenthebear, Today, 01:30 AM
                      2 responses
                      13 views
                      0 likes
                      Last Post gentlebenthebear  
                      Started by PaulMohn, Today, 12:36 PM
                      2 responses
                      17 views
                      0 likes
                      Last Post PaulMohn  
                      Working...
                      X