Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

1 ATM order at a time, please

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

    1 ATM order at a time, please

    Forgive me if this has been answered elsewhere. I ran a search and couldn't find an answer. Is there a way to ensure an automated ATM strategy will not open a second position while a first is still active, even if the signal requirements are again met? Also, I'm running the same strategy on four different timeframes. Is it further possible to limit my orders to one at a time? Bascially, even if the signal requirements are eventually met for all four, I'd like my entry orders to be taken on a first come, first serve basis and only have one trade open at a time.

    Thanks,
    Dave

    #2
    Hello,

    It sounds like you need to include a market position condition:
    if (Position.MarketPosition == MarketPosition.Flat)

    You will also find the Entering and Exiting and Retrieving Position Information section of this link helpful:
    http://www.ninjatrader-support.com/H...struments.html
    DenNinjaTrader Customer Service

    Comment


      #3
      Hi Ben,

      Thanks for your reply. I just read through the link you sent. Before I drive myself nuts with BarArray commands, if I were to add "if (Position.MarketPosition == MarketPosition.Flat)" to the code and then opened the strat on each individual chart, would that do what I want? Meaning, if my 1 min triggers an order and it's currently open, if my 5 min gets a buy signal , will it read that my position is NOT currently flat? Also, where do I install this code? Do I treat is at just another condition?

      Thanks.

      Comment


        #4
        Hello,

        I'm not sure what you mean exactly. Maybe code it and post your code if it doesn't work.
        DenNinjaTrader Customer Service

        Comment


          #5
          Morning Ben,

          What I meant was...if I have four timeframe charts open and I install my strategy with the "if (Position.MarketPosition == MarketPosition.Flat)" line in it (so that all four charts have it), will three of my charts know to stay out of the market if one of my timeframes gets a signal and is in a trade?

          Comment


            #6
            Okay, I've added the following to my code:

            {
            Add(PeriodType.Volume, 20000);
            Add(PeriodType.Volume, 30000);
            CalculateOnBarClose = true;
            }

            if (Position.MarketPosition == MarketPosition.Flat && BarsInProgress == 0)
            return;

            // Condition set 1

            else if (Position.MarketPosition == MarketPosition.Flat && BarsInProgress == 2)
            return;

            // Condition set 1

            else if (Position.MarketPosition == MarketPosition.Flat && BarsInProgress == 2)
            return;

            // Condition set 1

            1. My 10,000 volume chart doesn't trade
            2. I'm still getting more than one trade at a time
            3. I am now getting orders for twice - four times the amount my ATM states

            Do I need to enter "Add(PeriodType.Volume, 10000);" and do I need the strat to be running on all these charts? I thought it only needs the first (my 10,000).

            Thanks.

            EDIT: Removed "return;" and "else". Strat now trades my 10,000 but still enters a new position while one is still in play. Also still sometimes enters more positions per trade than it should.
            Last edited by dsraider; 01-31-2010, 01:18 PM.

            Comment


              #7
              Hello,

              First, you have two BarsInProgress ==2. One of these should be set to 1 to over all bars.

              Second, try placing the order via EnterLong() and EnterShort() instead of ATM strategies. ATM's are sent and forgotten by the strategy.
              DenNinjaTrader Customer Service

              Comment


                #8
                Hey Ben,

                I actually do have BarsInProgress [1] and [2] in my strat. I just copied and pasted in here and forgot to change it. Sorry.

                Your second point makes complete sense. However, set my ATM to do the following:

                1. Go long 2 cars (ES).
                2. Set two targets at 4 and 8 ticks.
                3. Set stops for both at -8 ticks.
                4. Set both trails to where once I am 4 ticks in profit, both stops move to 4 ticks behind current price, or break-even (I do this for the first because my targets NEVER fill immediately).
                5. Have second trail follow tick by tick thereafter.

                I have no problem coding this directly but was under the impression that I couldn't do so without using an ATM. Am I wrong?

                Thanks.

                Comment


                  #9
                  Hello,

                  Everything you do in an ATM can be done in a strategy, it just takes some coding to get it done. Here is a link that will help with the trailing stop code:
                  DenNinjaTrader Customer Service

                  Comment


                    #10
                    Maybe it's me, but from everything I read, I can't code a stop loss and a trail stop in the same strat, like how the ATM works. Also, I didn't see a way to have two targets, with two separate trails. Am I reading it wrong or is there a sample anywhere that does this? I installed 'SamplePriceModification' but that didn't seem to help either...

                    Comment


                      #11
                      Hello,

                      I will have someone reply to you on Monday. Thank you for your patience.
                      DenNinjaTrader Customer Service

                      Comment


                        #12
                        dsraider, you can code different trails and combine stoploss / trailstops. Important is to scale in first to be able to scale out at a later point - http://www.ninjatrader-support2.com/vb/showthread.php?t=3751

                        For stoploss / trailstop on the very same position please use the 'SamplePriceModification' Ben referred you to, as you can't use a SetStopLoss and SetTrailStop on the same position, thus you use a SetStopLoss only and change it's stop price as needed on the fly (trailing aspect).

                        Comment


                          #13
                          Thank you, Bertrand and Ben. Will report back...

                          Dave

                          Comment


                            #14
                            Hi Bertrand. I took a look at what both of you suggested. Thanks very much for the link. Here is what I WANT to do (ex. for long):

                            When X happens, go long 2 ES cars
                            1. set targets at +4 and +8 ticks
                            2. set stop loss at -8 ticks for both
                            3. when +4 in profit, move stop to breakeven on both (since target never sells at first touch)
                            4. have stop trail, tick for tick, on second car, once 1st target sells

                            My entries and targets now work perfectly. My problem, however, is with the stop loss. Since I can't use both Stop Loss and Trail, I tried to cancel the stop loss once I was +4 ticks in profit and replace it with trails on both. I couldn't get that to work so I decided to make my own trail:

                            protected override void Initialize()
                            {
                            //Add(PeriodType.Volume, 20000);
                            //Add(PeriodType.Volume, 30000);
                            EntriesPerDirection = 1;
                            EntryHandling = EntryHandling.UniqueEntries;

                            CalculateOnBarClose = true;

                            SetProfitTarget("Long 1a", CalculationMode.Ticks, 4);
                            SetProfitTarget("Long 1b", CalculationMode.Ticks, 8);
                            SetProfitTarget("Short 1a", CalculationMode.Ticks, 4);
                            SetProfitTarget("Short 1b", CalculationMode.Ticks, 8);
                            SetStopLoss(CalculationMode.Ticks, 8);
                            }

                            /// <summary>
                            /// Called on each bar update event (incoming tick)
                            /// </summary>

                            protected override void OnBarUpdate()
                            {
                            // Entry Condition: If signal occurs
                            if ("entry signal occurs")
                            {
                            // Only allow entries if we have no current positions open
                            if (Position.MarketPosition == MarketPosition.Flat)
                            {
                            SetStopLoss(CalculationMode.Ticks, 8);
                            }

                            // Resets the stop loss to the original value when all positions are closed
                            else if (Position.MarketPosition == MarketPosition.Long)
                            {
                            // Once the price is greater than entry price +4 ticks, set stop loss to breakeven
                            if (Close[0] > Position.AvgPrice + 4 * TickSize)
                            SetStopLoss(CalculationMode.Price, Position.AvgPrice);
                            }
                            // Once the price is greater than entry price +5 ticks, set stop loss to breakeven +1
                            if (Close[0] > Position.AvgPrice + 5 * TickSize)
                            {
                            SetStopLoss(CalculationMode.Price, Position.AvgPrice +1);
                            }
                            // Once the price is greater than entry price +6 ticks, set stop loss to breakeven +2
                            if (Close[0] > Position.AvgPrice + 6 * TickSize)
                            {
                            SetStopLoss(CalculationMode.Price, Position.AvgPrice +2);
                            }
                            // Once the price is greater than entry price +7 ticks, set stop loss to breakeven +3
                            if (Close[0] > Position.AvgPrice + 7 * TickSize)
                            {
                            SetStopLoss(CalculationMode.Price, Position.AvgPrice +3);
                            }
                            // Once the price is greater than entry price +8 ticks, set stop loss to breakeven +4
                            if (Close[0] > Position.AvgPrice + 8 * TickSize)
                            {
                            SetStopLoss(CalculationMode.Price, Position.AvgPrice +4);
                            }

                            {
                            EnterLong("Long 1a");
                            EnterLong("Long 1b");
                            }
                            }

                            My stop doesn't show in the DOM and as you can see by the attached pic, I believe it's setting my stop loss at 4.00 on the ES (a little too much risk for me). Am I doing something wrong? Also, is it possible to just cancel the stop and replace it with a trail? I'd like to do whatever will cause the least number of problems when I'm live.

                            Thanks,
                            Dave
                            Attached Files
                            Last edited by dsraider; 02-01-2010, 11:04 AM.

                            Comment


                              #15
                              Dave, you would need to use the same approach for the stops as you've done for the target side, basically you need a stop for each contract to be able to close one and then trail the other contract.

                              Also you want to add the TickSize multipler to your stop loss price calls / amendments as well - i.e.

                              Code:
                              // Once the price is greater than entry price +8 ticks, set stop loss to breakeven +4
                              if (Close[0] > Position.AvgPrice + 8 * TickSize)
                              {
                              SetStopLoss(CalculationMode.Price, Position.AvgPrice + 4 [B]* TickSize[/B]);
                              }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              95 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              50 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              31 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              36 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              72 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X