Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Breakeven for NT8

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

    Breakeven for NT8

    I have been unable to get my stoplosss to move to breakeven +2 pips after .002 (20 pips) of profit in my favor has been met since entry.

    Here is a simple example of what I have been trying.

    if ((Close[1] < Close[2])
    && (Close[0] > Close[1]))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }



    if (High[0] >= Position.AveragePrice + .002 )
    ExitLongStopMarket(Position.Quantity,Position.Aver agePrice + .0002 );

    Any help would be greatly appreciated.
    Last edited by FXMIKE; 10-02-2016, 07:32 PM.

    #2
    Hello FXMIKE,

    Thanks for your post.

    The ExitLongStopMarket would be cancelled on the next bar unless resubmitted. From the NT8 helpguide on Managed Approach, "By default, orders submitted via Entry() and Exit() methods automatically cancel at the end of a bar if not re-submitted" Link:

    You can use the method overload that provides a live until canceled order: ExitLongStopMarket(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double stopPrice, string signalName, string fromEntrySignal) Link: http://ninjatrader.com/support/helpG...t_strateg2.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      I tried using this code as well and it also did not work. Does this example also cancel the order after each bar

      if ((Close[1] < Close[2])
      && (Close[0] > Close[1]))
      {
      EnterLong(Convert.ToInt32(DefaultQuantity), "");
      }

      if (High[0] >= Position.AveragePrice + .002 )
      SetStopLoss("", CalculationMode.Price,Position.AveragePrice + .0002 , false);

      Comment


        #4
        Hello FXMIKE,

        Thanks for your reply.

        The code you've shown with SetStopLoss() should work however keep in mind if you have previously used SetStopLoss(), and you enter an order, the SetStopLoss will immediately employ using whatever the last value was in the previous use of SetStopLoss().

        It is recommended that if using SetStopLoss() that when you are flat, that you set the stoploss to a specific level so that when your entry order is placed, the setstoploss will be in the correct initial position. Typically this is done by setting the stop loss using CalculationMode.Pips, with the value of pips away to set the initial stop. You can then employ your breakeven adjustment when you are in a position...

        http://ninjatrader.com/support/helpG...etstoploss.htm
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Can you provide me and example of how to reset the stoploss when the position is Flat?


          Thanks

          Comment


            #6
            Hello FXMIKE,

            Thanks for your reply.

            Here is an example of resetting the value of SetStopLoss() when flat:

            if (Position.MarketPosition == MarketPosition.Flat)
            {
            SetStopLoss(CalculationMode.Pips, 30);
            }

            http://ninjatrader.com/support/helpG...etstoploss.htm
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Using the code below as an example will move the stoploss to Breakeven plus 2 pips, but now it will not take the normal 20 pips stoploss if the trade goes in the opposite direction before moving 20 pips in profit. Is it possible there is a bug or am I missing something. I know I am new to programming so any help would be greatly appreciated.


              }
              else if (State == State.Configure)
              {
              SetStopLoss("", CalculationMode.Pips,.20, false);
              SetProfitTarget("", CalculationMode.Pips, 40);


              }
              }

              protected override void OnBarUpdate()
              {

              if (Position.MarketPosition == MarketPosition.Flat)
              {
              SetStopLoss(CalculationMode.Pips, 20);
              }

              if (CurrentBar < BarsRequiredToTrade)
              return;

              if (Position.MarketPosition == MarketPosition.Long)

              Be = (Position.AveragePrice + .002);



              if ((Close[1] < Close[2])
              && (Close[0] > Close[1]))

              {
              EnterLong(Convert.ToInt32(DefaultQuantity), "");
              }


              //Moves Stoploss To Breakeven +2 pips
              if (High[0] >= Position.AveragePrice + .002 )

              SetStopLoss("", CalculationMode.Price,Position.AveragePrice + .0002 , false);

              Comment


                #8
                Hello FXMIKE,

                Thanks for your post.

                This statement:

                if (High[0] >= Position.AveragePrice + .002 )
                SetStopLoss("", CalculationMode.Price,Position.AveragePrice + .0002 , false);

                Will adjust the stop level even when you are not in a position.

                Please try:

                if (Position.MarketPosition == MarketPosition.Long && High[0] >= Position.AveragePrice + .002 )
                SetStopLoss("", CalculationMode.Price,Position.AveragePrice + .0002 , false); // adjust stop when in a position and when High> entry + 2 ticks.

                If this does not resolve, please send your strategy code file to PlatformSupport[at]Ninjatrader[dot]com mark atten Paul and a link to this thread. The source code file can be found in Documents>Ninjatrader8>Bin>Custom>strategy>
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks, I had that in the code before I posted this topic on the forum, but must of deleted it as I was trying to get the stoploss to move to breakeven. The code now works perfect since adding this back in.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by trilliantrader, 04-10-2024, 09:33 PM
                  6 responses
                  23 views
                  0 likes
                  Last Post trilliantrader  
                  Started by traderqz, Today, 12:06 AM
                  5 responses
                  9 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by Mongo, Today, 11:05 AM
                  2 responses
                  7 views
                  0 likes
                  Last Post Mongo
                  by Mongo
                   
                  Started by guillembm, Today, 11:25 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post guillembm  
                  Started by Tim-c, Today, 10:58 AM
                  1 response
                  3 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X