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

ETF trading and help

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

    ETF trading and help

    Hello, I have some questions about some variables. I would very much appreciate examples of all 3 in strategy builder if possible. I know there are some smart people in here 8)

    I am trying to
    1) Buy 2 ETFs at the bell open
    2) Close all active positions at a specific time of the day
    3) Create a stop loss on both ETFs at 2% loss when bought

    PS: Is it possible to run 2 stocks as one strategy... or do i just run both as separate strategies at the same time?

    #2
    Hello Tirosovan,

    Thanks for your post.

    To clarify, are you wanting to submit orders to two separate instruments?

    Or, are you wanting to place orders on a single instrument when conditions on a separate instrument occur? (For example, if the Close price of instrument 2 is greater than the Close price of instrument 1, submit an order to instrument 1)

    If you want to submit orders to two separate instruments, this is not possible to accomplish in a Strategy Builder strategy. You would need to unlock your code from the Strategy Builder by clicking the 'Unlock code' button and manually program your strategy to submit orders to two instruments.

    This could be accomplished by adding a secondary series to the script using the AddDataSeries() method and then submitting entry orders to the primary series and added secondary series.

    See the help guide documentation below for more information about AddDataSeries() and working with Multi-Timeframe/Multi-Instrument NinjaScripts.

    AddDataSeries() Help Guide: https://ninjatrader.com/support/help...dataseries.htm
    Multi-TimeFrame/Multi-Instrument Help guide: https://ninjatrader.com/support/help...nstruments.htm

    You could also view the reference samples that come with NinjaTrader, SampleMultiInstrument and SampleMultiTimeFrame. To view these scripts, open a New > NinjaScript Editor window, open the Strategies folder, and double click on the 'SampleMultiInstrument' or 'SampleMultiTimeFrame' files.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      I suppose I could run 2 strategies in the strategies tab though? Back test each one individually then run both during the day.

      I have another question:
      Is there a way to sell a position after a % from open has been achieved?

      Comment


        #4
        I suppose I could run 2 strategies in the strategies tab though? Back test each one individually then run both during the day.

        I have another question:
        Is there a way to sell a position after a % from open has been achieved?

        Comment


          #5
          Hello Tirosovan,

          Thanks for your notes.

          Yes, you could run two strategies on separate instruments in the Strategies tab of the Control Center.

          To clarify, are you wanting to exit the position when the current market price reaches a certain percentage away from the average position price of the entry?

          If so, you could create a condition that checks if the Close price (Price folder > Close) is greater than or equal to the Average Position Price (Strategy folder > Average position price) and offset the Average Position Price by a set percent. Then, create an action in that Set to place an exit order, such as ExitLong() (Order Management folder > Exit long position)

          See the help guide documentation below which contains information about offsetting a value and exiting a market position.

          Conditions: https://ninjatrader.com/support/help...on_builder.htm
          Actions: https://ninjatrader.com/support/help...t8/actions.htm
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            This is excellent! thank you.

            Question 1: So now I'm trying to run my strategies live, but today the simulation account did not produce any loss or gain for the day. The chart posted the trades as if they triggered visually. The chart is connected to the strategy and are enabled, what am I missing?

            Question 2: Is there a way to trade $ amount each day instead of quantity of shares? Entropy effects my bottom line over the course of weeks-months of back-testing.

            Comment


              #7
              Hello Tirosovan,

              Thanks for your notes.

              1. Please test the SampleMACrossover strategy that comes with NinjaTrader on the Sim101 account. After letting the script run and place trades on real-time data, do you see a value in the Sim101 account in the Accounts tab of the Control Center for the 'Realized Pnl' column?

              Do you see a value reported for the 'Realized' column for the strategy in the Strategies tab of the Control Center?


              2. You would need to program your strategy to calculate a certain quantity based on a dollar amount and then use that calculated quantity for the Enter/Exit methods within your script. This would need to be done in an unlocked script as it cannot be done in a Strategy Builder strategy.

              Utilizing AccountItem you could pull the information you would like: https://ninjatrader.com/support/helpGuides/nt8/accountitem.htm

              You should confirm with your broker the formula for calculating the funds required for each trade or contract.

              In general, the formula would be the Account CashValue divided by Margin.

              The AccountItem.CashValue can be found from an account with Account.Get().

              Account.Get(): https://ninjatrader.com/support/helpGuides/nt8/get.htm

              For backtesting a script, you would need to calculate this in your script. The Strategy Analyzer does not have a specific account to get account information from. You could use an input to allow the user to set the account size, or you could query the account balance by finding an account and using the AccountItem.CashValue with Account.Get().​
              Brandon H.NinjaTrader Customer Service

              Comment


                #8
                Ok, i ran it today, it worked!

                Sorry i have so many questions. I'm learning so much. So what about buying after a % up or down?

                Comment


                  #9
                  Hello Tirosovan,

                  Thanks for your notes.

                  To clarify, are you referring to placing an entry order if the current Close price is a certain percentage above the previous Close price?

                  If so, you could create a condition that checks if the current Close price (Price folder > Close > Bars ago set to 0) is greater than the previous Close price (Price folder > Close > Bars ago set to 1) and offset the previous Close price by a set percentage. Then, create an action to place an entry order, such as EnterLong() (Order Management folder > Enter long position).

                  See this help guide page for more information about price comparisons and offsetting a value: https://ninjatrader.com/support/help...on_builder.htm
                  Brandon H.NinjaTrader Customer Service

                  Comment


                    #10
                    Great info!

                    What about buying on the 5 min chart when 3 red candles form?

                    Comment


                      #11
                      Actually, to be more precise, I want to sell all positions and not buy on a red candle. Also, to buy on any green candle. This is a 5 min chart.

                      Comment


                        #12
                        Hello Tirosovan,

                        Thanks for your notes.

                        To detect if the current bar is a red bar (down bar) you could create a condition that checks if the current Close price (Close[0]) is less than the current Open price (Open[0]).

                        To detect if the previous bar is a red bar (down bar) you could create a condition that checks if the previous Close price (Close[1]) is less than the previous Open price (Open[1]).

                        Note that we pass in a barsAgo of 0 to get the current price and we pass in a barsAgo of 1 to get the previous price. To check if the bar is a red bar 2 bars ago you would pass in a barsAgo value of 2, and so on.

                        To detect is the current bar is a green bar (up bar) you could create a condition that checks if the current Close price (Close[0]) is greater than the current Open price (Open[0]).

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

                        Comment


                          #13
                          Perfect!

                          Ok, so I was backtesting the 11 minute heikenashi chart. I noticed I don't have this option when I try and run the bot live in simulation. Am i just not seeing the option? is it possible to run a custom time frame?

                          Backtesting has almost any time frame you want. I was hoping this would translate into live simulation.

                          Comment


                            #14
                            Hello Tirosovan,

                            Thanks for your notes.

                            Yes, a strategy could be run live on an 11-Minute Heiken Ashi chart or from the Strategies tab of the Control Center.

                            To run the strategy from a chart, open a New > Chart window, set the chart Data Series 'Type' field to 'Heiken Ashi', set the 'Bars period type' field to 'Minute', and set the 'Base period value' field to 11 to open an 11-Minute Heiken Ashi chart. Then, enable your strategy on that chart window.

                            To run the strategy from the Strategies tab of the Control Center, navigate to the Strategies tab of the Control Center, right-click in the Strategies tab, select 'New strategy', select the strategy you want to run, set the Data Series 'Type' field to 'Heiken Ashi', set the 'Bars period type' field to 'Minute', set the 'Base period value' field to 11, and click 'OK'. Then, check then 'Enabled' checkbox in the Strategies tab of the Control Center to enable the strategy.

                            Here are some help guide links for more information about enabling a strategy.

                            Enabling a Strategy from the Control Center — https://ninjatrader.com/support/helpGuides/nt8/running_a_ninjascript_strateg2.htm

                            Enabling a Strategy in a Chart window — https://ninjatrader.com/support/helpGuides/nt8/running_a_ninjascript_strategy.htmt
                            Brandon H.NinjaTrader Customer Service

                            Comment


                              #15
                              Thank you,

                              Your links are broken.

                              I kept my bots running this morning and nothing happened. They are running on Sim101's and are enabled. The connection to Kinetic is good. Why do the charts not update live? so when i get back from work the new days chart should be populated.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by burtoninlondon, Today, 12:38 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post burtoninlondon  
                              Started by AaronKoRn, Yesterday, 09:49 PM
                              0 responses
                              14 views
                              0 likes
                              Last Post AaronKoRn  
                              Started by carnitron, Yesterday, 08:42 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Yesterday, 07:51 PM
                              0 responses
                              13 views
                              0 likes
                              Last Post strategist007  
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              44 responses
                              3,982 views
                              3 likes
                              Last Post jhudas88  
                              Working...
                              X