Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

2 EnterLong orders, one by one.

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

    2 EnterLong orders, one by one.

    Hello, NT gurus.
    Tell me please, why this construction is not working? As result i have only 1 enter and 1 stop from the first signal (Long1).

    PHP Code:
     protected override void OnBarUpdate()
            {
                if((High[0] - Low[0]) > (High[1] - Low[1]) * 2
                    && Close[0] < Open[0]
                    && enabled)
                {
                    EnterLong(1, "Long1");
                    ExitLongStop(0, true, 1, 10, "Stop12", "Long1");
                    
                    EnterLong(1, "Long");
                    ExitLongStop(0, true, 1, Close[0] + 20, "StaticSL", "Long");
                    ExitLongLimit(0, true, 1, Close[0] + 20, "StaticTP", "Long");
                }            
            } 
    

    #2
    Hello Dzammer.

    Thanks for your post and welcome to the forums.

    In reviewing the ExitLong (stop and limit) it appears you are specifying an overload for a multi-timeframe strategy while the EnterLong code does not. You should use the overload that best matches your needs which I think is:
    ExitLongStop(int quantity, double stopPrice, string signalName, string fromEntrySignal)
    Here is the complete reference from the helpguide: http://www.ninjatrader.com/support/h...itlongstop.htm

    The Close[0] + 20 says that you are adding a value of 20 to the current close price, is that correct or are you trying to add 20 ticks? (If so then you would specify Close[0] + 20 * TickSize). Likewise the ExitLongStop associated with Long1 has a specified value of 10 only, is that the correct price?

    Please let me know if I can be of further assistance.

    Comment


      #3
      I have corrected, but without result again.
      World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.

      I was attached strategy file.
      Attached Files

      Comment


        #4
        Hello Dzammer,

        Thanks for your reply and code.

        In the strategy you have ExitLongStop(1, 20 * TickSize, "Stop12", "Long1"); As this is a Long Stop you need to place the stop below the entry price so the 20*Ticksize is an incomplete expression of where you want the stop to be.

        Instead try ExitLongStop(1, Close[0] - 20 * TickSize, "Stop12", "Long1");

        Also you might look at ExitLongStop(1, Position.AvgPrice - 20 * TickSize, "Stop12", "Long1"); see http://www.ninjatrader.com/support/h...l?position.htm

        For the ExitLongLimit you would want to add the 10 *TickSize either to the Close[0] or the Position.AvgPrice so that the target is above the entry.

        In the strategy I didn't see an ExitLongLimit for the first entry, only the stop.

        As you have two long entries, when you apply the strategy make sure you set entries per direction to 2 in the order handling section of the user Interface. Without that set to 2, only the first order will be used. If you would prefer to code that in, here is the helpguide reference for that: http://www.ninjatrader.com/support/h...rdirection.htm

        Please let me know if I can be of further assistance.

        Comment


          #5
          Thank you for reply.
          I do that you tell me, and all work fine. But.. When i placed code for enter position on click method, they did not work again... Can you see were is the mistake?
          Attached Files

          Comment


            #6
            Hello Dzammer,

            Thanks for your reply.

            Regrettably the methods you are using are not supported so I cannot assist other than to recommend moving all of the toolstrip items from initialize and put them into the Startup method.

            Comment


              #7
              Ok. I clear code from all toolstrips.
              Look. In the first bar we have 2 entries. But in the next bar we have 2 entries and Stops...
              World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.

              World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.
              Attached Files

              Comment


                #8
                Hello Dzammer,

                Thanks for your reply.

                Sorry, I do not understand what you are trying to accomplish.

                Looking at the code I see:

                1) EnterLong called Long1
                2) EnterLong called Long
                3) ExitLongStop tied to Long1, called Stop12
                4) ExitlongStop tied to long, called StaticSL
                5) ExitLongLimit tied to long, called StaticTP

                You have no logic ahead of the orders so each bar close will result in trying to place the same orders.

                If you could clarify what you are trying to accomplish I may be able to assist.

                Comment


                  #9
                  Originally posted by NinjaTrader_Paul View Post

                  Looking at the code I see:

                  1) EnterLong called Long1
                  2) EnterLong called Long
                  3) ExitLongStop tied to Long1, called Stop12
                  4) ExitlongStop tied to long, called StaticSL
                  5) ExitLongLimit tied to long, called StaticTP
                  Yes. Right. But look in to the screens. In first bar we have only
                  1) EnterLong called Long1
                  2) EnterLong called Long
                  in the next bar we have all positions:
                  1) EnterLong called Long1
                  2) EnterLong called Long
                  3) ExitLongStop tied to Long1, called Stop12
                  4) ExitlongStop tied to long, called StaticSL
                  5) ExitLongLimit tied to long, called StaticTP

                  What i want.. I want to open 2 orders:
                  1) EnterLong called Long1
                  2) EnterLong called Long
                  For first order i want to set trailing stop
                  3) ExitLongStop tied to Long1, called Stop12
                  And for other order i want to set static stop and take
                  4) ExitlongStop tied to long, called StaticSL
                  5) ExitLongLimit tied to long, called StaticTP

                  Comment


                    #10
                    Hello Dzammer,

                    Thanks for your reply.

                    To limit your orders you would want to set your EntriesPerDirection to 1 and your entry handling to Unique.Entries. This will allow you to enter Long and long1 once and subsequent entry attempts will be ignored. Please review (example 2) of: http://www.ninjatrader.com/support/h...rdirection.htm
                    also example 2 here: http://www.ninjatrader.com/support/h...ryhandling.htm

                    For the trailing stop, unless you intend to write your own procedure, the NinjaScript method is identified here: http://www.ninjatrader.com/support/h...ttrailstop.htm For your code I suggest this overload of the method: SetTrailStop(string fromEntrySignal, CalculationMode mode, double value, bool simulated) so that you can tie the trailstop only to a specific entry. Please be sure to observe the tips listed in the helpguide section referenced.

                    Please let me know if I can be of further assistance.

                    Comment


                      #11
                      Hello.
                      I do that you tell me... But it still not working... Strategy open only 2 long orders and no open stop and take.
                      World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.
                      Attached Files

                      Comment


                        #12
                        Hello Dzammer,

                        Thanks for your reply.

                        In looking at the strategy file I didn't see the changes we discussed.

                        I've modified your test strategy to set the entries per direction to be 1 and the entry handling to be unique entries. I then added setstoploss, settrailstop and setprofittarget methods. Finally for testing I added logic so it only enters the two orders once.

                        On the first bar close, two long entries are made, 1 trail stop, 1 profit target and 1 stoploss each tied to the signal names.

                        Please let me know if I can be of further assistance.
                        Attached Files

                        Comment


                          #13
                          It work. Thank you. But. IF i want to set different stop size for each trade?

                          Comment


                            #14
                            Hello Dzammer,

                            Thanks for your reply and glad that helped.

                            Please make sure you review the help guide as it covers dynamically setting setProfitTarget, SetTrailStop and setStopLoss:


                            http://www.ninjatrader.com/support/h...etstoploss.htm.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            647 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            369 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            108 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            572 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            573 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X