Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.



        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.



          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 Christopher_R, Today, 12:29 AM
              0 responses
              9 views
              0 likes
              Last Post Christopher_R  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              166 responses
              2,235 views
              0 likes
              Last Post sidlercom80  
              Started by thread, Yesterday, 11:58 PM
              0 responses
              3 views
              0 likes
              Last Post thread
              by thread
               
              Started by jclose, Yesterday, 09:37 PM
              0 responses
              8 views
              0 likes
              Last Post jclose
              by jclose
               
              Started by WeyldFalcon, 08-07-2020, 06:13 AM
              10 responses
              1,415 views
              0 likes
              Last Post Traderontheroad  
              Working...
              X