Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

invalid based on the price range of the bar

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

    invalid based on the price range of the bar

    Hello, could anyone help me with this case?

    protected override void OnExecutionUpdate()
    if(execution.Order.Name == "C4" && execution.Order.OrderState == OrderState.PartFilled)
    {
    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, execution.Order.Filled/2, (execution.Order.AverageFillPrice + (AlvoTicks4*TickSize)), 0.0, ocoString, "TargetC4");
    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, execution.Order.Filled, 0.0, (execution.Order.AverageFillPrice - ((AlvoTicks4/2)*TickSize)), ocoString, "StopLossC4");
    }
    else if(execution.Order.Name == "C4" && execution.Order.OrderState == OrderState.Filled && sumFilled == execution.Order.Filled)
    {
    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, execution.Order.Filled/2, (execution.Order.AverageFillPrice + (AlvoTicks4*TickSize)), 0.0, ocoString, "TargetC4");
    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, execution.Order.Filled, 0.0, (execution.Order.AverageFillPrice - ((AlvoTicks4/2)*TickSize)), ocoString, "StopLossC4");
    }

    Log:
    ============
    StopPrice=18535,75 SignalName='V1'
    LimitPrice=18533,25 StopPrice=0 SignalName='TargetV1'
    StopPrice=18542,25 SignalName='StopLossV1'

    Passed without error...............................

    LimitPrice=0 StopPrice=0 SignalName='V2'
    LimitPrice=18533,25 StopPrice=0 SignalName='TargetV2'
    StopPrice=18537,00 SignalName='StopLossV2'

    Passed without error...............................

    LimitPrice=0 StopPrice=0 SignalName='V3'
    LimitPrice=18533,25 StopPrice=0 SignalName='TargetV3'
    LimitPrice=0 StopPrice=18537,00 SignalName='StopLossV3'

    Passed without error...............................

    NOW ERROR::::
    01/04/2024 07:05:00 Strategy 'RoboOCOUnmanaged/323791933': Entered internal SubmitOrderUnmanaged() method at 01/04/2024 07:05:00: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=4 LimitPrice=0 StopPrice=0 SignalName='V4'
    PASSOU AQUI...............................
    01/04/2024 07:05:00 Strategy 'RoboOCOUnmanaged/323791933': Entered internal SubmitOrderUnmanaged() method at 01/04/2024 07:05:00: BarsInProgress=0 Action=BuyToCover OrderType=Limit Quantity=2 LimitPrice=18533,25 StopPrice=0 SignalName='TargetV4'
    01/04/2024 07:05:00 Strategy 'RoboOCOUnmanaged/323791933': Entered internal SubmitOrderUnmanaged() method at 01/04/2024 07:05:00: BarsInProgress=0 Action=BuyToCover OrderType=StopMarket Quantity=4 LimitPrice=0 StopPrice=18537,00 SignalName='StopLossV4'
    PASSOU AQUI...............................
    PASSOU AQUI...............................
    01/04/2024 07:05:00 Strategy 'RoboOCOUnmanaged/323791933': Entered internal SubmitOrderUnmanaged() method at 01/04/2024 07:05:00: BarsInProgress=0 Action=BuyToCover OrderType=StopMarket Quantity=2 LimitPrice=0 StopPrice=18534,50 SignalName='StopLossV4'
    Strategy 'RoboOCOUnmanaged/323791933': An order has been ignored since the stop price ‘18534.5’ near the bar stamped ‘04/01/2024 07:05:00’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored.
    01/04/2024 07:05:00 Strategy 'RoboOCOUnmanaged/323791933': Ignored SubmitOrderUnmanaged() method at 01/04/2024 07:05:00: BarsInProgress=0 Action=BuyToCover OrderType=StopMarket Quantity=2 LimitPrice=0 StopPrice=18534,50 SignalName='StopLossV4' FromEntrySignal='' Reason='Invalid order price, please see log tab'
    PASSOU AQUI...............................8
    Strategy 'RoboOCOUnmanaged': Error on calling 'OnBarUpdate' method on bar 169: Object reference not set to an instance of an object.
    01/04/2024 07:05:00 CancelAllOrders: BarsInProgress=0​

    #2
    Hello WenisCR,

    Thanks for your post.

    An order has been ignored since the stop price ‘18534.5’ near the bar stamped ‘04/01/2024 07:05:00’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored.

    The error is letting you know the price was invalid for that order when it was submitted based on the prices at that time. You would need to make sure to use a price that's valid at that time.

    Prints should be added to the script that print out the Close, High, Low, Bid, and Ask prices of the bars along with the time of the bar and the stop price you are submitting the order to. Then you could compare the print output to the bars on the chart to see how the stop price is evaluated based on the range of the bars.

    Buy stop orders must be placed above the current ask price. Sell stop orders must be placed below the current bid price.

    Note if this is being tested on Historical data, such as backtesting in the Strategy Analyzer, the bid/ask prices are replaced with the Close price. This information could be found on the help guide pages below.

    GetCurrentBid(): https://ninjatrader.com/support/help...=getcurrentbid
    GetCurrentAsk(): https://ninjatrader.com/support/help...=getcurrentask

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.


    "Error on calling 'OnBarUpdate' method on bar 169: Object reference not set to an instance of an object.​"

    This error indicates that something in your script is returning null at the time you are accessing it. To determine the exact line of code causing the behavior to occur, you should add debugging prints throughout your script that print out the values used in the script. You could also reduce the code of the script by commenting out sections of code and noting if the behavior persists. If at any point you comment out a line of code and the behavior stops, it is likely the last commented-out section of code causing the behavior. You could then use prints to narrow in on the offending code.

    Further, my colleagues have given a very good guide on troubleshooting missed orders here, please read through this post and see if any of this applies to your situation: https://ninjatrader.com/support/foru...ge#post1104682
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    54 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    71 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X