Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Enter long - coding questions

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

    Enter long - coding questions

    I am testing a semi automated strategy which provides entry possibilities in a 1Minute candle stick when certain conditions are met. I then decide whether nor not to enter. When I do decide to enter, let's say long, I want to get in now now now with a market order. However it happened several times now that an order is placed at a certain price, then price continues to move up, the order remains where it was placed and is cancelled a minute later or so. End result I missed a perfectly good entry.

    The portion of the code which I am using for the order entry is as follows:

    {eOrder = EnterLong(contract_Quanity, "");
    Position.AvgPrice = entry_Price;
    return;
    }

    Any suggestions how I would need to amend this code so that it does not merely place an order but actually gets me in, even with a 1 or 2 tick "loss".

    sandman

    #2
    Hi sandman,

    Using EnterLong() will submit a market order that should fill immediately.

    To understand what happened with the order I will need to see your log and trace files.

    Please send an email to support [at] ninjatrader [dot] com. In the email add a link to this forum thread.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Done, I have emailed you everything.

      Comment


        #4
        Hi Chelsea,

        I decided to start from scratch and learn how to build the strategy myself. What I need to arrive at is that I want to enter on my own by clicking on the DOM. From there on, i.e. from that entry onwards the strategy is supposed to take over the management of this trade.

        A. In the first stage (of writing this strategy) I will want to begin with the strategy just placing a StopLoss and a Profit Target.

        B. In the next step I would want to add to that strategy that it exits the trade when a specific indicator changes by moving the Stoploss right then 1tick below the current price and the ProfitTarget 1tick above the current price (going long). Or, going short, moving the StopLoss 1tick above and the ProfitTarget 1tick below the current price. Bracket the current price with a ProfitTargetExitOrder and a StopLossExitOrder so to speak.

        C. In the next and I think last step I would want to figure out how to turn the fixed StopLoss into a Trailing StopLoss as the trade develops.

        Can you please give me a good reference in the HELP section or YOUTUBE where I could start learning this step by step starting with getting A. above accomplished.

        (NB: Charting and indicator building is quite well understood and practiced by myself.)

        sandman

        Comment


          #5
          Hello sandman,

          A) If you would like to enter an order manually and have your strategy recognize the order, the strategy will need to create its own set of buttons that cause actions within the script. This is not supported by NinjaTrader but is possible to accomplish. Orders that are made outside of the strategy, such as from the SuperDOM, Chart Trader, and the Orders tab of the Control Center, will not affect your strategy's position.

          Below is a link to a sample script that uses buttons to enter orders.
          http://www.ninjatrader.com/support/f...php?linkid=490

          For a stop loss and profit target that are automatically set see SetStopLoss and SetProfitTarget in the help guide.
          http://www.ninjatrader.com/support/h...etstoploss.htm
          http://www.ninjatrader.com/support/h...ofittarget.htm

          You can also use an Exit order such as an ExitShortStopLimit order that you modify the price of. This would be similar to a stop loss, except that it cannot be tied with OCO with a ExitShortLimit that is used as a profit target.

          Below is a link to the help guide on Order Methods.
          http://www.ninjatrader.com/support/h...er_methods.htm

          B) Are you asking how to call an indicator to compare to a value?
          Try:
          if (SMA(19)[0] > Close[0])

          This would detect if the current value of the SMA(19) is greater than the current close price.

          Are you asking how to move a stop loss? Call the SetStopLoss again (at any time) with a new value to move the the stop loss.

          If you are using an Exit order as a stop loss, there is an example reference sample that shows how to use this as a trailing stop.
          http://www.ninjatrader.com/support/f...ead.php?t=7499

          C) To use the stop loss as a trailing stop write logic that moves the stop loss to a number of ticks from the current price any time the price goes up (but not down).



          We do have resources to help you begin creating NinjaScript Strategies/Indicators.

          The best way to begin learning NinjaScript is to use the Strategy Wizard. With the Strategy Wizard you can setup conditions and variables and then see the generated code in the NinjaScript Editor by clicking the View Code button.

          I'm also proving a link to a recently recorded 'Automated Strategy Development Webinar' video for you to view at your own convenience: Automated Strategy Development Level 1 - NinjaTrader Training - 3/26/2013

          We also have great resources in relation to Strategy Development on our Support Forum. There is a very active developer community in our support forum that supplements the responses provided by NinjaTrader support staff providing all users with an exceptional support experience.
          Take me to your support forum!

          There are a few Sample Automated Strategies which come pre-configured in NinjaTrader that you can use as a starting point. These are found under Tools--> Edit NinjaScript--> Strategy. You will see locked strategies where you can see the details of the code, but you will not be able to edit (you can though always create copies you can later edit via right click > Save as)

          We also have some Reference samples online as well as ‘Tips and Tricks’ for both indicators and strategies:
          Click here to see our NinjaScript Reference Samples
          Click here to see our NinjaScript Tips

          These samples can be downloaded, installed and modified from NinjaTrader and hopefully serve as a good base for your custom works.

          Further, the following link is to our help guide with an alphabetical reference list to all supported methods, properties, and objects that are used in NinjaScript.
          Alphabetical Reference

          We also have a few tutorials in our help guide for both Indicators and Strategies.
          Indicator tutorials
          Strategy tutorials

          Last, if you would like to have this strategy coded for you, you may contact one of our professional NinjaScript consultants.
          Click here to see our Consultants page
          Last edited by NinjaTrader_ChelseaB; 06-27-2014, 08:10 AM.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Chelsea,

            Thank you very much indeed. That's plenty of specific references to get me going. I'll get back to you if/when I run into something that I cannot figure out.

            sandman
            Last edited by sandman; 06-27-2014, 10:46 AM. Reason: Privacy

            Comment


              #7
              Hi sandman,

              I wanted to give you another example that I've written for another client you may find helpful.
              Attached Files
              Last edited by NinjaTrader_ChelseaB; 06-27-2014, 11:07 AM.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Will your code example work correctly when run inside the strategy analyzer?

                The documentation implies OnMarketData() is not called during backtesting ...

                Comment


                  #9
                  Hi bltdavid,

                  That is correct. In backtest OnMarketData will not trigger.

                  For this to work in backtest, 1 tick intra-bar granularity would need to be added and the trailing action set in OnBarUpdate for the tick series.

                  Below is a link to a reference sample on intra-bar granularity.
                  http://www.ninjatrader.com/support/f...ead.php?t=6652
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks, that is a good example.

                    Do the orders need to be filled on the 1-tick secondary bars series (when BarsInProgress == 0) in order for the trailing stop to be set when BarsInProgress == 1?

                    My question is really, I mean, is it *required* to do it this way?

                    For example, I can see this code in my head:

                    Add(PeriodType.Tick, 1);
                    ....
                    when BarsInProgress == 0
                    Enter order A on bar series #1 <-- can this be #0 or #1 or must it be #1?
                    when BarsInProgress == 1
                    Manage trailing stop on order A

                    Is it required to enter the order against the secondary bar series that
                    will be used to manage the trailing stop? Or does that part matter?

                    Comment


                      #11
                      Hi bltdavid,

                      The order does need to be entered on the secondary data series.

                      If entered on the primary series, only the ohlc of the primary series will be able to close the order. The order can move by being set in BarsInProgress 1, however, the order would still only fill with the primary bars series.

                      So yes, add the order using BarsInProgress 1 so that the tick data will cause the order to fill at the right price.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Thank you, that is an important detail to know.

                        Comment


                          #13
                          "C) To use the stop loss as a trailing stop write logic that moves the stop loss to a number of ticks from the current price any time the price goes up (but not down)."

                          How would this be done? at first i thought it would be a simple if (high [0] > high [1]) but then i realized that wouldn't work quite right, as the high of a bar 2 bars back could be higher, etc

                          Comment


                            #14
                            Hello sra18376,

                            Thank you for your post.

                            You can use the reference sample at the following link as a guide on setting this up: http://www.ninjatrader.com/support/f...ead.php?t=3222

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by sjsj2732, Yesterday, 04:31 AM
                            0 responses
                            31 views
                            0 likes
                            Last Post sjsj2732  
                            Started by NullPointStrategies, 03-13-2026, 05:17 AM
                            0 responses
                            286 views
                            0 likes
                            Last Post NullPointStrategies  
                            Started by argusthome, 03-08-2026, 10:06 AM
                            0 responses
                            283 views
                            0 likes
                            Last Post argusthome  
                            Started by NabilKhattabi, 03-06-2026, 11:18 AM
                            0 responses
                            133 views
                            1 like
                            Last Post NabilKhattabi  
                            Started by Deep42, 03-06-2026, 12:28 AM
                            0 responses
                            91 views
                            0 likes
                            Last Post Deep42
                            by Deep42
                             
                            Working...
                            X