• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question about breakeven

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

    Question about breakeven

    Hello, please help me, I want to add a breakeven function if the price has passed a certain number of ticks
    Stops and takest I did that way

    protected override void OnExecution(IExecution execution)
    {
    /* We advise monitoring OnExecution to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate()
    which ensures your strategy has received the execution which is used for internal signal tracking. */
    if (entryOrder != null && entryOrder == execution.Order)
    {
    if (Position.MarketPosition == MarketPosition.Long)
    {
    // Stop-Loss order ticks below our entry price
    stopOrder = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 4 * TickSize, "MyLongStop", "Long");

    // Target order ticks above our entry price
    targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 8 * TickSize, "MyTarget", "Long");

    // Resets the entryOrder object to null after the order has been filled
    if (execution.Order.OrderState != OrderState.PartFilled)
    {
    entryOrder = null;
    }
    }
    if (Position.MarketPosition == MarketPosition.Short)
    {
    // Stop-Loss order ticks below our entry price
    stopOrder = ExitShortStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 4 * TickSize, "MyShortStop", "Short");

    // Target order ticks above our entry price
    targetOrder = ExitShortLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 8 * TickSize, "MyTarget", "Short");

    // Resets the entryOrder object to null after the order has been filled
    if (execution.Order.OrderState != OrderState.PartFilled)
    {
    entryOrder = null;
    }
    }
    }

    But I do not know how to call the current price to calculate the required number of ticks to move the stop to +

    #2
    Hello Kovalev,
    Thanks for your post.

    Are you simply trying to find the current price of the instrument?
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JoshG View Post
      Hello Kovalev,
      Thanks for your post.

      Are you simply trying to find the current price of the instrument?
      Hello, NinjaTrader_JoshG, yes, and I also wanted to know - can I prescribe a condition for the movement of stop loss in "On execution"?

      Comment


        #4
        Kovalev,

        Close[0] will be the latest price.

        https://ninjatrader.com/support/help...nt7/?close.htm

        You can also include a condition for your stop loss movement inside OnExecution. Whether that is the best place to use that logic will depend on your specific condition.

        Josh G.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_JoshG View Post
          Kovalev,

          Close[0] will be the latest price.

          https://ninjatrader.com/support/help...nt7/?close.htm

          You can also include a condition for your stop loss movement inside OnExecution. Whether that is the best place to use that logic will depend on your specific condition.
          NinjaTrader_JoshG, but if i use CalculateOnBarClose = true; ?

          Comment


            #6
            Or perhaps another option is to calculate relative to the entry point
            ​​​​​​​if (Position.MarketPosition == MarketPosition.Long && execution.Order.AvgFillPrice + 9 * TickSize)

            Comment


              #7
              Hello Kovalev,

              Yes, Close[0] would be the last close price when using CalculateOnBarClose = true. The building bar is not being accounted for when using CalculateOnBarClose = true.

              It is generally suggested to use the average fill price rather than the close as that is absolute once the order fills where as the close may be different than the end fill price. We have a sample that demonstrates using the fill price to submit targets here: https://ninjatrader.com/support/help...and_onexec.htm

              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by AdmiralUptick, Today, 05:35 AM
              1 response
              13 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by Gav_G, Today, 02:12 PM
              2 responses
              4 views
              0 likes
              Last Post Gav_G
              by Gav_G
               
              Started by Gav_G, Today, 01:41 PM
              0 responses
              5 views
              0 likes
              Last Post Gav_G
              by Gav_G
               
              Started by kweiss, Today, 01:21 PM
              0 responses
              5 views
              0 likes
              Last Post kweiss
              by kweiss
               
              Started by digibob, Yesterday, 06:45 AM
              2 responses
              15 views
              0 likes
              Last Post NinjaTrader_ChrisL  
              Working...
              X