Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error : order has been ignored....

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

    Error : order has been ignored....

    Hi, every time I enable my strategy I get the error in picture 1, do you know what it means?

    here is my strategy, not working properly, don't know why, sometimes the orders are not cancelled and he can't update properly.

    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class Aversion3 : Strategy
    {
    private int PositionCalc;
    private double SLprice;
    private double Entryprice;

    private MyDonchianClose MyDonchianClose1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "Aversion3";
    Calculate = Calculate.OnPriceChange;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = false;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.ImmediatelySubmit;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.IgnoreAllErrors;
    StopTargetHandling = StopTargetHandling.ByStrategyPosition;
    BarsRequiredToTrade = 60;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    Virtual_Account_Value = 10000;
    Risk = 0.06;
    Contract_Multiplier = 1;
    Entry_Stop_Spread_TICKS = 100;
    PositionCalc = 1;
    SLprice = 1;
    Entryprice = 1;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    MyDonchianClose1 = MyDonchianClose(Close, 54);
    }
    }

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

    if (CurrentBars[0] < 55) //you have to put 2, unless it wont run because you are asking indicator data [1]barago, so need 2 bars at least.
    return; //you have to put 55, so you would have at least 55 bars, unless he tries to enter position on 3 bars distance which is huge!

    // Set 1
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    Entryprice=MyDonchianClose1.Upper[1]; //calculating what should be the position size of the trade
    SLprice=MyDonchianClose1.Lower[1];
    double PositionCalc=Math.Ceiling((Virtual_Account_Value*R isk)/((Entryprice-SLprice)*Contract_Multiplier));

    EnterLongStopLimit(Convert.ToInt32(PositionCalc), (MyDonchianClose1.Upper[1] + (Entry_Stop_Spread_TICKS * TickSize)) , MyDonchianClose1.Upper[1], @"EnterLong");
    }

    // Set 2
    if (Position.MarketPosition == MarketPosition.Long)
    {
    //here you put Position.Quantity=equal to currentposition, so the position size will be the same as we enter the trade.
    ExitLongStopMarket(Convert.ToInt32(Position.Quanti ty), MyDonchianClose1.Lower[1], @"ExitLong", @"EnterLong");
    }

    }

    #region Properties
    [NinjaScriptProperty]
    [Range(1, double.MaxValue)]
    [Display(Name="Virtual_Account_Value", Description="This is the cash value before you start the strategy in the small virtual account", Order=1, GroupName="Parameters")]
    public double Virtual_Account_Value
    { get; set; }

    [NinjaScriptProperty]
    [Range(0.01, double.MaxValue)]
    [Display(Name="Risk", Description="Risk percent on each trade of the virtual account", Order=2, GroupName="Parameters")]
    public double Risk
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Contract_Multiplier", Description="Multiplier for futures", Order=3, GroupName="Parameters")]
    public int Contract_Multiplier
    { get; set; }

    [NinjaScriptProperty]
    [Range(0, int.MaxValue)]
    [Display(Name="Entry_Stop_Spread_TICKS", Description="what is the distance of the LMT in the StopLmt order", Order=4, GroupName="Parameters")]
    public int Entry_Stop_Spread_TICKS
    { get; set; }
    #endregion

    }
    }

    would appreciate if you see something screamingly wrong... thanks in advance!

    #2
    Hello zoharcho,

    Thank you for your post.

    Strategies have a property called BarsRequiredToTrade that basically restricts the strategy from entering until at least that number of bars is on the chart.

    The note you're seeing isn't actually an error, just telling you that the strategy wasn't to the minimum number of bars on the chart before it tried to take a trade. You can set this to a different value by setting BarsRequiredToTrade in State.SetDefaults.



    Please let us know if we may be of further assistance to you.

    Comment


      #3
      thank you, happy to hear

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      89 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      135 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X