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

Don't buy in case the open is above entry

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

    Don't buy in case the open is above entry

    Hi,

    I'm running a strategy on daily chart.
    Assuming we are talk about long positions, I place EnterLongStopLimit order to buy above the high of the entry candle.

    My question is, how can I make sure not to buy stocks that open above the entry and then going down ?

    Thanks

    #2
    Hello shayhz,

    To ensure that the order is above the session open after the first bar closes when the order is placed at the high:

    if (CurrentBar == 0 && High[0] > Open[0])
    {
    EnterLongStopLimit(High[0], High[0]);
    }

    This would place an entry stop limit with the stop and limit at the high of the first bar on the chart as long as that bar's high is greater than the open.


    What is the criteria for going down?

    Do you mean if when the first bar closes it is greater than when it opens?

    if (CurrentBar == 0 && Close[0] > Open[0])

    Are you planning to place the order after the first bar?

    Lets say its the third bar and you want to make sure that each bar that has closed has not closed less than the session open:

    if (CurrentBar == 2 && Close[0] >= CurrentDayOHL().CurrentOpen[0] && Close[1] >= CurrentDayOHL().CurrentOpen[0] && Close[2] >= CurrentDayOHL().CurrentOpen[0])

    Or on the third bar you want to make sure each bar has closed higher or equal to the previous bar.

    if (CurrentBar == 2 && Close[0] >= Close[1] && Close[1] >= Close[2])

    Or if you wanted to loop through all bars and make sure each bar is greater than the last
    bool allHigher = true;
    for (int i = 0; i < CurrentBar - 1; i++)
    {
    if (Close[i] < Close[i-1])
    allHigher = false;
    }

    if (allHigher == true)
    {
    EnterLongStopLimit(High[0], High[0]);
    }
    Last edited by NinjaTrader_ChelseaB; 12-28-2015, 03:00 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      Thanks for you reply.
      I'm not sure we are on the same page.
      Let's have an example:
      On day 1 I placed long stop limit above the high of the day, e.g. 50.
      On day 2, the open is 50.3 - if the stock price will fall to 50, then my order will catch, but I don't want it to be caught, because the open is greater then my entry price.

      Comment


        #4
        Hello shayhz,

        In this scenario the limit price is the same as the stop price, correct?

        The sell stop limit is being placed before the end of the session above the current market price, then on the next session this order is still working (a stop limit order would have to be a sell order to be placed above the market price). The close of the session is below the stop price of the order. As the new session opens, this opens with a gap and opens higher than stop price. As the limit price is also below market price this would fill before you would have a chance to cancel this.

        Really there would not be a way to prevent this. You would need to cancel the order before the close of the session to ensure it does not fill on the first tick of the new session as the stop and limit are set to the same price.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          ... a stop limit order would have to be a sell order to be placed above the market price
          Nope. Quite to the contrary.

          Comment


            #6
            koganam,

            You are correct, thank you for catching me on this.

            A Sell Stop Limit does place under the market price while a Buy Stop Limit places above the market price.

            Correcting the senario:
            The buy stop limit is being placed before the end of the session above the current market price, then on the next session this order is still working (a stop limit order would have to be a buy order to be placed above the market price). The close of the session is below the stop price of the order. As the new session opens, this opens with a gap and opens higher than stop price.

            Continuing:
            The limit is now working and the price must return for the order to fill.
            However, you would like to cancel the order if the gap has occurred and the price is falling.

            As the order is submitted, the entry method will return an IOrder. This IOrder would need to be supplied to CancelOrder() if the criteria for the price falling after the start of a new session is met. This would also need to be done in real-time after the first tick is received to prevent the order from filling.

            For example:
            Code:
            private IOrder entryOrder;
            private newSession = false;
            
            if (/* conditions to place entry order */)
            {
            entryOrder = EnterLongStopLimit(High[0], High[0]);
            newSession = false;
            }
            
            if (entryOrder != null
            && entryOrder.OrderState == OrderState.Working
            && Bars.FirstBarOfSession == true)
            {
            newSession = true;
            }
            
            if (newSession == true && entryOrder != null
            && entryOrder.OrderState == OrderState.Working
            && Close[0] < CurrentDayOHL().CurrentOpen[0])
            {
            CancelOrder(entryOrder);
            newSession = false;
            }
            This would place a buy stop limit at the high of a bar. Then if the bar is the first bar of the session this will set a trigger that cancelling the order will unset. If the order is somehow placed again because the order is filled, the trigger is unset when the order is submitted again.

            If the newSession trigger is set and the order is still in a working state and close of a bar is below the session open, then the order will be cancelled.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by trilliantrader, 04-10-2024, 09:33 PM
            7 responses
            25 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by traderqz, Today, 12:06 AM
            5 responses
            11 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by Mongo, Today, 11:05 AM
            2 responses
            10 views
            0 likes
            Last Post Mongo
            by Mongo
             
            Started by guillembm, Today, 11:25 AM
            0 responses
            4 views
            0 likes
            Last Post guillembm  
            Started by Tim-c, Today, 10:58 AM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X