Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    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.

        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Skifree, Today, 03:41 AM
        3 responses
        12 views
        0 likes
        Last Post Skifree
        by Skifree
         
        Started by traderqz, Yesterday, 09:06 AM
        5 responses
        32 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by guillembm, Today, 11:25 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by owensd, 04-21-2024, 11:34 PM
        9 responses
        34 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by trilliantrader, 04-10-2024, 09:33 PM
        7 responses
        25 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X