Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

1 ATM order at a time, please

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

    #16
    Okay, I added the "* TickSize" part, which makes perfect sense. Thanks for that. Tried doing the following:

    SetStopLoss("Long 1a", CalculationMode.Ticks, 8);
    SetStopLoss("Long 1b", CalculationMode.Ticks, 8);

    and got: No overload for method 'SetStopLoss' takes '3' arguments

    Did I not understand you correctly?

    UPDATE: See next post and forget I ever wrote this dumb one.
    Last edited by dsraider; 02-01-2010, 01:18 PM. Reason: Because I am an idiot

    Comment


      #17
      SetStopLoss("Short 1a", CalculationMode.Ticks, 8, false);
      SetStopLoss("Short 1b", CalculationMode.Ticks, 8, false);

      ^ Compiles. I forgot about the bool part with stops. Do I have to do that for each breakeven/ticksize statement or can I just leave it as this:

      // Only allow entries if we have no current positions open
      if (Position.MarketPosition == MarketPosition.Flat)
      {
      SetStopLoss("Short 1a", CalculationMode.Ticks, 8, false);
      SetStopLoss("Short 1b", CalculationMode.Ticks, 8, false);
      }

      // Resets the stop loss to the original value when all positions are closed
      else if (Position.MarketPosition == MarketPosition.Short)
      {
      // 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);

      Thanks again,
      Dave

      Comment


        #18
        Great progress Dave - you would need to do this for each SetStopLoss where you want to change it's price to trail the stop...those are tied to each scaled in entry, thus you need those mutiple calls to trail all and not just a part of the overall position.

        Comment


          #19
          Bertrand,

          Thanks for the words of encouragement (I need them). Is this what you meant?

          // Only allow entries if we have no current positions open
          if (Position.MarketPosition == MarketPosition.Flat)
          {
          SetStopLoss("Long 1a", CalculationMode.Ticks, 8, false);
          SetStopLoss("Long 1b", CalculationMode.Ticks, 8, false);
          }

          // 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("Long 1a", CalculationMode.Price, Position.AvgPrice, false);
          SetStopLoss("Long 1b", CalculationMode.Price, Position.AvgPrice, false);

          Comment


            #20
            You're welcome Dave, yes this is what needed to be done.

            Comment


              #21
              Thanks again, Bertrand, but this gave me mixed results.

              It set one stop perfectly and the other at a price of 1.00 instead of 1083.50, like the other. Then, my breakeven/trail didn't work. My code compiles and looks fine. Am I missing something?

              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("Long 1a", CalculationMode.Ticks, 8, false);
              SetStopLoss("Long 1b", CalculationMode.Ticks, 8, false);
              SetStopLoss("Short 1a", CalculationMode.Ticks, 8, false);
              SetStopLoss("Short 1a", CalculationMode.Ticks, 8, false);
              }

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

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

              // 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("Long 1a", CalculationMode.Price, Position.AvgPrice, false);
              SetStopLoss("Long 1b", CalculationMode.Price, Position.AvgPrice, false);
              }
              // Once the price is greater than entry price +5 ticks, set stop loss to breakeven +1
              if (Close[0] > Position.AvgPrice + 5 * TickSize)
              {
              SetStopLoss("Long 1b", CalculationMode.Price, Position.AvgPrice +1 * TickSize, false);
              {
              Last edited by dsraider; 02-01-2010, 03:09 PM.

              Comment


                #22
                Dave, you want to reset the stop losses as well when you're flat with your strategy. Please also enable TraceOrders in the Initialize() to be able to take a look 'under the hood' of your order behavior -



                Also ensure your entry handling is set to 'PerEntryExecution' under Tools > Options > Strategies > NinjaScript.

                Comment


                  #23
                  Done and done. Question, though. I thought it looked strange to have "Close[0] > Position.AvgPrice + 4 * TickSize" where 'Close' = current price. Wouldn't this mean if current bar closes > entry price by 4 ticks, move up the stop? I ask because my stop did just move up on the sim, though not as expected. Maybe I should be using something other than "Close" so it moves up tick by tick. Is there a 'CurrentPrice' command or something like it? I can't seem to find one.

                  Thanks.

                  Comment


                    #24
                    Dave, you could run the strategy updating on each tick (CalculateOnBarClose = false) or you could use the Closes of a added, finer series to get more frequent updates -

                    Comment


                      #25
                      That has to be it. I just changed all the > to == and the stops moved perfectly upon the close of each bar. So, it looks like i need a trail, unless I prevent the stop from moving backwards. Can I set the strat to start out with a stop loss, then cancel it once it hits a certain point and replace it with a trail? I don't want it to trail right from the start so I can't just use a normal trailing stop as far as I know.

                      I didn't see your last post until now. Even if this updates on a tick by tick bases, they way it's written, my stop will move backwards as price moves backwards, since it's set to be 4 ticks behind price. So, is there either a way of preventing the stop loss from moving backwards or is there a way of replacing the stop loss with a trailing stop once I am 4 ticks in profit?

                      Thanks.
                      Last edited by dsraider; 02-01-2010, 05:01 PM.

                      Comment


                        #26
                        Dave, the strategy would start out with your static SetStopLoss value until the commands to trail based on your trade PnL are kicking into gear. To not have it move backward, just higher...you would need to keep track of the peak profit while in the trade and then only trail further if this is exceeded.

                        Comment


                          #27
                          Okay, can you help point me in the right direction for that? Sounds like it's the last part I need...

                          Thanks.

                          Comment


                            #28
                            Dave, several ways to approach this - one would be to save your current unrealized Pnl in a variable and reassign if higher than the value of the previous saved value.

                            Or you use one of the trailstop frameworks shared by users in our sharing section -

                            Comment


                              #29
                              Hi Bertrand.

                              First, thanks for the link. One of the other members had what I was looking for and my stop now stays put.

                              Unfortunately, I'm now having a few issues. Sometimes, it enters and sets stops perfectly. Sometimes it will set one stop at 8 (which is right) and the other anywhere from 3 - 7. Sometimes it cancels itself, saying that I can't set stops higher than current market price. I absolutely cannot figure out why this is happening. I tried exporting the zip but it wouldn't let me do that either, even though it complies. Can you please take a look and see if anything jumps out at you?

                              Also, I want to use limit orders and tried every code combination I could think of. Is there anything that's preventing me from using limit orders?

                              Thanks in advance,
                              Dave
                              Attached Files

                              Comment


                                #30
                                Dave, could not compile as it misses then the NinjaScript utility you use from TradingStudies, might need to check it manually to export it with the script -



                                For the stops, you would need to make sure you submit them at valid prices if you run into this error...it could mean the stop is too close for the developing bar to be at a valid price point.

                                When using limit orders for entry, you would run into issues potentially with our Internal Order Handling Rules -

                                http://www.ninjatrader-support.com/H...verview36.html (bottom section here).

                                You would notice ignored orders (because for example a Set() method order still being working as per the rules) if you let your script run with TraceOrders = true in the Initialize().

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                89 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                48 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
                                34 views
                                0 likes
                                Last Post TheRealMorford  
                                Started by Mindset, 02-28-2026, 06:16 AM
                                0 responses
                                69 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Working...
                                X