Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

using ATM strategy in strategy

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

    #16
    Originally posted by NinjaTrader_ChelseaB View Post
    Hi arbuthnot,

    A breakeven would be pretty simple to achieve with logic.

    if (Position.MarketPosition == MarketPosition.Long && Close[0] >= Position.AvgPrice + 10 * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice);
    }

    This would be a breakeven at 10 ticks.

    However if you would like I can submit a feature request to development to create a function that does this. Would you like me to submit a feature request for this?
    Hi Chelsea

    Thanks very much for your ideas.

    Firstly, I would indeed be very grateful to you if you could submit a request for a breakeven function that would be accessible in Initialize. Along with the other functions or methods (stoploss, etc.) this would enable a non-ATM strategy to be as powerful as an ATM without any special coding.

    Secondly, thanks very much for the 'breakeven' code you posted. I've been taking a close look at it and it seems very effective. (Almost all my own script work thus far has been involved with indicator development and I'm just now trying to find the best strategy implementation of these so I'm learning about 'AvgPrice', etc.)

    Assume we've set variables: ProfitTrigger and BreakEvenPlus (the amount above the entry price where we wish to put the stop) and there's a bool: BreakEvenSet.

    The reason for having a bool (and please correct me, Chelsea, if this isn't necessary) is because, without one, as illustrated below, whenever Close[0] >= Position.AvgPrice + ProfitTrigger * TickSize, a new stop would be entered, whereas we only wish this to happen once.

    So this is the code as I've slightly adjusted it:

    if (
    Position.MarketPosition == MarketPosition.Long
    && Close[0] >= Position.AvgPrice + ProfitTrigger * TickSize
    && BreakEvenSet == false
    )

    {
    SetStopLoss(CalculationMode.Price, (Position.AvgPrice + BreakEvenPlus) * TickSize);
    BreakEvenSet = true;
    }


    Another point is this: the stop level is set, initially, as:

    (Position.AvgPrice + BreakEvenPlus) * TickSize

    Won't future bars recalculate "Position.AvgPrice" according to the AvgPrice level for that bar? I'm thinking (and of course, I could be wrong here) that it may be an idea to set a variable to take this value, such as:

    Variable0 = Position.AvgPrice

    so that the value remains constant.

    Thanks for letting me have your thoughts on this, Chelsea.

    Much obliged.

    Comment


      #17
      Hi arbuthnot,

      Thanks for your note.

      I have submitted a feature request in your behalf to create a function similar to SetTrailStop that does a breakeven action.

      Regarding your question about Position.AvgPrice, the Position.AvgPrice does not change from bar to bar. This is the entry price for your position. The Position.AvgPrice does not change unless the position changes. So if you add in an order, the Position.AvgPrice will re-average the entry prices for individual orders to the position average entry price.

      If the position changes, you will want the Position.AvgPrice to change to include the new order.

      Below is a link to the help guide on Position.AvgPrice.
      http://www.ninjatrader.com/support/h...7/avgprice.htm


      If you want to use the entry price of an individual order, you will need the IOrder handle of the order.

      For example:

      private IOrder myOrder = null;

      myOrder = EnterLong();

      if (myOrder != null && myOrder.OrderState == OrderState.Filled)
      {
      Print(myOrder.AvgFillPrice);
      }

      Below is a link to the help guide on IOrder.
      http://www.ninjatrader.com/support/h...nt7/iorder.htm
      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      647 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      369 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      572 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X