Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EnterLongLimit ignores the fact that the price is set at High[1]

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

    EnterLongLimit ignores the fact that the price is set at High[1]

    Hi,

    For some reason if I do the backtesting on historical datas or with market replay datas, the command EnterLongLimit completely ignores the price input.

    The Code:

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

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (CurrentBar != CurrentBars[0])
    {
    CancelOrder(ShortHigh);
    }


    if (LongHigh == null)
    if (High[0] < High[1])
    {
    EnterLongLimit(4,High[1],"LongHigh");
    CurrentBar = CurrentBars[0];
    }


    }
    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled,
    double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
    {
    if(order.Name == "LongHigh")
    {
    LongHigh = order;
    }
    if (LongHigh != null && LongHigh == order)
    {
    if (LongHigh.OrderState == OrderState.Cancelled)
    {
    LongHigh = null;
    }
    else
    {
    LongHigh = null;
    }

    }
    }

    The limit order is always placed at the opening price of the next bar.

    Best
    S.







    #2
    Hello Slaywer,

    Welcome to the NinjaTrader support forum.

    In a historical situation we should see the order placed on the next bar unless there is some secondary series being used for intrabar granularity. This is because the condition will evaluate at the bar close. As for the price that would in historical relate to the historical fill processing:



    You can try using the higher fill resolution here to see if that gives the results you are expecting, if you are instead expecting an intrabar fill here.

    I look forward to being of further assistance.

    Comment


      #3
      Hi Jesse,

      Thanks for the fast reply.

      I thought I found the answer, but unfortunately it appears to be still not the way it was intended.

      If I write this :

      EnterLongStopMarket(4, (High[1] + 0.5) , "LongHigh");

      Then after the bar closes the code should submit a long stop-order at the price of the last bars high ( if real time data used ) and with historical data the price " High[0] + 0.5 " is supposed to be the price level of the last bars high + 0.5.

      But it seems like the code is submitting long limit orders at the next bar's opening independend of my input. ( Same problem as before)

      Sorry if it's a trivial problem, just started coding..

      Best,
      S

      Comment


        #4
        Hello Slaywer,

        I couldn't really say what may be happening with this amount of information, you are also comparing realtime and historical which work differently. My reply was based on the note about backtesting, if you are not backtesting and instead using realtime that is a different situation and you likely need to look at your logic. If you are not sure what actual data is being used you can try printing the Time[1] when you call EnterLongStopMarket to see what bar that targets. Depending on what you coded that could relate to the structure of your script. The [0] BarsAgo value will represent the last Closed bars value, if you meant the previous bar you likely need [1] here.

        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        87 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        132 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
        118 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        67 views
        0 likes
        Last Post PaulMohn  
        Working...
        X