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

Stop Order

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

    Stop Order

    Hi,

    I've a strategy that I want to place an order at the next candle when it break of a current candle (which is a signal candle). Any idea how do I enter the trade?

    For example: for long, I only go long when only the next candle price is above the current candle high and vice versa for short.

    Appreciate any help.
    Last edited by ark321; 12-12-2021, 05:58 PM.

    #2
    Hello ark321,

    if (Close[0] > High[0])
    EnterLong();

    if (Close[0] < Low[0])
    EnterShort();

    Below I am providing a link to a forum post with helpful information about getting started with NinjaScript and C#.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Correction if I may:

      if (Close[0] > High[1])
      EnterLong();

      if (Close[0] < Low[1])
      EnterShort();

      Comment


        #4
        thank you. one other question. Two other questions:

        1) Is there a way to enter long 1 tick above/below the signal bar (current bar)?
        2) What if I want to enter the trade whenever the price is above/below after the signal bar. Meaning, it can be after 1 bar or x number of bars
        Last edited by ark321; 12-13-2021, 06:52 AM.

        Comment


          #5
          Hello ark321,

          You could have the logic check the Close[0] is equal to or greater than the previous bar's High[1] + TickSize.

          Or you could place a limit or stop (depending if buy or sell) at the High[1] + TickSize.

          You can save the CurrentBar to an int variable and trigger an action x number of bars later.

          private int signalBar;
          private int numOfBarsBeforeAction = 3;

          if (/*conditions*/)
          {
          signalBar = CurrentBar;
          }

          if (CurrentBar > signalBar + numOfBarsBeforeAction)
          {
          EnterLong();
          }
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            this helps. Thanks a lot

            Comment


              #7
              I added the logic as per the above suggestion to place a stop order once the price goes above the signal bar. However, as you see below - it is not working as expected. Long triggered below the high of the signal bar. Any idea what am I missing?

              Comment


                #8
                here is the code
                Attached Files

                Comment


                  #9
                  Hello ark321,

                  Use Print() to understand the behavior.

                  What is the condition that triggers the order?

                  Print the time of the bar and all values in the condition set.

                  What is the stop price used for the order? Print this one line above where the order is submitted.

                  Below is a link to a forum post that demonstrates using Print() to understand behavior.


                  Include labels with the prints to identify what the values are, and labels to show how the values are being compared.

                  Include the output saved to a text file with your reply.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks for the feedback. I finally figured out. What I noticed is previous candle [1] is the signa bar. So, I need to change the logic to enter the trade in current bar when the price is above the high of the previous bar(for long) or below the low of the previous bar.

                    Logic has to be:
                    Enter long -- if the current bar price is above the previous bar high enter market order. or enter Stop Order with one tick above the previous bar.
                    Enter Short - if the current bar price is below the previous bar low enter market order otherwise enter stop order with a price one tick below the previous bar

                    Any guidance on how to do this?

                    Comment


                      #11
                      I may have figured it.. Is this the correct way to enter?

                      if(High[1] < GetCurrentAsk()+1) {
                      EnterLong(Qty, "EnterLong 1");
                      } else {
                      EnterLongStopMarket(Qty, High[1] + TickSize,"EnterLong 1");
                      }

                      Comment


                        #12
                        Hello ark123,

                        What you have written describes what you are trying to do. You may test to verify it behavers as you like, and you can use prints to confirm what values High[1], and GetCurrentAsk()+1 are to see exactly how that condition evaluates.

                        Keep in mind that if you do not use an IsLiveUntilCancelled overload, the order will be cancelled on the next bar.

                        LiveUntilCancelled Orders - https://ninjatrader.com/support/help...ancelledOrders

                        Keeping orders alive - https://ninjatrader.com/support/help...ders_alive.htm
                        JimNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by traderqz, Today, 12:06 AM
                        2 responses
                        4 views
                        0 likes
                        Last Post traderqz  
                        Started by RideMe, 04-07-2024, 04:54 PM
                        5 responses
                        28 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Started by f.saeidi, Today, 08:13 AM
                        1 response
                        7 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by DavidHP, Today, 07:56 AM
                        1 response
                        6 views
                        0 likes
                        Last Post NinjaTrader_Erick  
                        Started by kujista, Today, 06:23 AM
                        3 responses
                        11 views
                        0 likes
                        Last Post kujista
                        by kujista
                         
                        Working...
                        X