Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unmanaged order barsinprogress problem

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

    Unmanaged order barsinprogress problem

    Hi, i'm just doing this easy strategy to try if i can enter the market and putting stop loss and take profit correctly, but it gives me the error: the barsrequired to trade property hasn't been met ecc ecc The stop loss is the problem. thanks
    but i used BarsTOtrade = 0


    #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 UnManaged : Strategy
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "UnmanagedOrders";
    Calculate = Calculate.OnBarClose;
    IsUnmanaged = true;
    BarsRequiredToTrade = 0;
    }
    else if (State == State.Configure)
    {

    AddVolumetric("FBTP 03-22", BarsPeriodType.Tick, 1, VolumetricDeltaType.BidAsk, 1);

    }
    }
    private enum Pos
    {
    FLAT,
    LONG,
    SHORT
    }
    private Pos m_marketPosition;
    protected override void OnBarUpdate()
    {
    if(State == State.Historical)
    return;
    if(BarsInProgress==1)
    {

    if (m_marketPosition == Pos.FLAT)
    {
    SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, 3);
    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, 3, GetCurrentAsk() + 175 * TickSize);
    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, 3, GetCurrentAsk() - 100 * TickSize);


    // the stop loss give me the error

    }


    }

    }

    protected override void OnPositionUpdate(Cbi.Position position, double averagePrice,int quantity, Cbi.MarketPosition marketPosition)
    {

    MarketPosition marketPos = position.MarketPosition;
    if (marketPos==MarketPosition.Flat)
    {
    m_marketPosition = Pos.FLAT;
    }
    else if (marketPos == MarketPosition.Long)
    {
    m_marketPosition = Pos.LONG;
    }
    else if(marketPos == MarketPosition.Short)
    {
    m_marketPosition = Pos.SHORT;
    }
    }
    }
    }

    #2
    Hello AlessioCianini12,

    Thanks for your post.

    I see that you have modified BarsRequiredToTrade, but since it is in State.SetDefaults, you will need to remove and re-add the script to have the new default recognized.

    When BarsRequiredToTrade is set to 0, trades will be allowed starting with the first historical bar that is processed.

    Some additional notes regarding your snippet:
    1. You are adding a single tick Volumetric bar. Is this purposeful? It will be less expensive to use a regular single tick data series. The volumetric bar information may not be helpful on a 1 tick data series.
    2. You are processing data on the 1 tick data series but are submitting orders to BarsInProgress 0 (the primary data series.) This would be less accurate with backtesting as opposed to submitting orders to the single tick data series.
    3. You are tracking your own Position object from OnPositionUpdate. We would suggest using the built in Position object instead.

    Multi Time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

    Backtesting with intrabar granularity - https://ninjatrader.com/support/help...ipt_strate.htm

    Position - https://ninjatrader.com/support/help...l?position.htm

    We look forward to assisting.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    62 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    134 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X