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

Please help, problem with position reversal

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

    Please help, problem with position reversal

    Hello, please help solve the following problem, i want to make position reversal in my strategy. For example, the strategy put a limit order to sell at a certain price and the position was closed by stop, how to make the strategy placed an order to buy at a price higher than the previous entry point for a certain number of points?
    Thank you in advance for your attention.

    #2
    Hello Papercut110,

    Thank you for your note.

    I have attached a script which will demonstrate how to do this.

    The way it works is that after an entry signal is given, a long order is submitted, the orders IOrder id is saved to variable entryOrder, and a bool is set to true. Then under OnExecution the orders fill price is saved to variable entryOrder of IOrder type, which is then referenced by line 69 after line 67 becomes true. This will submit a buy stop order 10 ticks above the initial entry.

    Please see the following reference example which covers using IOrder and OnExecution(),
    The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


    Please let us know if you need further assistance.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_AlanP, thanks a lot, worked

      but...could you please explain what do these lines

      if(Close[0]!= Close[5] && firstEntryDone==false)

      and

      if(BarsSinceEntry()>15)
      {
      entryOrder = null;
      ExitLong();
      }
      Last edited by Papercut110; 12-28-2016, 09:30 PM.

      Comment


        #4
        Hello Papercut110,

        The (Close[0]!= Close[5] is a generic condition which triggers true of the close of this bar is not equal to the close of 5 bars ago. firstEntryDone==false checks to make sure this block of code only runs once, for the purpose of demonstrating how the reversal would work.

        The BarsSinceEntry>15 is another generic condition which would close any open position after 15 bars.

        These conditions were really just place holders for your code as I was trying to demonstrate how you could do a reversal.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          thank you very much, I understand

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          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
          4 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
          9 views
          0 likes
          Last Post kujista
          by kujista
           
          Started by Mindset, Yesterday, 02:04 AM
          2 responses
          18 views
          0 likes
          Last Post NinjaTrader_RyanS  
          Working...
          X