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 SalmaTrader, 07-07-2026, 10:26 PM
        0 responses
        45 views
        0 likes
        Last Post SalmaTrader  
        Started by CarlTrading, 07-05-2026, 01:16 PM
        0 responses
        22 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 06-17-2026, 10:32 AM
        0 responses
        14 views
        0 likes
        Last Post CaptainJack  
        Started by kinfxhk, 06-17-2026, 04:15 AM
        0 responses
        20 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 06-17-2026, 04:06 AM
        0 responses
        22 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Working...
        X