Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Pending EnterLongLimit cancelled in new Bar

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

    Pending EnterLongLimit cancelled in new Bar


    I have been trying for 15 days that not to cancel my EnterLongLimit at the end of the first candle. I tried it anyway
    What is wrong here? I would appreciate some help

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class diau : Strategy
    {
    private double Target;
    private Order myEntryOrder = null;
    private int barNumberOfOrder = 0;


    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "diau";
    Calculate = Calculate.OnEachTick;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    Target = 0;
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;


    // Set 1
    if ((Close[1] > Open[1])
    && (myEntryOrder == null))
    {
    Target = (Low[1] + (-30 * TickSize)) ;
    myEntryOrder = EnterLongLimit(Convert.ToInt32(DefaultQuantity), Target, "hello");
    barNumberOfOrder = CurrentBar;


    }

    if (myEntryOrder != null && CurrentBar > barNumberOfOrder + 5 && myEntryOrder.OrderState == OrderState.Working)
    {
    CancelOrder(myEntryOrder);
    myEntryOrder = null;
    }
    }


    }
    }


    #2
    Hello milfocs,

    When using the managed approach orders are automatically cancelled after the submission bar closes, unless the overload with isLiveUntilCancelled is used and set to true.

    EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)

    "isLiveUntilCancelled - The order will NOT expire at the end of a bar, but instead remain live until the CancelOrder() method is called or its time in force is reached.​"

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      oki thanks,
      I've change it, but now it doesn't put the enterlonglimit

      BarsRequiredToTrade = 20;
      // Disable this property for performance gains in Strategy Analyzer optimizations
      // See the Help Guide for additional information
      IsInstantiatedOnEachOptimizationIteration = true;
      Target = 0;
      Velestime = 1;
      }
      else if (State == State.Configure)
      {
      }
      }

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 1)
      return;

      // Set 1
      if (Close[1] > Open[1])
      {
      Target = (Open[1] + (-30 * TickSize)) ;
      EnterLongLimit(0, true, Convert.ToInt32(DefaultQuantity), Target, "LongEntry");
      }

      }
      }
      }​

      Comment


        #4
        Hello milfocs,

        Your code would be updating the price of the that order on every bar update the condition is true (instead of submitting the order once).

        One line above the condition, print the time of the bar, print Close[1], Open[1], and print GetCurrentAsk().

        Enable TraceOrders and print the order.ToString() object in OnOrderUpdate().

        Below is a link to a support article on using Print() and TraceOrders to understand behavior.


        Re-run the script and provide the output from the output window.

        We want to see the limit price of the order is above the ask price for the order to fill on each bar update.
        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
        633 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        567 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X