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

Long Strategy using moving average

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

    Long Strategy using moving average

    I would like to create a strategy to open a long position if a bar opens greater than a moving average utilizing daily bars. I would like this position to remain open until it reaches a profit target of x percent and then sell.

    In addition I would like the process to repeat the next day and so on even if I am currently long another position or multiple positions.

    As I have attempted to create the tutorial strategies it seems that all my results are on 1min bars. What am I doing wrong.

    Iam a non programmer and I am not sure how to acheive this end.

    Any assistance would greatly be appreciated.

    #2
    ZIBA1, welcome to the forums! This will depend on from which chart you start your strategy from, the used interval is not 'hard coded' into the strategy - just apply the strategy you already setup to a daily chart - http://www.ninjatrader-support.com/H...ingAChart.html
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thank you for assistance. I've tried opening a new chart prior to running the strategy and setting the interval to daily bars, and once I have done that and re run the strategy I do not get any trades to occur and there is no data on the chart.

      Does it make any difference that the historical data that I am utilizing for this process was downloaded from a one minute file?

      If not I am not sure what is occuring.

      Comment


        #4
        Yes, it could be you don't have access to daily data - http://www.ninjatrader-support.com/H...ricalData.html

        As a workaround it would be best to use 1440 min bars then to test this.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I just tried adjusting the interval to 1440 minute bars. That did adjust the chart to display show me a daily bar. When I then went to see the individual trades they are still listed in one minute increments.

          I am utilizing tradestation for data and after reviewing the link it appears that they do not support daily data.

          I did notice that I can make a connection to Yahoo for daily data.

          I will try that. Thank You.

          Comment


            #6
            Correct, the TS connection does not support historical daily data, Yahoo would be a convenient alternative for you - http://www.ninjatrader.com/webnew/support_Yahoo.htm
            BertrandNinjaTrader Customer Service

            Comment


              #7
              I just made a connection to Yahoo and that did the trick. Thank you

              Do you have any thoughts on how I might begin to create the stategy I posted?

              I want to enter a long position at the open price on a daily bar once my stock is above a moving average. I would like to hold that position open until price meets a profit target value.

              I would like to then repeat the process of opening a new position even though my previous position has not sold.

              Comment


                #8
                You can setup this up in our Strategy Wizard - http://www.ninjatrader-support.com/H...rdScreens.html

                Just check for price being greater than you're MA value and place the needed order type then (for example a stop market buy order at the open).

                A profit target can be added later in the wizard as well.

                For multiple entries even if a position is open, work with the EntriesPerDirection setting upon starting the strategy (Order Handling settings) - http://www.ninjatrader-support.com/H...Direction.html
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Here is the code I am using for this strategy. It doe not return an entry
                  every time the open is above the MA. The profit target is working.

                  Any thoughts?

                  Attached Files

                  Comment


                    #10
                    The order placed as this would expire at the end of the bar if not filled, this is default behavior in NinjaTrader, you can set those to liveUntilCancelled if you unlock the code and use the suitable overload - http://www.ninjatrader-support.com/H...rLongStop.html

                    In addition TraceOrders are helpful to debug and analyze your order behavior - http://www.ninjatrader-support2.com/...ead.php?t=3627
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      I am sorry I am so inexperienced at the Strategy creation process.
                      I read the links, but I am lost as to how to proceed with the live til cancelled funtion.

                      I added the trace to the code, but not sure where to go from here.

                      Thanks for your patience and understanding.

                      Comment


                        #12
                        For the TraceOrders please open up the output window to follow the info generated while orders are placed (Control Center > Tools > Output Window).



                        For the liveUntiCancelled, try this call in your Condition1 -

                        Code:
                         
                        // Condition set 1
                        if (Open[0] > EMA(14)[0])
                        {
                        EnterLongStop(0, true, DefaultQuantity, Open[0], "LE");
                        }
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          I have made the changes to the code

                          I am now receiving an error in the log file

                          the stop price is < or = to close price of the current bar

                          I am not sure I quite understand.

                          Thank You
                          Attached Files

                          Comment


                            #14
                            You can only place a buy stop order above the market, so this may or may not be the case in your scenario as the order is placed, try to enter a Limit order then for example.
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              Bertrand,

                              Thanks for all of you generous assistance, but I am still having problems.

                              I would like to create a strategy to open a long position if a bar opens greater than a moving average utilizing daily bars. I would like this position to remain open until it reaches a profit target of x percent and then sell.

                              I would like this position to buy at the open each day and then sell at profit target.

                              Thanks for your thoughts again.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by haas88, 03-21-2024, 02:22 AM
                              18 responses
                              207 views
                              0 likes
                              Last Post haas88
                              by haas88
                               
                              Started by Board game geek, Today, 02:20 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post Board game geek  
                              Started by knighty6508, Today, 01:20 AM
                              2 responses
                              13 views
                              0 likes
                              Last Post knighty6508  
                              Started by franatas, Today, 01:53 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post franatas  
                              Started by knighty6508, Today, 01:17 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post knighty6508  
                              Working...
                              X