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

Breakeven is cancelled on live

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

    Breakeven is cancelled on live

    Hello Ninjatrader support.
    My strategy follows the logic described below.
    1. Initially and each time the position gets flat the logic set stop loss with using
    Code:
    SetStopLoss(CalculationMode.Ticks, Stop_Loss_Ticks);
    2. Once entry condition is met the logic places 2 entry orders with signal names "Entry for TP #1" and "Entry for TP #2"
    3. Once target profit #1 condition is met the logic closes "Entry for TP #1" position and moves stop loss to breakeven in OnPositionUpdate callback
    Code:
    SetStopLoss(CalculationMode.Price, averagePrice);
    It works fine on Sim account. But it doesn't on live account (I use Interactive Broker). Each time the logic moves stop loss to breakeven NT8 cancels stop order for some reason... I guess it has something to do with isLiveUntilCancelled parameter. But the problem is Set methods don't have such a parameter. What can you advise? Should I use ExitLongStopMarket / ExitShortStopMarket instead of SetStopLoss?

    #2
    Hello PopovDS,

    Is there a Native message for the cancellation on the Log tab of the Control Center?

    You may need to use unique signal names for each entry and have separate stop losses using the from entry signals of those entries.

    Set methods do not have an isLiveUntilCancelled implementation and would not cancel for this reason.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      No any native error text (see the attached screenshot). OK, I will try separate SL for each entry.
      Attached Files

      Comment


        #4
        Hello.
        I would like to resume the discussion of the issue of Stop Loss order cancellation on live account Interactive Broker. Note, that issue have never occurred on Sim account. The logic is as following:
        1. Each time the position gets flat stop loss at 140 ticks is placed.
        Code:
        SetStopLoss(CalculationMode.Ticks, 140);
        2. If entry condition is met and position is flat the logic places entry market order.
        Code:
        EnterLong(300, "Entry");
        3. If the position is not flat and target condition is met the logic takes profit.
        Code:
        ExitLong(200, "Profit", "Entry");
        4. Once TP is filled Breakeven is placed.
        Code:
        protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
        {
              if (orderState == OrderState.Filled)
              {
                    if (order.Name == "Profit")
                    {
                            var bid = GetCurrentBid();
                            var ask = GetCurrentAsk();
                            if ((Position.AveragePrice.ApproxCompare(bid) >= 0 && Position.MarketPosition == MarketPosition.Long) ||
                                (Position.AveragePrice.ApproxCompare(ask) <= 0 && Position.MarketPosition == MarketPosition.Short))
                            {
                                   // The stop price is above/below the market
                                   ExitLong();
                            }
                            else
                            {
                                   // Breakeven
                                   SetStopLoss(CalculationMode.Price, Position.AveragePrice);
                            }
                     }
              }
        }​
        Submitted Breakeven is cancelled sometimes. NT8 log doesn't clarify the reason... Perhaps the position size is calculated incorrectly when using IB broker connection... After TP is taken the position size remains at 100.
        Last edited by PopovDS; 03-28-2024, 03:23 PM.

        Comment


          #5
          Are there any suggestions regarding the request posted above?

          Comment


            #6
            Hello PopovDS,

            I recommend using separate entries with unique signal names for each quantity you want to scale out.

            Below is a link to an example.


            Or alternatively, use the unmanaged approach to have full control over the orders.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Haiasi, 04-25-2024, 06:53 PM
            2 responses
            16 views
            0 likes
            Last Post Massinisa  
            Started by Creamers, Today, 05:32 AM
            0 responses
            5 views
            0 likes
            Last Post Creamers  
            Started by Segwin, 05-07-2018, 02:15 PM
            12 responses
            1,786 views
            0 likes
            Last Post Leafcutter  
            Started by poplagelu, Today, 05:00 AM
            0 responses
            3 views
            0 likes
            Last Post poplagelu  
            Started by fx.practic, 10-15-2013, 12:53 AM
            5 responses
            5,407 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Working...
            X